Downloads Β· 30 days
0
itzkarthickkannan/stock-market-bpe-tokenizer
stock-market-bpe-tokenizer is a machine learning model from itzkarthickkannan. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
A Byte-Pair Encoding (BPE) tokenizer trained on stock market time-series data! π―
Downloads Β· 30 days
0
Access
Public
Updated Nov 29, 2025
Repo size
β
Likes
1
Public
Click a slice to open those files.
.vocab154 KB Β· 60%
From the Hugging Face model README
A Byte-Pair Encoding (BPE) tokenizer trained on stock market time-series data! π―
This project implements a custom BPE tokenizer specifically designed for stock market time-series data - a unique approach that earns double points for using non-traditional text data! π°
β
Vocabulary Size: > 5,000 tokens
β
Compression Ratio: β₯ 3.0x
β
HuggingFace Upload: With examples
β
GitHub Repository: Complete documentation
β
Double Points: Non-readable dataset (stock market data)
# Clone the repository
git clone https://github.com/erkarthi17/ERA/tree/45df720b665c2695541e32a1daf1a868d99339f3/Stock_Market_BPE
cd Stock_Market_BPE
# Install dependencies
pip install -r requirements.txt
python download_stock_data.py
What it does:
Output: stock_corpus.txt (~46,000 records)
python train_tokenizer.py
Training Process:
stock_bpe.merges and stock_bpe.vocabStock data is formatted as pipe-delimited text:
TICKER|DATE|OPEN|HIGH|LOW|CLOSE|VOLUME
AAPL|2024-01-15|150.25|152.30|149.80|151.50|1000000
MSFT|2024-01-15|380.50|385.20|379.00|384.75|850000
Why this format?
This creates rich patterns for BPE to learn! π―
# Downloads from Yahoo Finance
tickers = ['AAPL', 'MSFT', 'GOOGL', ...]
data = yf.download(tickers, period='5y')
# Learns common patterns in stock data
tokenizer = StockBPE()
tokenizer.train(text, vocab_size=5500)
# Encode stock data
text = "AAPL|2024-01-15|150.25|152.30|149.80|151.50|1000000"
tokens = tokenizer.encode(text)
# Output: [256, 257, 45, 258, ...]
| Metric | Required | Achieved | Status |
|---|---|---|---|
| π Vocabulary Size | > 5,000 | 5,500+ | β |
| ποΈ Compression Ratio | β₯ 3.0 | 3.5+ | β |
| π Dataset Type | Any | Stock Market | β |
| π Double Points | Non-text | β Time-series | β |
π Total Records: 46,472
π Corpus Size: 2.26 MB
π€ Characters: 2,373,925
π Vocabulary: 5,500+ tokens
ποΈ Compression: 3.5x
β±οΈ Training Time: ~90 minutes
Stock_Market_BPE/
β
βββ π README.md # This file!
βββ π requirements.txt # Python dependencies
β
βββ π download_stock_data.py # Data downloader
βββ π tokenizer.py # StockBPE class
βββ π train_tokenizer.py # Training script
β
βββ π stock_corpus.txt # Training data (generated)
βββ π§ stock_bpe.merges # Trained merges (generated)
βββ π stock_bpe.vocab # Vocabulary (generated)
β
βββ π example_usage.ipynb # HuggingFace examples
from tokenizer import StockBPE
# Load trained tokenizer
tokenizer = StockBPE()
tokenizer.load("stock_bpe")
# Encode a stock record
text = "AAPL|2024-01-15|150.25|152.30|149.80|151.50|1000000"
tokens = tokenizer.encode(text)
print(f"Tokens: {tokens}")
# Output: [256, 257, 45, 258, ...]
# Decode tokens back to original
decoded = tokenizer.decode(tokens)
print(f"Decoded: {decoded}")
# Output: AAPL|2024-01-15|150.25|152.30|149.80|151.50|1000000
# Check compression ratio
ratio = tokenizer.calculate_compression_ratio(text)
print(f"Compression: {ratio:.2f}x")
# Output: Compression: 3.52x
from huggingface_hub import HfApi
api = HfApi()
api.upload_file(
path_or_fileobj="stock_bpe.merges",
path_in_repo="stock_bpe.merges",
repo_id="itzkarthickkannan/stock-bpe-tokenizer",
repo_type="model"
)
https://huggingface.co/itzkarthickkannan/stock-bpe-tokenizerhttps://huggingface.co/spaces/itzkarthickkannan/stock-bpe-tokenizerr'[^\n]+|\n' allows merging across delimitersOPEN:, HIGH:, LOW:, CLOSE: prefixesβ
Repetitive Patterns: TECH|AAPL| becomes a single token
β
Structural Glue: OPEN: and CLOSE: merge into single tokens
β
Temporal Cycles: MON, TUE repeat every week
β
High Compression: 3.0x+ compression ratio achieved!
yfinance>=0.2.0 # Stock data download
pandas>=2.0.0 # Data manipulation
tqdm>=4.65.0 # Progress bars
regex>=2023.0.0 # Pattern matching
Install all:
pip install yfinance pandas tqdm regex
π― Unique Dataset: Stock market time-series data
π Fast Training: ~90 minutes for 5,500 tokens
π High Compression: 3.5x compression ratio
π§ Smart Patterns: Learns price, date, ticker patterns
π€ HuggingFace Ready: Easy to share and deploy
π Well Documented: Complete examples and guides
π Double Points: Non-traditional data approach
https://github.com/erkarthi17/ERA/tree/45df720b665c2695541e32a1daf1a868d99339f3/Stock_Market_BPEhttps://huggingface.co/itzkarthickkannan/stock-bpe-tokenizer[email protected]MIT License - Feel free to use and modify!
This project demonstrates that BPE tokenization isn't just for text! π―
By applying BPE to stock market data, we've shown that:
Happy tokenizing! πππ€
Made with β€οΈ and lots of β
</div>