File size: 3,013 Bytes
6919ba5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | ---
language:
- en
license: apache-2.0
tags:
- tokenizer
- sentencepiece
- bpe
- code
---
# NiftyOracle Tokenizer
**A 50,000-piece SentencePiece BPE tokenizer for code and text, used by [CodeSymb-1B](https://huggingface.co/NiftyOracleAI/CodeSymb-1B-MI325X).**
| Setting | Value |
| --- | --- |
| File | `niftyoracle_tokenizer.model` |
| Algorithm | SentencePiece BPE |
| Vocabulary | 50,000 pieces |
| Normalization | `nmt_nfkc` |
| Digits | Split into single digits (`2026` → `2` `0` `2` `6`) |
| Byte fallback | Off |
| Character coverage | 0.9999 |
| Special IDs | `<pad>` 0 · `<unk>` 1 · `<bos>` 2 · `<eos>` 3 |
## Special tokens
27 user-defined symbols (IDs 4–30). Each is always encoded as a single token.
| Group | Tokens (IDs) |
| --- | --- |
| Code structure | `<code>` `</code>` (4–5) · `<function>` `</function>` (6–7) · `<class>` `</class>` (8–9) |
| Debugging | `<bug>` `</bug>` (10–11) · `<fix>` `</fix>` (12–13) · `<error>` `</error>` (14–15) |
| Languages | `<python>` 16 · `<javascript>` 17 · `<java>` 18 · `<cpp>` 19 · `<go>` 20 · `<rust>` 21 · `<typescript>` 22 · `<sql>` 23 · `<shell>` 24 |
| Retrieval | `<query>` `</query>` (25–26) · `<answer>` `</answer>` (27–28) |
| Reasoning | `<think>` `</think>` (29–30) |
## Usage
```python
from huggingface_hub import hf_hub_download
import sentencepiece as spm
path = hf_hub_download("NiftyOracleAI/niftyoracle-tokenizer", "niftyoracle_tokenizer.model")
sp = spm.SentencePieceProcessor(model_file=path)
print(sp.encode("def add(a, b): return a + b", out_type=str))
# ['▁def', '▁add', '(', 'a', ',', '▁b', '):', '▁return', '▁a', '▁+', '▁b']
```
## Known limitations
- **Whitespace is not preserved.** The `nmt_nfkc` normalizer turns newlines, tabs and runs of spaces into a single space, so indentation-sensitive code (such as Python) does not round-trip.
- **No byte fallback.** Characters outside the vocabulary (some emoji, rare scripts) become `<unk>`.
### Whitespace codec (used by CodeSymb-1B)
CodeSymb-1B works around the whitespace limitation without changing this tokenizer. Seven pieces that never occurred in its training data are given fixed whitespace meanings; text between whitespace is still encoded by this tokenizer.
| ID | Original piece | Meaning |
| --- | --- | --- |
| 46632 | `CHOPEL` | newline |
| 46642 | `ETHFSx` | tab |
| 46648 | `GENlep` | 1 space |
| 42206 | `FakeNodeGroup` | 2 spaces |
| 37796 | `JobTickStatus` | 4 spaces |
| 42279 | `Repairprogress` | 8 spaces |
| 42227 | `getyesterdaty` | 16 spaces |
The codec (`ws_codec.py`) ships in the CodeSymb-1B repository, inside `backup/state_final.tgz`. A model trained with the codec must use it for both encoding and decoding.
## Used by
- [NiftyOracleAI/CodeSymb-1B-MI325X](https://huggingface.co/NiftyOracleAI/CodeSymb-1B-MI325X): a 1.18B-parameter code model trained from scratch on 8× AMD Instinct MI325X.
Built by Dev Malkar, NiftyOracle AI. Questions: open a discussion in the Community tab.
|