Documentation
¶
Overview ¶
Package tiktoken is the byte-pair encoding OpenAI's models count tokens with: a vocabulary of byte strings ranked by merge priority, a pattern that cuts text into pieces before the merges, and special tokens, read from the rank files OpenAI publishes
Index ¶
- Constants
- func DataGym(vocabBPE, encoderJSON []byte) (map[string]int, error)
- func ForModel(model string) (string, bool)
- func ParseRanks(contents []byte) (map[string]int, error)
- type Encoding
- func (e *Encoding) Count(text string, specials bool) int
- func (e *Encoding) Decode(ids []int) string
- func (e *Encoding) DecodeBytes(ids []int) []byte
- func (e *Encoding) Encode(text string, specials bool) []int
- func (e *Encoding) EncodeOrdinary(text string) []int
- func (e *Encoding) ID(token string) (int, bool)
- func (e *Encoding) Size() int
- func (e *Encoding) Spans(text string, specials bool) ([]int, [][2]int)
- func (e *Encoding) Special(id int) bool
- func (e *Encoding) Specials() map[string]int
- func (e *Encoding) Token(id int) (string, bool)
- type File
- type Spec
Constants ¶
const ( EndOfText = "<|endoftext|>" FIMPrefix = "<|fim_prefix|>" FIMMiddle = "<|fim_middle|>" FIMSuffix = "<|fim_suffix|>" EndOfPrompt = "<|endofprompt|>" )
Special tokens every encoding names its own way
Variables ¶
This section is empty.
Functions ¶
func DataGym ¶
Ranks of GPT-2's original files: the merges of vocab.bpe ranked after the 256 single bytes, checked against encoder.json as tiktoken checks them, since the ranks are only right when both say the same
Types ¶
type Encoding ¶
type Encoding struct {
Name string
// contains filtered or unexported fields
}
A vocabulary of ranked byte strings with the pattern that cuts text before merging and the special tokens beside it
func Build ¶
The encoding a spec makes of the contents of its files, given in the order Files names them
func New ¶
Encoding of a split pattern in tiktoken's own syntax, the ranks of its byte strings and its special tokens by id
func (*Encoding) Decode ¶
Text of the tokens, bytes that are no text replaced as tiktoken replaces them
func (*Encoding) DecodeBytes ¶
Bytes of the tokens, joined
func (*Encoding) Encode ¶
Tokens of a text, a special token written in it read as itself when specials is set and as text otherwise
func (*Encoding) EncodeOrdinary ¶
Tokens of a text with every special token read as text
func (*Encoding) Spans ¶
Tokens of a text with the byte range of the text each covers; a token of part of a character covers the bytes it holds
type File ¶
A file an encoding's ranks are read from, at the address OpenAI publishes it with the digest it publishes for it
type Spec ¶
type Spec struct {
Name string
Pattern string
// Special tokens by id
Specials map[string]int
// One rank file, or GPT-2's vocab.bpe and encoder.json in that order
Files []File
// The vocabulary is GPT-2's data-gym pair rather than a rank file
DataGym bool
// Ids the encoding states it has, zero when it states none
Vocab int
}
An encoding OpenAI publishes: how it cuts text, its special tokens and the files of its ranks