Skip to content
class

BPE

extendsTokenizer
BPE

Constructors

1

Methods

9
fnconst

decode

int decode(const int & ids)
fnconst

encode

int encode(const int & text)

── Tokenizer overrides ────────────────────────────────────────

fnconst

encode_chunk_

int encode_chunk_(const int & chunk)

Apply the merge sequence to one pre-tokenized chunk. Operates on a working buffer of (id, next-pair-rank) pairs and repeatedly picks the lowest-rank pair to merge. O(N · log K) per chunk where N = chunk length and K = #active merges (typically << M because most merges' pairs never appear in the chunk).

fnconst

id_to_token

int id_to_token(int id)
fn

rebuild_tables_

void rebuild_tables_()

Rebuild id_to_token_ + pair_to_merge_ from the current vocab_ + merges_str_. Called after construction and after train.

fn

train

void train(const int & corpus, int target_vocab_size)