# theschoolofai/brahmictokenizer-131k architecture

> Architecture diagram of the GitHub repository theschoolofai/brahmictokenizer-131k, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/theschoolofai/brahmictokenizer-131k
- Repository: https://github.com/theschoolofai/brahmictokenizer-131k

## Overview

1. This repository is a tokenizer research and reproduction package, not an application runtime. The central artifact is `tokenizer.json`, a 131,072-vocabulary byte-level BPE tokenizer intended as a drop-in replacement for `o200k_base` in downstream training or evaluation pipelines.

2. The architecture is centered on one immutable model artifact plus multiple verification and measurement layers around it. The tokenizer is treated as the source of truth; every script either validates structural constraints on that artifact or measures its behavior on benchmark corpora and tasks.

3. The core boundary is between the tokenizer artifact and external data/services. The repo itself does not ship training data; the evaluation scripts fetch public datasets and third-party tokenizers at runtime from Hugging Face or canonical dataset hosts. This means reproducibility depends on network access and accepted dataset/model licenses.

4. There are four lightweight structural verification scripts that operate directly on `tokenizer.json`. They check constraints such as no cross-script merges, maximum byte length, Kronecker-style structural conditions, and byte-identical structural identity against a reference tokenizer family. These are the fastest confidence checks and are designed for reviewer smoke testing.

5. The evaluation subsystem measures tokenizer efficiency on benchmark tasks. `evaluate_fertility_flores.py` and `evaluate_fertility_in22.py` compute fertility on FLORES-200 and IN22-Gen across multiple competing tokenizers, while `evaluate_code_math.py` targets code and math datasets such as HumanEval, MBPP, and GSM8K. These scripts are comparative benchmarks, not model inference pipelines.

6. The corpus tokenization subsystem is `tokenize_full_indic_corpus.py`. It reads large Indic corpora from multiple sources, tokenizes them with different tokenizer choices, and aggregates corpus-wide compression statistics. This is the heaviest data-processing path in the repo and is used to support the headline corpus-level claims in the README.

7. The audit subsystem under `audit/` is a deeper diagnostic layer. `audit/tokenizer_audit.py` emits detailed reports, token frequency tables, vocabulary dumps, garbage-token analysis, and language/script-specific breakdowns. The committed CSVs and markdown/JSON outputs are the historical results of running this audit suite on the shipped tokenizer.

8. `reference_outputs/` provides fixed outputs for the key benchmark scripts. These files act as a reproducibility boundary: rerunning the scripts should match the committed JSON exactly, making it easy to validate that the environment and artifact match the published results.

9. The repository also includes a clear separation between “paper claims” and “artifact integrity.” The verification scripts prove the tokenizer obeys structural constraints; the evaluation scripts prove compression/fertility behavior; the audit suite explains vocabulary quality and utilization. Together they cover correctness, performance, and interpretability.

10. The external dependencies matter architecturally because they define the evaluation surface. The repo expects `tokenizers`, `transformers`, `tiktoken`, `datasets`, `pandas`, and `pyarrow`, and it relies on Hugging Face model/tokenizer downloads plus public corpus downloads. In an architecture diagram, those should appear as out-of-repo inputs feeding the benchmark and audit scripts, while `tokenizer.json` remains the single internal artifact being tested and measured.

Main entry points: [`tokenizer.json`](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/tokenizer.json) (Tokenizer), [`evaluate_fertility_flores.py`](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_fertility_flores.py) (FLORES fertility), [`evaluate_fertility_in22.py`](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_fertility_in22.py) (IN22 fertility), [`audit/tokenizer_audit.py`](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/audit/tokenizer_audit.py) (Tokenizer audit)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core artifact"]
  node_tokenizer_json[("Tokenizer<br/>byte-level BPE artifact<br/>[tokenizer.json]")]
end

subgraph group_verify["Verification"]
  node_verify_no_cross_script_merges_py["No cross merges<br/>structural check"]
  node_verify_max_byte_length_py["Byte length<br/>structural check"]
  node_verify_kronecker_constraints_unified_py["Kronecker check<br/>structural check"]
  node_verify_sarvam_m_structural_identity_py["Identity check<br/>structural check"]
end

subgraph group_eval["Evaluation"]
  node_evaluate_fertility_flores_py["FLORES fertility<br/>fertility benchmark"]
  node_evaluate_fertility_in22_py["IN22 fertility<br/>fertility benchmark"]
  node_evaluate_code_math_py["Code/math eval<br/>task benchmark"]
end

subgraph group_corpus["Corpus processing"]
  node_tokenize_full_indic_corpus_py["Indic corpus<br/>corpus tokenizer"]
end

subgraph group_audit["Audit"]
  node_tokenizer_audit_py["Tokenizer audit<br/>diagnostic report<br/>[tokenizer_audit.py]"]
  node_audit_reports["Audit outputs<br/>committed reports"]
