← 开源

Javascript BPE Encoder Decoder for GPT-2 / GPT-3

Model DevelopmentDataset engineeringJavaScript
增长势头
+-124 小时新增 Star-0.1%
719
Star
196
Fork
+-1
本周
7
贡献者
创建于 2020-09-04 · 更新于 2026-12-05 · 今日第 29278 名
主要开发者
nickwaltonkafkasInvaderSquibs
README

GPT-3-Encoder

Javascript BPE 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 javascript implementation of OpenAI's original python encoder/decoder which can be found here

Install with npm

npm install gpt-3-encoder

Usage

Compatible with Node >= 12

const {encode, decode} = require('gpt-3-encoder')

const str = 'This is an example sentence to try encoding out on!'
const encoded = encode(str)
console.log('Encoded this string looks like: ', encoded)

console.log('We can look at each token and what it represents')
for(let token of encoded){
  console.log({token, string: decode([token])})
}

const decoded = decode(encoded)
console.log('We can decode it back into:\n', decoded)
排名相邻
同类项目

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载