yum/FastTextPager
Compressed text paging over OSC.
git clone https://git.yummers.dev/yum/FastTextPager
0c54e1f
master
1import argparse 2import sentencepiece as spm 3 4def get_tokenizer (): 5model_path = "./custom_unigram_tokenizer_65k/unigram.model" 6f"Loading SentencePiece tokenizer from: { model_path } " ) 7sp = spm .SentencePieceProcessor () 8sp .load (model_path ) 9f"Successfully loaded SentencePiece model. Vocab size: { sp . get_piece_size () } " ) 10return sp 11 12def parse_args (): 13parser = argparse .ArgumentParser (description = "Tokenize a given string using a SentencePiece model." ) 14parser .add_argument ("text" ,type = str ,help = "The string to tokenize." ) 15args = parser .parse_args () 16return args 17 18args = parse_args () 19tok = get_tokenizer () 20tokens = tok .encode_as_pieces (args .text ) 21"Tokens:" ,tokens ) 22 23token_ids = tok .encode_as_ids (args .text ) 24"Token IDs:" ,token_ids ) 25 26# Split each token ID into two 8-bit chunks (high byte, low byte) 27byte_pairs = [(tid >> 8 ,tid & 0xFF )for tid in token_ids ] 28"Token ID Byte Pairs:" ,byte_pairs )