end

subgraph group_refs["Reference outputs"]
  node_reference_outputs_dir["Refs<br/>baseline outputs"]
end

subgraph group_external["External inputs"]
  node_hf_datasets[("Datasets<br/>public corpora")]
  node_hf_tokenizers[("Tokenizer refs<br/>model/tokenizer downloads")]
  node_tokenizers_deps["Tokenizer libs<br/>runtime deps"]
  node_license_inputs(("Network license<br/>runtime constraint"))
end

node_tokenizer_json -->|"input"| node_verify_no_cross_script_merges_py
node_tokenizer_json -->|"input"| node_verify_max_byte_length_py
node_tokenizer_json -->|"input"| node_verify_kronecker_constraints_unified_py
node_tokenizer_json -->|"input"| node_verify_sarvam_m_structural_identity_py
node_tokenizer_json -->|"measure"| node_evaluate_fertility_flores_py
node_tokenizer_json -->|"measure"| node_evaluate_fertility_in22_py
node_tokenizer_json -->|"measure"| node_evaluate_code_math_py
node_tokenizer_json -->|"tokenize"| node_tokenize_full_indic_corpus_py
node_tokenizer_json -->|"audit"| node_tokenizer_audit_py
node_evaluate_fertility_flores_py -->|"fetch"| node_hf_datasets
node_evaluate_fertility_flores_py -->|"compare"| node_hf_tokenizers
node_evaluate_fertility_in22_py -->|"fetch"| node_hf_datasets
node_evaluate_fertility_in22_py -->|"compare"| node_hf_tokenizers
node_evaluate_code_math_py -->|"fetch"| node_hf_datasets
node_tokenize_full_indic_corpus_py -->|"fetch"| node_hf_datasets
node_tokenizer_audit_py -->|"fetch"| node_hf_datasets
node_tokenizer_audit_py -->|"writes"| node_audit_reports
node_evaluate_fertility_flores_py -.->|"compare"| node_reference_outputs_dir
node_evaluate_fertility_in22_py -.->|"compare"| node_reference_outputs_dir
node_verify_no_cross_script_merges_py -->|"depends on"| node_tokenizers_deps
node_evaluate_code_math_py -->|"depends on"| node_tokenizers_deps
node_tokenize_full_indic_corpus_py -->|"depends on"| node_tokenizers_deps
node_tokenizer_audit_py -->|"depends on"| node_tokenizers_deps
node_hf_datasets -.->|"gated by"| node_license_inputs
node_hf_tokenizers -.->|"gated by"| node_license_inputs

