tokenizer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT, MIT Imports: 10 Imported by: 0

Documentation

Overview

Source: github.com/tiktoken-go/tokenizer/codec/codec.go@v0.8.1 The splitting and byte-pair merge algorithm is retained verbatim; long pieces use an equivalent heap merge, and vocabulary storage is owned by tokenizer.go. See LICENSE for the upstream MIT license.

Package tokenizer provides Mekugi's pinned GPT-5 (o200k_base) tokenizer.

The vocabulary is embedded data, not a generated Go map. Token IDs and the splitting/BPE algorithm match github.com/tiktoken-go/tokenizer v0.8.1. Special-token spellings in source are ordinary text, not control tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

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

Codec tokenizes text with the pinned o200k_base vocabulary. Use New to initialize a codec with its own regexp.

func New

func New() (*Codec, error)

New returns a codec with immutable shared vocabulary and its own regexp.

func (*Codec) Count

func (c *Codec) Count(input string) (int, error)

Count returns the number of tokens in the input string.

func (*Codec) Decode

func (c *Codec) Decode(tokens []uint) (string, error)

func (*Codec) Encode

func (c *Codec) Encode(input string) ([]uint, []string, error)

Encode returns the token IDs and tokens for the input string.

func (*Codec) GetName

func (c *Codec) GetName() string

func (*Codec) SelectRows

func (c *Codec) SelectRows(value string, limit int, tail bool) (string, error)

SelectRows admits LF-terminated rows in order, stopping at the first row that exceeds limit. Tail admission walks backwards but returns source order. Completed regexp pieces never change at a later row boundary. Only the piece crossing that boundary needs to be recounted, including newline/whitespace runs whose BPE counts need not grow monotonically.

Directories

Path Synopsis
Package codec registers the pinned upstream generated regex engines.
Package codec registers the pinned upstream generated regex engines.

Jump to

Keyboard shortcuts

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