Learn a subword tokenizer
Learn a byte-pair encoder from a corpus, save it, and split new words into its subwords (byte-pair encoders).
$ cat corpus.txt
low low low low lower lower newest newest newest widest
Learn the merges
Each merge joins the most frequent adjacent pair; the merges print in the order learned:
$ trex bpe train corpus.txt --merges 3
trex bpe: learned 3 merges from 56 bytes in 0.0s
l o
lo w
e s
Split words with it
Ten merges saved as words.bpe, the list train prints:
$ cat words.bpe
l o
lo w
e s
es t
est </w>
low </w>
e w
ew est</w>
n ewest</w>
e r
$ trex bpe encode --text 'lower' --model words.bpe
low er </w>
</w> marks a word’s end. The saved model is the merge list train prints, one pair a line,
and trex bpe encode --model FILE splits text with it.