click node_tokenizer_json "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/tokenizer.json"
click node_verify_no_cross_script_merges_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_no_cross_script_merges.py"
click node_verify_max_byte_length_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_max_byte_length.py"
click node_verify_kronecker_constraints_unified_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_kronecker_constraints_unified.py"
click node_verify_sarvam_m_structural_identity_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_sarvam_m_structural_identity.py"
click node_evaluate_fertility_flores_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_fertility_flores.py"
click node_evaluate_fertility_in22_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_fertility_in22.py"
click node_evaluate_code_math_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_code_math.py"
click node_tokenize_full_indic_corpus_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/tokenize_full_indic_corpus.py"
click node_tokenizer_audit_py "https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/audit/tokenizer_audit.py"
click node_audit_reports "https://github.com/theschoolofai/brahmictokenizer-131k/tree/main/audit/report_hybrid_full"
click node_reference_outputs_dir "https://github.com/theschoolofai/brahmictokenizer-131k/tree/main/reference_outputs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tokenizer_json,node_hf_datasets,node_hf_tokenizers,node_tokenizers_deps,node_license_inputs toneBlue
class node_verify_no_cross_script_merges_py,node_verify_max_byte_length_py,node_verify_kronecker_constraints_unified_py,node_verify_sarvam_m_structural_identity_py toneAmber
class node_evaluate_fertility_flores_py,node_evaluate_fertility_in22_py,node_evaluate_code_math_py toneMint
class node_tokenize_full_indic_corpus_py toneRose
class node_tokenizer_audit_py,node_audit_reports toneIndigo
class node_reference_outputs_dir toneTeal
```

## Components

### Core artifact

Primary tokenizer model artifact and repository boundary.

- [Tokenizer](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/tokenizer.json): byte-level BPE artifact · 131,072-vocabulary tokenizer used as the single source of truth. · `tokenizer.json`

### Verification

Structural checks over the shipped tokenizer artifact.

- [No cross merges](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_no_cross_script_merges.py): structural check · Validates merge constraints across scripts. · `verify_no_cross_script_merges.py`
- [Byte length](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_max_byte_length.py): structural check · Checks maximum byte-length constraints. · `verify_max_byte_length.py`
- [Kronecker check](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_kronecker_constraints_unified.py): structural check · Checks unified structural constraints on tokenizer behavior. · `verify_kronecker_constraints_unified.py`
- [Identity check](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/verify_sarvam_m_structural_identity.py): structural check · Compares structural identity against the reference tokenizer family. · `verify_sarvam_m_structural_identity.py`

### Evaluation

Comparative benchmark scripts for fertility and task efficiency.

- [FLORES fertility](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_fertility_flores.py): fertility benchmark · Measures token fertility on FLORES-200 across tokenizers. · `evaluate_fertility_flores.py`
- [IN22 fertility](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_fertility_in22.py): fertility benchmark · Measures token fertility on IN22-Gen across tokenizers. · `evaluate_fertility_in22.py`
- [Code/math eval](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/evaluate_code_math.py): task benchmark · Compares tokenizer efficiency on code and math corpora/tasks. · `evaluate_code_math.py`

### Corpus processing

Large-scale corpus tokenization and compression measurement.

- [Indic corpus](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/tokenize_full_indic_corpus.py): corpus tokenizer · Tokenizes large Indic corpora and aggregates compression statistics. · `tokenize_full_indic_corpus.py`

### Audit

Detailed vocabulary and token-usage diagnostics.

- [Tokenizer audit](https://github.com/theschoolofai/brahmictokenizer-131k/blob/main/audit/tokenizer_audit.py): diagnostic report · Generates token frequency, garbage-token, and script-specific audit outputs. · `audit/tokenizer_audit.py`
- [Audit outputs](https://github.com/theschoolofai/brahmictokenizer-131k/tree/main/audit/report_hybrid_full): committed reports · Historical CSV, JSON, and markdown outputs from audit runs. · `audit/report_hybrid_full`

### Reference outputs

Committed outputs used as reproducibility baselines.

- [Refs](https://github.com/theschoolofai/brahmictokenizer-131k/tree/main/reference_outputs): baseline outputs · Committed benchmark outputs used to validate reproducibility. · `reference_outputs`

### External inputs

Public datasets, model/tokenizer downloads, and runtime dependencies.

- **Datasets**: public corpora · External benchmark and corpus downloads fetched at runtime.
- **Tokenizer refs**: model/tokenizer downloads · External tokenizer and model artifacts used for comparison.
- **Tokenizer libs**: runtime deps · tokenizers, transformers, tiktoken, datasets, pandas, pyarrow.
- **Network license**: runtime constraint · Reproducibility depends on accepted licenses and network access.

## Connections

- Tokenizer → No cross merges: input · Structural validation reads the shipped tokenizer artifact.
- Tokenizer → Byte length: input · Checks tokenizer byte-length constraints.
- Tokenizer → Kronecker check: input · Checks structural constraints against expected rules.
- Tokenizer → Identity check: input · Compares against reference tokenizer identity.
- Tokenizer → FLORES fertility: measure · Benchmark script measures fertility of the artifact.
- Tokenizer → IN22 fertility: measure · Benchmark script measures fertility of the artifact.
- Tokenizer → Code/math eval: measure · Benchmark script measures compression/efficiency on tasks.
- Tokenizer → Indic corpus: tokenize · Corpus pipeline uses the tokenizer as the main encoder.
- Tokenizer → Tokenizer audit: audit · Audit pipeline analyzes the tokenizer vocabulary and usage.
- FLORES fertility → Datasets: fetch · Loads FLORES-200 data at runtime.
- FLORES fertility → Tokenizer refs: compare · Compares against third-party tokenizers.
- IN22 fertility → Datasets: fetch · Loads IN22-Gen data at runtime.
- IN22 fertility → Tokenizer refs: compare · Compares against third-party tokenizers.
- Code/math eval → Datasets: fetch · Loads code and math benchmarks at runtime.
- Indic corpus → Datasets: fetch · Reads large public Indic corpora.
- Tokenizer audit → Datasets: fetch · Consumes corpus inputs for token analysis.
- Tokenizer audit → Audit outputs: writes · Produces detailed audit artifacts and summaries.
- FLORES fertility → Refs: compare · Expected to match committed benchmark outputs.
- IN22 fertility → Refs: compare · Expected to match committed benchmark outputs.
- No cross merges → Tokenizer libs: depends on · Uses tokenizer runtime libraries.
- Code/math eval → Tokenizer libs: depends on · Uses benchmark and data-processing libraries.
- Indic corpus → Tokenizer libs: depends on · Uses corpus processing libraries.
- Tokenizer audit → Tokenizer libs: depends on · Uses analysis and data processing libraries.
- Datasets → Network license: gated by · External downloads depend on access and accepted licenses.
- Tokenizer refs → Network license: gated by · External downloads depend on access and accepted licenses.
