pub struct SimpleTokenizerV2 { /* private fields */ }
Expand description
[Listing 2.4] A simple text tokenizer that handles unknown words
Implementations§
Source§impl SimpleTokenizerV2
impl SimpleTokenizerV2
Sourcepub fn from_vocab(vocab: HashMap<&str, i32>) -> Self
pub fn from_vocab(vocab: HashMap<&str, i32>) -> Self
Creates a new SimpleTokenizerV2
from a vocab.
use llms_from_scratch_rs::listings::ch02::SimpleTokenizerV2;
use std::collections::HashMap;
let vocab: HashMap<&str, i32> = HashMap::from([
("this", 1_i32),
("is", 2_i32),
("a", 3_i32),
("test", 4_i32)
]);
// Any words not in the vocab will be encoded as "<|unk|>" token
let tokenizer = SimpleTokenizerV2::from_vocab(vocab);
Trait Implementations§
Source§impl Debug for SimpleTokenizerV2
impl Debug for SimpleTokenizerV2
Source§impl Default for SimpleTokenizerV2
impl Default for SimpleTokenizerV2
Source§fn default() -> SimpleTokenizerV2
fn default() -> SimpleTokenizerV2
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SimpleTokenizerV2
impl RefUnwindSafe for SimpleTokenizerV2
impl Send for SimpleTokenizerV2
impl Sync for SimpleTokenizerV2
impl Unpin for SimpleTokenizerV2
impl UnwindSafe for SimpleTokenizerV2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more