TokenMapping

Struct TokenMapping 

Source
pub struct TokenMapping { /* private fields */ }
Expand description

Maps TØR-G tokens to LLM vocabulary token IDs.

TØR-G has 9 fixed tokens plus a range of Id tokens. This struct provides bidirectional mapping between TØR-G tokens and the corresponding token IDs in an LLM’s vocabulary.

Implementations§

Source§

impl TokenMapping

Source

pub fn builder() -> TokenMappingBuilder

Create a builder for custom token mappings.

Source

pub fn sequential(id_count: u16) -> Self

Example mapping using sequential IDs starting from 0.

Warning: This is for testing only. In production, you must map to actual unused token IDs in your LLM’s vocabulary.

Layout:

  • 0: Or
  • 1: Nor
  • 2: Xor
  • 3: NodeStart
  • 4: NodeEnd
  • 5: InputDecl
  • 6: OutputDecl
  • 7: True
  • 8: False
  • 9..265: Id(0)..Id(255)
Source

pub fn ministral() -> Self

Mapping for Mistral/Ministral models using reserved <SPECIAL_N> tokens.

Ministral tokenizers reserve token IDs 36-565 as <SPECIAL_N> placeholders. This mapping uses IDs 36-300 for TØR-G tokens:

TØR-G TokenMinistral ID
Or36
Nor37
Xor38
NodeStart39
NodeEnd40
InputDecl41
OutputDecl42
True43
False44
Id(0)45
Id(255)300

Compatible with: Ministral-3B, Ministral-8B, Mistral-7B v0.3+

Source

pub fn get(&self, token: Token) -> Option<u32>

Map a TØR-G token to its LLM vocabulary ID.

Returns None if the token cannot be mapped (e.g., Id out of range).

Source

pub fn reverse(&self, id: u32) -> Option<Token>

Map an LLM vocabulary ID back to a TØR-G token.

Returns None if the ID doesn’t correspond to any mapped token.

Source

pub fn id_count(&self) -> u16

Get the number of Id tokens mapped.

Source

pub fn total_tokens(&self) -> usize

Get the total number of mapped tokens (9 fixed + id_count).

Trait Implementations§

Source§

impl Clone for TokenMapping

Source§

fn clone(&self) -> TokenMapping

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenMapping

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TokenMapping

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for TokenMapping

Source§

fn eq(&self, other: &TokenMapping) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TokenMapping

Source§

impl StructuralPartialEq for TokenMapping

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.