PHPackages                             coderevolutionplugins/gpt-3-encoder-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. coderevolutionplugins/gpt-3-encoder-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

coderevolutionplugins/gpt-3-encoder-php
=======================================

PHP BPE Text Encoder/Decoder for GPT-2 / GPT-3

10046.1k↓10.4%18[1 PRs](https://github.com/CodeRevolutionPlugins/GPT-3-Encoder-PHP/pulls)PHP

Since Mar 14Pushed 3y ago3 watchersCompare

[ Source](https://github.com/CodeRevolutionPlugins/GPT-3-Encoder-PHP)[ Packagist](https://packagist.org/packages/coderevolutionplugins/gpt-3-encoder-php)[ RSS](/packages/coderevolutionplugins-gpt-3-encoder-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

GPT-3-Encoder-Decoder-PHP
=========================

[](#gpt-3-encoder-decoder-php)

PHP BPE Text Encoder/Decoder for GPT-2 / GPT-3

About
-----

[](#about)

GPT-2 and GPT-3 use byte pair encoding to turn text into a series of integers to feed into the model. This is a PHP implementation of OpenAI's original python encoder and decoder which can be found [here](https://github.com/openai/gpt-2). The main source of inspiration for writing this encoder was the NodeJS version of this encoder, found [here](https://github.com/latitudegames/GPT-3-Encoder).

You can test the results, by comparing the output generated by this script, with the [official tokenizer page from OpenAI](https://beta.openai.com/tokenizer).

This specific encoder and decoder is used in the [Aiomatic WordPress plugin](https://1.envato.market/aiomatic), to count the number of tokens a string will use when sent to OpenAI API. Check more of my work on my [website](https://coderevolution.ro/).

Usage
-----

[](#usage)

The mbstring PHP extension is needed for this tool to work correctly (in case non-ASCII characters are present in the tokenized text): [details here on how to install mbstring](https://www.php.net/manual/en/mbstring.installation.php)

```
$prompt = "Many words map to one token, but some don't: indivisible. Unicode characters like emojis may be split into many tokens containing the underlying bytes: 🤚🏾 Sequences of characters commonly found next to each other may be grouped together: 1234567890";

$token_array = gpt_encode($prompt);

$original_text = gpt_decode($token_array);
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/91943804?v=4)[Szabolcs-Istvan Kisded](/maintainers/CodeRevolutionPlugins)[@CodeRevolutionPlugins](https://github.com/CodeRevolutionPlugins)

---

Top Contributors

[![CodeRevolutionPlugins](https://avatars.githubusercontent.com/u/91943804?v=4)](https://github.com/CodeRevolutionPlugins "CodeRevolutionPlugins (17 commits)")

---

Tags

decoderencodergpt-2gpt-2-simplegpt-2-text-generationgpt-2-tokenizergpt-3gpt-3-promptgpt-3-promptsgpt-3-text-generationgpt-3-tokenizergpt3-decodergpt3-encoderphp

### Embed Badge

![Health badge](/badges/coderevolutionplugins-gpt-3-encoder-php/health.svg)

```
[![Health](https://phpackages.com/badges/coderevolutionplugins-gpt-3-encoder-php/health.svg)](https://phpackages.com/packages/coderevolutionplugins-gpt-3-encoder-php)
```

###  Alternatives

[judev/php-htmltruncator

HTML Truncation library, ported from the html\_truncator rubygem

26286.5k6](/packages/judev-php-htmltruncator)[flarum/pusher

See new discussions and posts in real-time using Pusher.

22367.3k4](/packages/flarum-pusher)[causal/extractor

This extension detects and extracts metadata (EXIF / IPTC / XMP / ...) from potentially thousand different file types (such as MS Word/Powerpoint/Excel documents, PDF and images) and bring them automatically and natively to TYPO3 when uploading assets. Works with built-in PHP functions but takes advantage of Apache Tika and other external tools for enhanced metadata extraction.

16244.5k](/packages/causal-extractor)[awcodes/palette

A color picker field for Filament Forms that uses preset color palettes.

2552.6k5](/packages/awcodes-palette)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
