tokenizers

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Formats = "" /* 186-byte string literal not displayed */

Formats names the tokenizer files Load reads, in the order it looks for them

Variables

This section is empty.

Functions

This section is empty.

Types

type AddedToken

type AddedToken struct {
	ID         int    `json:"id"`
	Content    string `json:"content"`
	SingleWord bool   `json:"single_word"`
	LStrip     bool   `json:"lstrip"`
	RStrip     bool   `json:"rstrip"`
	Normalized bool   `json:"normalized"`
	Special    bool   `json:"special"`
}

AddedToken is a token cut out of the text before the model runs

type Dir

type Dir string

Dir is a snapshot folder on disk

func (Dir) Has

func (d Dir) Has(name string) bool

func (Dir) Read

func (d Dir) Read(name string) ([]byte, error)

type Encoder

type Encoder interface {
	Encode(text string) ([]int, error)
}

Encoder gives the token ids of a text

func Load

func Load(src Source) (Encoder, error)

Load reads the tokenizer of a snapshot from whichever tokenizer file it ships

type Source

type Source interface {
	Has(name string) bool
	Read(name string) ([]byte, error)
}

Source reads the files of one tokenizer snapshot

type Tokenizer

type Tokenizer struct {
	// contains filtered or unexported fields
}

Tokenizer runs the pipeline one tokenizer.json describes

func FromJSON

func FromJSON(data []byte) (*Tokenizer, error)

FromJSON builds the tokenizer a tokenizer.json file describes

func (*Tokenizer) Decode

func (t *Tokenizer) Decode(ids []int, skipSpecial bool) (string, error)

Decode returns the text of token ids, leaving special tokens out when skipSpecial is set

func (*Tokenizer) Encode

func (t *Tokenizer) Encode(s string) ([]int, error)

Encode returns the token ids of a text with the special tokens the post processor adds

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL