Encoded

Struct Encoded 

Source
pub struct Encoded<'a> { /* private fields */ }
Expand description

Output produced by a Tokenizer::encode implementation.

Use Encoded::token_ids to get the token IDs to feed to a model, and Encoded::text_for_token_range to map token ID ranges back to the corresponding input text.

Implementations§

Source§

impl<'a> Encoded<'a>

Source

pub fn token_ids(&self) -> &[TokenId]

Return the sequence of token IDs that the input was tokenized into.

Source

pub fn into_token_ids(self) -> Vec<TokenId>

Consume self and return a list of token IDs.

This is a convenient way to discard other information from the encoded output and get the token IDs as an owned vector.

Source

pub fn token_offsets(&self) -> &[usize]

Return the byte offsets of the start of each token in the input sequence. If the input contained two sequences, the offsets are assigned as if the two sequences were concatenated.

Source

pub fn token_type_ids(&self) -> impl Iterator<Item = usize>

Return an iterator of the inputs for the token_type_ids input field in the model, if it has one.

Source

pub fn text_for_token_range(&self, range: Range<usize>) -> Option<&'a str>

Return the text from the input sequence(s) that corresponds to a range of token indices. If the input contained two sequences, the range must lie entirely within one of them.

Trait Implementations§

Source§

impl<'a> Debug for Encoded<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Encoded<'a>

§

impl<'a> RefUnwindSafe for Encoded<'a>

§

impl<'a> Send for Encoded<'a>

§

impl<'a> Sync for Encoded<'a>

§

impl<'a> Unpin for Encoded<'a>

§

impl<'a> UnwindSafe for Encoded<'a>

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> 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, 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.