gpt3-tokenizer
This is a TypeScript tokenizer for OpenAI's GPT-3 model. Including support for `gpt3` and `codex` tokenization.
Last updated 5 years ago by lhr0909 .
MIT · Repository · Original npm · Tarball · package.json
$ npm install gpt3-tokenizer 
SYNC missed versions from official npm registry.

GPT3 Tokenizer

Build NPM Version NPM Downloads

This is a isomorphic TypeScript tokenizer for OpenAI's GPT-3 model. Including support for gpt3 and codex tokenization. It should work in both NodeJS and Browser environments.

Usage

First, install:

yarn add gpt3-tokenizer

In code:

import GPT3Tokenizer from 'gpt3-tokenizer';

const tokenizer = new GPT3Tokenizer({ type: 'gpt3' }); // or 'codex'
const str = "hello 👋 world 🌍";
const encoded: { bpe: number[]; text: string[] } = tokenizer.encode(str);
const decoded = tokenizer.decode(encoded.bpe);

Reference

This library is based on the following:

The main difference between this library and gpt-3-encoder is that this library supports both gpt3 and codex tokenization (The dictionary is taken directly from OpenAI so the tokenization result is on par with the OpenAI Playground). Also Map API is used instead of JavaScript objects, especially the bpeRanks object, which should see some performance improvement.

License

MIT

Current Tags

  • 1.1.5                                ...           latest (4 years ago)

9 Versions

  • 1.1.5                                ...           4 years ago
  • 1.1.4                                ...           4 years ago
  • 1.1.3                                ...           4 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 10
Today 0
This Week 0
This Month 10
Last Day 0
Last Week 9
Last Month 0
Dependencies (1)
Dev Dependencies (6)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE