[][src]Struct rust_tokenizers::tokenizer::Gpt2Tokenizer

pub struct Gpt2Tokenizer { /* fields omitted */ }

GPT2 tokenizer

GPT2 tokenizer performing:

  • splitting on special characters
  • whitespace splitting
  • (optional) lower casing
  • BPE tokenization

Implementations

impl Gpt2Tokenizer[src]

pub fn from_file(
    vocab_path: &str,
    merges_path: &str,
    lower_case: bool
) -> Result<Gpt2Tokenizer, TokenizerError>
[src]

Create a new instance of a Gpt2Tokenizer Expects a vocabulary json file and a merges file as an input.

Parameters

  • vocab_path (&str): path to the vocabulary file
  • merges_path (&str): path to the merges file (use as part of the BPE encoding process)
  • lower_case (bool): flag indicating if the text should be lower-cased as part of the tokenization

Example

use rust_tokenizers::tokenizer::{Gpt2Tokenizer, Tokenizer};
let lower_case = false;
let tokenizer =
    Gpt2Tokenizer::from_file("path/to/vocab/file", "path/to/merges/file", lower_case).unwrap();

pub fn from_existing_vocab_and_merges(
    vocab: Gpt2Vocab,
    merges: BpePairVocab,
    lower_case: bool
) -> Gpt2Tokenizer
[src]

Create a new instance of a Gpt2Tokenizer from an existing vocabulary and merges

Parameters

  • vocab (Gpt2Vocab): GPT-like vocabulary
  • merges (BpePairVocab): BPE pairs vocabulary
  • lower_case (bool): flag indicating if the text should be lower-cased as part of the tokenization

Example

use rust_tokenizers::tokenizer::{Gpt2Tokenizer, Tokenizer};
use rust_tokenizers::vocab::{BpePairVocab, Gpt2Vocab, Vocab};
let lower_case = false;
let vocab = Gpt2Vocab::from_file("path/to/vocab/file").unwrap();
let merges = BpePairVocab::from_file("path/to/merges/file").unwrap();

let tokenizer = Gpt2Tokenizer::from_existing_vocab_and_merges(vocab, merges, lower_case);

Trait Implementations

impl MultiThreadedTokenizer<Gpt2Vocab> for Gpt2Tokenizer[src]

impl Tokenizer<Gpt2Vocab> for Gpt2Tokenizer[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.