Documentation
¶
Overview ¶
Package bpe implements Byte Pair Encoding tokenization.
Index ¶
Constants ¶
View Source
const ( EndOfText = "<|endoftext|>" FIMPrefix = "<|fim_prefix|>" FIMMiddle = "<|fim_middle|>" FIMSuffix = "<|fim_suffix|>" EndOfPrompt = "<|endofprompt|>" )
Special token constants.
View Source
const ( EncodingO200kBase = "o200k_base" EncodingCL100kBase = "cl100k_base" EncodingP50kBase = "p50k_base" EncodingP50kEdit = "p50k_edit" EncodingR50kBase = "r50k_base" )
Encoding names.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BPETokenizer ¶
type BPETokenizer struct {
// contains filtered or unexported fields
}
BPETokenizer is the main tokenizer that wraps a BPE Encoder.
func NewEncoderByName ¶
func NewEncoderByName(encodingName string) (*BPETokenizer, error)
NewEncoderByName returns a BPETokenizer for the named encoding.
func (*BPETokenizer) Decode ¶
func (tok *BPETokenizer) Decode(tokens []int) string
Decode converts token IDs back to text.
func (*BPETokenizer) Encode ¶
func (tok *BPETokenizer) Encode(text string, allowedSpecial []string, disallowedSpecial []string) ([]int, error)
Encode tokenizes text with optional special token handling. Returns an error if text contains a disallowed special token.
func (*BPETokenizer) EncodeOrdinary ¶
func (tok *BPETokenizer) EncodeOrdinary(text string) []int
EncodeOrdinary tokenizes text without special token handling.
type Definition ¶
type Definition struct {
Name string
PatStr string
MergeableRanks map[string]int
SpecialTokens map[string]int
ExplicitNVocab int
}
Definition holds the specification for a BPE encoding scheme.
Click to show internal directories.
Click to hide internal directories.