Skip to content
class

RoFormerTokenizer

extendsWordPieceTokenizer
RoFormerTokenizer(vocab: dict[str, int], unk_token: str = '[UNK]', continuing_prefix: str = '##', max_chars_per_word: int = 100, do_lower_case: bool = True, normalizer: Normalizer | None = None, pre_tokenizer: PreTokenizer | None = None, special_tokens: SpecialTokens | None = None)

RoFormer tokenizer — pure-Python reference.

Identical algorithm to lucid.models.text.bert.BERTTokenizer (WordPiece longest-match with [UNK]/[CLS]/[SEP]/[PAD]/[MASK] registered out of the box). Kept as a separate class so every text-model family exposes a uniform from lucid.models.text.<family> import {Family}Tokenizer surface — useful for generic model-loading helpers.

Parameters

vocabdict[str, int]
BERT-style vocab with ## continuation prefix.
unk_tokenstr= "[UNK]"
No description.
continuing_prefixstr= "##"
No description.
max_chars_per_wordint= 100
No description.
do_lower_casebool= True
Set False for cased RoFormer checkpoints.
normalizerNormalizer= None
No description.
pre_tokenizerPreTokenizer= None
No description.
special_tokensSpecialTokens= None
No description.

Examples

>>> from lucid.models.text.roformer._tokenizer import RoFormerTokenizer
>>> vocab = {"[UNK]": 0, "he": 1, "##llo": 2}
>>> tok = RoFormerTokenizer(vocab=vocab)
>>> tok.encode("hello")
[1, 2]
WordPiece: the longest prefix in the vocabulary wins, and what is
left continues with the ## marker.  With [CLS] and [SEP]
in the vocabulary the sequence is framed as BERT frames it:
>>> vocab = {"[UNK]": 0, "[CLS]": 1, "[SEP]": 2, "he": 3, "##llo": 4}
>>> RoFormerTokenizer(vocab=vocab).encode("hello")
[1, 3, 4, 2]

See Also

Used by 1

Constructors

1
dunder

__init__

→None
__init__(vocab: dict[str, int], unk_token: str = '[UNK]', continuing_prefix: str = '##', max_chars_per_word: int = 100, do_lower_case: bool = True, normalizer: Normalizer | None = None, pre_tokenizer: PreTokenizer | None = None, special_tokens: SpecialTokens | None = None)