Views
No views yet
1from tokenizers import Tokenizer
2
3# Load tokenizer
4tokenizer = Tokenizer.from_file("tokenizer.json")
5
6# Simple formula
7encoding = tokenizer.encode("(MA0.1FA0.9)PbCl3")
8print(encoding.tokens)
9# ['[LB]', 'MA', '0', '[DOT]', '1', 'FA', '0', '[DOT]', '9', '[RB]', 'Pb', 'Cl', '3']
10# With special tokens (if enabled)
11# ['[CLS]', '[LB]', 'MA', '0', '[DOT]', '1', 'FA', '0', '[DOT]', '9', '[RB]', 'Pb', 'Cl', '3', '[SEP]']
12
13# Complex formula with fractional composition
14encoding = tokenizer.encode("(DMA0.1FA0.9)Pb(Cl0.1Br0.9)3")
15print(encoding.tokens)
16#['[LB]', 'DMA', '0', '[DOT]', '1', 'FA', '0', '[DOT]', '9', '[RB]', 'Pb', '[LB]', 'Cl', '0', '[DOT]', '1', 'Br', '0', '[DOT]', '9', '[RB]', '3'][PAD], [UNK], [CLS], [SEP], [MASK], [DOT], [LB], [RB]0.5 → 0 [DOT] 5() → [LB] ... [RB]