# isaluki/probabalisticmonkey architecture

> Architecture diagram of the GitHub repository isaluki/probabalisticmonkey, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/isaluki/probabalisticmonkey
- Repository: https://github.com/isaluki/probabalisticmonkey

## Overview

Probabilistic Monkey is a CPU-friendly chat language model, with a larger Gorilla variant supported by the same app. The main user workflow is browser chat: the local server serves the page, accepts conversation turns and a model choice, then streams generated text from the NumPy inference engine using the selected model. A separate documented pipeline gathers and prepares training data, tokenizes it, trains and exports weights; evaluation checks model behavior and benchmark leakage. Some training and server implementation details were not sampled, so those connections are included only where the README or source index supports them.

Main entry points: [`training/tokenize_data.py`](https://github.com/isaluki/probabalisticmonkey/blob/main/training/tokenize_data.py) (Corpus tokenization), [`app/engine.py`](https://github.com/isaluki/probabalisticmonkey/blob/main/app/engine.py) (NumPy inference), [`training/train.py`](https://github.com/isaluki/probabalisticmonkey/blob/main/training/train.py) (Model training), [`eval/check_leakage.py`](https://github.com/isaluki/probabalisticmonkey/blob/main/eval/check_leakage.py) (Leakage check)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat runtime"]
  node_page["Chat page<br/>[index.html]"]
  node_server["Local chat server<br/>[server.py]"]
  node_inference["NumPy inference<br/>[engine.py]"]
end

subgraph group_training["Training pipeline"]
  node_download["Data download<br/>[download_data.py]"]
  node_corpus["Corpus preparation<br/>[prepare_corpus.py]"]
  node_handwritten["Handwritten teaching data<br/>[handwritten.py]"]
  node_synthetic["Synthetic conversations<br/>[synthetic.py]"]
  node_tokenizer["Tokenizer training<br/>[train_tokenizer.py]"]
  node_tokenize["Corpus tokenization<br/>[tokenize_data.py]"]
  node_architecture["Transformer architecture<br/>[model.py]"]
  node_train["Model training<br/>[train.py]"]
  node_export["Quantized export<br/>[export.py]"]
end

subgraph group_model["Model artifacts"]
  node_weights[("Model weights and config<br/>[config.json]")]
end

subgraph group_evaluation["Evaluation"]
  node_benchmark["Model benchmark<br/>[benchmark.py]"]
  node_gorilla_benchmark["Gorilla benchmark"]
  node_leakage["Leakage check<br/>[check_leakage.py]"]
end

node_user(("Chat user"))

node_user -->|"uses"| node_page
node_page -->|"sends chat"| node_server
node_server -->|"generates with"| node_inference
node_inference -->|"loads"| node_weights
node_download -->|"supplies raw data"| node_corpus
node_corpus -->|"prepares text"| node_tokenize
node_handwritten -->|"provides teaching data"| node_tokenize
node_synthetic -->|"provides generated data"| node_tokenize
node_tokenizer -->|"provides tokenizer"| node_tokenize
node_tokenize -->|"provides token files"| node_train
node_architecture -->|"defines training model"| node_train
node_train -->|"produces checkpoint"| node_export
node_export -->|"writes quantized model"| node_weights
node_benchmark -->|"evaluates"| node_inference
node_gorilla_benchmark -->|"evaluates"| node_inference
node_leakage -->|"checks for overlap"| node_handwritten
node_leakage -->|"checks for overlap"| node_synthetic

click node_page "https://github.com/isaluki/probabalisticmonkey/blob/main/app/index.html"
click node_server "https://github.com/isaluki/probabalisticmonkey/blob/main/app/server.py"
click node_inference "https://github.com/isaluki/probabalisticmonkey/blob/main/app/engine.py"
click node_weights "https://github.com/isaluki/probabalisticmonkey/blob/main/model/config.json"
click node_download "https://github.com/isaluki/probabalisticmonkey/blob/main/training/download_data.py"
click node_corpus "https://github.com/isaluki/probabalisticmonkey/blob/main/training/prepare_corpus.py"
click node_handwritten "https://github.com/isaluki/probabalisticmonkey/blob/main/training/handwritten.py"
click node_synthetic "https://github.com/isaluki/probabalisticmonkey/blob/main/training/synthetic.py"
click node_tokenizer "https://github.com/isaluki/probabalisticmonkey/blob/main/training/train_tokenizer.py"
click node_tokenize "https://github.com/isaluki/probabalisticmonkey/blob/main/training/tokenize_data.py"
click node_architecture "https://github.com/isaluki/probabalisticmonkey/blob/main/training/model.py"
click node_train "https://github.com/isaluki/probabalisticmonkey/blob/main/training/train.py"
click node_export "https://github.com/isaluki/probabalisticmonkey/blob/main/training/export.py"
click node_benchmark "https://github.com/isaluki/probabalisticmonkey/blob/main/eval/benchmark.py"
click node_gorilla_benchmark "https://github.com/isaluki/probabalisticmonkey/blob/main/eval/gorilla_benchmark.py"
click node_leakage "https://github.com/isaluki/probabalisticmonkey/blob/main/eval/check_leakage.py"

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_page,node_server,node_inference,node_user toneBlue
class node_download,node_corpus,node_handwritten,node_synthetic,node_tokenizer,node_tokenize,node_architecture,node_train,node_export toneAmber
class node_weights toneMint
class node_benchmark,node_gorilla_benchmark,node_leakage toneRose
```

## Components

### Chat runtime

- [Chat page](https://github.com/isaluki/probabalisticmonkey/blob/main/app/index.html): `app/index.html`
- [Local chat server](https://github.com/isaluki/probabalisticmonkey/blob/main/app/server.py): `app/server.py`
- [NumPy inference](https://github.com/isaluki/probabalisticmonkey/blob/main/app/engine.py): `app/engine.py`

### Training pipeline

- [Data download](https://github.com/isaluki/probabalisticmonkey/blob/main/training/download_data.py): `training/download_data.py`
- [Corpus preparation](https://github.com/isaluki/probabalisticmonkey/blob/main/training/prepare_corpus.py): `training/prepare_corpus.py`
- [Handwritten teaching data](https://github.com/isaluki/probabalisticmonkey/blob/main/training/handwritten.py): `training/handwritten.py`
- [Synthetic conversations](https://github.com/isaluki/probabalisticmonkey/blob/main/training/synthetic.py): `training/synthetic.py`
- [Tokenizer training](https://github.com/isaluki/probabalisticmonkey/blob/main/training/train_tokenizer.py): `training/train_tokenizer.py`
- [Corpus tokenization](https://github.com/isaluki/probabalisticmonkey/blob/main/training/tokenize_data.py): `training/tokenize_data.py`
- [Transformer architecture](https://github.com/isaluki/probabalisticmonkey/blob/main/training/model.py): `training/model.py`
- [Model training](https://github.com/isaluki/probabalisticmonkey/blob/main/training/train.py): `training/train.py`
- [Quantized export](https://github.com/isaluki/probabalisticmonkey/blob/main/training/export.py): `training/export.py`

### Model artifacts

- [Model weights and config](https://github.com/isaluki/probabalisticmonkey/blob/main/model/config.json): `model/config.json`

### Evaluation

- [Model benchmark](https://github.com/isaluki/probabalisticmonkey/blob/main/eval/benchmark.py): `eval/benchmark.py`
- [Gorilla benchmark](https://github.com/isaluki/probabalisticmonkey/blob/main/eval/gorilla_benchmark.py): `eval/gorilla_benchmark.py`
- [Leakage check](https://github.com/isaluki/probabalisticmonkey/blob/main/eval/check_leakage.py): `eval/check_leakage.py`

### Other components

- **Chat user**

## Connections

- Chat user → Chat page: uses (evidence: `README.md`)
- Chat page → Local chat server: sends chat (evidence: `README.md`)
- Local chat server → NumPy inference: generates with (evidence: `app/server.py`)
- NumPy inference → Model weights and config: loads (evidence: `README.md`)
- Data download → Corpus preparation: supplies raw data (evidence: `README.md`)
- Corpus preparation → Corpus tokenization: prepares text (evidence: `README.md`)
- Handwritten teaching data → Corpus tokenization: provides teaching data (evidence: `training/tokenize_data.py`)
- Synthetic conversations → Corpus tokenization: provides generated data (evidence: `training/tokenize_data.py`)
- Tokenizer training → Corpus tokenization: provides tokenizer (evidence: `README.md`)
- Corpus tokenization → Model training: provides token files (evidence: `training/train.py`)
- Transformer architecture → Model training: defines training model (evidence: `training/train.py`)
- Model training → Quantized export: produces checkpoint (evidence: `README.md`)
- Quantized export → Model weights and config: writes quantized model (evidence: `README.md`)
- Model benchmark → NumPy inference: evaluates (evidence: `README.md`)
- Gorilla benchmark → NumPy inference: evaluates (evidence: `eval/gorilla_benchmark.py`)
- Leakage check → Handwritten teaching data: checks for overlap (evidence: `eval/check_leakage.py`)
- Leakage check → Synthetic conversations: checks for overlap (evidence: `eval/check_leakage.py`)
