crazzy501/gpt-3-encoder-php
Composer 安装命令:
composer require crazzy501/gpt-3-encoder-php
包简介
PHP BPE Text Encoder/Decoder for GPT-2 / GPT-3. Based on coderevolutionplugins/gpt-3-encoder-php
关键字:
README 文档
README
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
require './vendor/autoload.php'; $encoder = new \GPT3Encoder\Gpt3Encoder(); $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 = $encoder->encode($prompt); $original_text = $encoder->decode($token_array);
Or
Pass true as second argument to throw exception if decoder can't decode something.
Otherwise, it just skips some character
$original_text = $encoder->decode($token_array,true);
Configuration
require './vendor/autoload.php'; $configuration = (new \GPT3Encoder\Gpt3EncoderConfiguration) ->setCacheClass(\GPT3Encoder\Gpt3CacheMemcached::class) ->setEncoder(__DIR__.'/encoder.json') ->setVocabulary(__DIR__.'/vocabulary.bpe') ->setCharacters(__DIR__.'/characters.json') ->setMemoryLimitThreshold(10000); // for memory limit checks $encoder = new \GPT3Encoder\Gpt3Encoder($configuration);
crazzy501/gpt-3-encoder-php 适用场景与选型建议
crazzy501/gpt-3-encoder-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 383 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「encoder」 「decoder」 「GPT-3」 「gpt-2」 「GPT-3-Tokenizer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 crazzy501/gpt-3-encoder-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 crazzy501/gpt-3-encoder-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 crazzy501/gpt-3-encoder-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Streaming parser to extract tarballs with ReactPHP.
base62 encoder and decoder also for big numbers with Laravel integration
PHP Library for Encoding.com's XML API
A Base91 implementation as a composer package
Serialization library
A TOML parser and encoder for PHP with AST access and collected parse errors
统计信息
- 总下载量: 383
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-06