Download the PHP package crazzy501/gpt-3-encoder-php without Composer
On this page you can find all versions of the php package crazzy501/gpt-3-encoder-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crazzy501/gpt-3-encoder-php
More information about crazzy501/gpt-3-encoder-php
Files in crazzy501/gpt-3-encoder-php
Package gpt-3-encoder-php
Short Description PHP BPE Text Encoder/Decoder for GPT-2 / GPT-3. Based on coderevolutionplugins/gpt-3-encoder-php
License MIT
Informations about the package gpt-3-encoder-php
GPT-3-Encoder-Decoder-PHP
PHP BPE Text Encoder/Decoder for GPT-2 / GPT-3
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 OOP implementation of OpenAI's original python encoder and decoder which can be found here. The main source of inspiration for writing this encoder was the NodeJS version of this encoder, found here.
You can test the results, by comparing the output generated by this script, with the official tokenizer page from OpenAI.
Encoder uses caching for store characters arrays for encode/decode that can be configured by using Gpt3EncoderConfiguraion class.
By default, encoder uses php arrays for caching that may be memory intensive, but you can change it to Redis or Memcached driver
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
Or
Pass true
as second argument to throw exception if decoder can't decode something.
Otherwise, it just skips some character
Configuration
All versions of gpt-3-encoder-php with dependencies
ext-json Version *