Vocabulary Projection #
A bounded vocabulary retains token ids in first-occurrence order. Local id zero is reserved for an explicit unknown token; tokens beyond capacity map to it. Token streams remain tensors while the reverse lookup uses a hash map of vocabulary metadata.
Original token ids and reverse lookup for an assigned prefix of a fixed-capacity vocabulary.
Original token ids in local-id order; only the assigned prefix is used.
- size : ℕ
Number of assigned local ids, including the reserved unknown-token slot.
The assigned prefix fits in the storage tensor.
- toLocalMap : Std.HashMap ℕ ℕ
Lookup from original token ids to their assigned local ids.
- unknownToken : ℕ
Original token id returned when decoding an unassigned local id.
Instances For
Map an original token id to its assigned local id, defaulting to the unknown-token slot.
Instances For
Decode an assigned local id, using the explicit unknown token for an unassigned id.
Instances For
Start a vocabulary with one reserved unknown token.
Instances For
Extend in row-major token order, retaining existing ids when capacity is full.
Instances For
Build a vocabulary from a token tensor, reserving local id zero for unknownToken.
Instances For
Project every token while retaining the shape of the original stream or batch.
Instances For
Decode every local token while retaining the stream or batch shape.