Text Generation
Transformers
English
custom
tokenizer
symbolic-ai
mathematics
llm
reasoning
ast
compiler
nlp
deep-learning
machine-learning
mathematical-reasoning
symbolic-reasoning
tokenization
parser
artificial-intelligence
Eval Results (legacy)
Instructions to use SurweeshSP/mathtok with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SurweeshSP/mathtok with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="SurweeshSP/mathtok")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("SurweeshSP/mathtok", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use SurweeshSP/mathtok with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "SurweeshSP/mathtok" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SurweeshSP/mathtok", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/SurweeshSP/mathtok
- SGLang
How to use SurweeshSP/mathtok with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "SurweeshSP/mathtok" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SurweeshSP/mathtok", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "SurweeshSP/mathtok" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SurweeshSP/mathtok", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use SurweeshSP/mathtok with Docker Model Runner:
docker model run hf.co/SurweeshSP/mathtok
SurweeshSP commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -94,27 +94,126 @@ Compressed Token Stream
|
|
| 94 |
```
|
| 95 |
|
| 96 |
---
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
```bash
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
pip install -e ".[eval,dev]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
python -m mathtok.pipeline "The derivative of sin(x^2) + 3x"
|
|
|
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
pytest tests/ -v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
python -m evaluation.comparison
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
python -m evaluation.visualize
|
| 116 |
```
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
---
|
| 119 |
|
| 120 |
## Python API
|
|
|
|
| 94 |
```
|
| 95 |
|
| 96 |
---
|
| 97 |
+
## Installation
|
| 98 |
|
| 99 |
+
Clone the repository and install the package in editable mode:
|
| 100 |
|
| 101 |
```bash
|
| 102 |
+
git clone https://github.com/SurweeshSP/mathtok.git
|
| 103 |
+
|
| 104 |
+
cd mathtok
|
| 105 |
+
|
| 106 |
pip install -e ".[eval,dev]"
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
## Quick Start
|
| 111 |
+
|
| 112 |
+
### Tokenize a Mathematical Expression
|
| 113 |
+
|
| 114 |
+
Run the tokenizer pipeline directly from the command line:
|
| 115 |
|
| 116 |
+
```bash
|
| 117 |
python -m mathtok.pipeline "The derivative of sin(x^2) + 3x"
|
| 118 |
+
```
|
| 119 |
|
| 120 |
+
Example output:
|
| 121 |
+
|
| 122 |
+
```text
|
| 123 |
+
[
|
| 124 |
+
FUNCTION_SIN,
|
| 125 |
+
VARIABLE_x,
|
| 126 |
+
POWER,
|
| 127 |
+
NUMBER_2,
|
| 128 |
+
OP_ADD,
|
| 129 |
+
NUMBER_3,
|
| 130 |
+
VARIABLE_x
|
| 131 |
+
]
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## Running the Test Suite
|
| 137 |
+
|
| 138 |
+
Execute the comprehensive unit and integration test suite:
|
| 139 |
+
|
| 140 |
+
```bash
|
| 141 |
pytest tests/ -v
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
Current coverage includes:
|
| 145 |
+
|
| 146 |
+
- AST generation
|
| 147 |
+
- Canonicalization
|
| 148 |
+
- Lexer validation
|
| 149 |
+
- Pipeline integration
|
| 150 |
+
- Serialization consistency
|
| 151 |
+
- Structural comparison metrics
|
| 152 |
+
|
| 153 |
+
---
|
| 154 |
|
| 155 |
+
## Comparative Tokenizer Evaluation
|
| 156 |
+
|
| 157 |
+
Run the full benchmark evaluation pipeline:
|
| 158 |
+
|
| 159 |
+
```bash
|
| 160 |
python -m evaluation.comparison
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
This benchmark compares:
|
| 164 |
+
|
| 165 |
+
- MathTok (Hybrid AST Tokenizer)
|
| 166 |
+
- GPT-2 BPE
|
| 167 |
+
- SentencePiece Unigram
|
| 168 |
+
- Character-Level Tokenization
|
| 169 |
+
|
| 170 |
+
Evaluation metrics include:
|
| 171 |
+
|
| 172 |
+
- Symbolic Compression Ratio (SCR)
|
| 173 |
+
- Semantic Density
|
| 174 |
+
- Structural Efficiency
|
| 175 |
+
- Token Fragmentation
|
| 176 |
+
- Sequence Compactness
|
| 177 |
+
|
| 178 |
+
---
|
| 179 |
+
|
| 180 |
+
## Visualization Dashboard
|
| 181 |
|
| 182 |
+
Generate benchmark plots and the unified evaluation dashboard:
|
| 183 |
+
|
| 184 |
+
```bash
|
| 185 |
python -m evaluation.visualize
|
| 186 |
```
|
| 187 |
|
| 188 |
+
Generated outputs include:
|
| 189 |
+
|
| 190 |
+
- Semantic Density Comparison
|
| 191 |
+
- SCR Comparison
|
| 192 |
+
- Structural Efficiency Comparison
|
| 193 |
+
- Token Count Analysis
|
| 194 |
+
- Unified Metrics Dashboard
|
| 195 |
+
|
| 196 |
+
All generated figures are stored in:
|
| 197 |
+
|
| 198 |
+
```text
|
| 199 |
+
evaluation/results/
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
---
|
| 203 |
+
|
| 204 |
+
## Repository Structure
|
| 205 |
+
|
| 206 |
+
```text
|
| 207 |
+
mathtok/
|
| 208 |
+
βββ mathtok/ # Core tokenizer framework
|
| 209 |
+
βββ evaluation/ # Benchmarking and evaluation
|
| 210 |
+
βββ tests/ # Comprehensive test suite
|
| 211 |
+
βββ assets/ # Architecture diagrams
|
| 212 |
+
βββ README.md
|
| 213 |
+
βββ setup.py
|
| 214 |
+
βββ pyproject.toml
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
---
|
| 218 |
|
| 219 |
## Python API
|