This repository contains a small Byte-Pair Encoding (BPE) tokenizer implemented in JavaScript for the command line.
It is designed as an educational tool — not a production-grade tokenizer — but it's fully runnable and demonstrates the full pipeline:
- Training merges from a corpus
- Saving vocab + merges
- Tokenizing text into subword pieces
- Encoding to IDs
- Decoding back to text
tokenizer-bpe.js: BPE tokenizer implementationcli.js: Command-line wrapper for training, encoding, decoding, tokenizing, and infocorpus.txt: Small sample corpuspackage.json: npm metadatavocab_example.json: Example vocab + merges (generated by runningtrain)README.md: This file
# 1. Extract the zip (if applicable) or clone the repo
# 2. Make the CLI executable (optional on Windows)
chmod +x cli.js
# 3. Train (creates vocab.json)
node cli.js train corpus.txt vocab.json --minfreq=2 --ops=2000
# 4. Encode
node cli.js encode vocab.json "Hello world!"
# 5. Tokenize (see subword pieces)
node cli.js tokenize vocab.json "Hello world!"
# 6. Decode (example: replace <ids> with output from encode)
node cli.js decode vocab.json <ids>


