百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

GPT-3-Encoder-PHP

> 编程语言
开源

用于 GPT-2 / GPT-3 的 PHP BPE 文本编码器/解码器

100 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于 GPT-2 / GPT-3 的 PHP BPE 文本编码器/解码器

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 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.

This specific encoder and decoder is used in the Aiomatic WordPress plugin, to count the number of tokens a string will use when sent to OpenAI API. Check more of my work on my website.

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

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);

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPdecoderencodergpt-2gpt-2-simple

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言