# sricharanadontula/next_word_ai architecture

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

- Interactive diagram: https://gitdiagram.com/sricharanadontula/next_word_ai
- Repository: https://github.com/sricharanadontula/next_word_ai

## Overview

This is a Flask-based next-word prediction application backed by a trained LSTM. The main workflow accepts a seed phrase and generation settings, converts the phrase to token IDs, repeatedly predicts and samples a word, then returns the generated text to the web page. The README also describes Shakespeare-baseline and combined-corpus training, evaluation, and generation experiments; the corresponding notebooks are present, but their internals were not sampled. The README’s dataset paths do not match the supplied tree, so the graph uses only paths that exist there.

Main entry points: [`app.py`](https://github.com/sricharanadontula/next_word_ai/blob/main/app.py) (Text generation loop), [`notebooks/02_combined_corpus_model.ipynb`](https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/02_combined_corpus_model.ipynb) (Combined corpus model), [`templates/index.html`](https://github.com/sricharanadontula/next_word_ai/blob/main/templates/index.html) (Input and results page), [`notebooks/01_shakespeare_baseline.ipynb`](https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/01_shakespeare_baseline.ipynb) (Shakespeare baseline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_page["Input and results page<br/>[index.html]"]
  node_route["Flask home route<br/>[app.py]"]
end

subgraph group_runtime["Prediction runtime"]
  node_generator["Text generation loop<br/>[app.py]"]
  node_tokenizer["Tokenizer"]
  node_padding["Sequence padding<br/>[app.py]"]
  node_sampler["Top-k sampler<br/>[app.py]"]
  node_wordmap["Word index mapping<br/>[app.py]"]
end

subgraph group_artifacts["Model artifacts"]
  node_lstm["Small LSTM model"]
  node_baseline_model["Baseline model artifact"]
  node_fixed_model["Fixed model artifact"]
  node_small_tokenizer["Small tokenizer artifact"]
  node_main_tokenizer["Tokenizer artifact<br/>[tokenizer.pkl]"]
end

subgraph group_training["Training experiments"]
  node_baseline["Shakespeare baseline"]
  node_combined["Combined corpus model"]
  node_corpus["Notebook text dataset<br/>[text.txt]"]
end

node_user(("User"))

node_user -->|"enters prompt"| node_page
node_page -->|"submits form"| node_route
node_route -->|"calls generation"| node_generator
node_route -->|"renders results"| node_page
node_generator -->|"encodes prompt"| node_tokenizer
node_generator -->|"pads context"| node_padding
node_generator -->|"predicts probabilities"| node_lstm
node_generator -->|"samples index"| node_sampler
node_sampler -->|"resolves word"| node_wordmap
node_baseline -.->|"trains baseline"| node_baseline_model
node_combined -.->|"trains combined model"| node_combined
node_corpus -.->|"supplies text"| node_combined
node_combined -.->|"saves model"| node_fixed_model
node_combined -.->|"saves tokenizer"| node_main_tokenizer
node_baseline -.->|"compares performance"| node_combined
node_small_tokenizer -->|"loaded by runtime"| node_generator

click node_page "https://github.com/sricharanadontula/next_word_ai/blob/main/templates/index.html"
click node_route "https://github.com/sricharanadontula/next_word_ai/blob/main/app.py"
click node_generator "https://github.com/sricharanadontula/next_word_ai/blob/main/app.py"
click node_tokenizer "https://github.com/sricharanadontula/next_word_ai/blob/main/models/tokenizer_small.pkl"
click node_padding "https://github.com/sricharanadontula/next_word_ai/blob/main/app.py"
click node_lstm "https://github.com/sricharanadontula/next_word_ai/blob/main/models/next_word_model_small.keras"
click node_sampler "https://github.com/sricharanadontula/next_word_ai/blob/main/app.py"
click node_wordmap "https://github.com/sricharanadontula/next_word_ai/blob/main/app.py"
click node_baseline "https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/01_shakespeare_baseline.ipynb"
click node_combined "https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/02_combined_corpus_model.ipynb"
click node_corpus "https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/dataset/text.txt"
click node_baseline_model "https://github.com/sricharanadontula/next_word_ai/blob/main/models/next_word_model.keras"
click node_fixed_model "https://github.com/sricharanadontula/next_word_ai/blob/main/models/next_word_model_fixed.keras"
click node_small_tokenizer "https://github.com/sricharanadontula/next_word_ai/blob/main/models/tokenizer_small.pkl"
click node_main_tokenizer "https://github.com/sricharanadontula/next_word_ai/blob/main/models/tokenizer.pkl"

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_route,node_user toneBlue
class node_generator,node_tokenizer,node_padding,node_sampler,node_wordmap toneAmber
class node_lstm,node_baseline_model,node_fixed_model,node_small_tokenizer,node_main_tokenizer toneMint
class node_baseline,node_combined,node_corpus toneRose
```

## Components

### Web interface

- [Input and results page](https://github.com/sricharanadontula/next_word_ai/blob/main/templates/index.html): `templates/index.html`
- [Flask home route](https://github.com/sricharanadontula/next_word_ai/blob/main/app.py): `app.py`

### Prediction runtime

- [Text generation loop](https://github.com/sricharanadontula/next_word_ai/blob/main/app.py): `app.py`
- [Tokenizer](https://github.com/sricharanadontula/next_word_ai/blob/main/models/tokenizer_small.pkl): `models/tokenizer_small.pkl`
- [Sequence padding](https://github.com/sricharanadontula/next_word_ai/blob/main/app.py): `app.py`
- [Top-k sampler](https://github.com/sricharanadontula/next_word_ai/blob/main/app.py): `app.py`
- [Word index mapping](https://github.com/sricharanadontula/next_word_ai/blob/main/app.py): `app.py`

### Model artifacts

- [Small LSTM model](https://github.com/sricharanadontula/next_word_ai/blob/main/models/next_word_model_small.keras): `models/next_word_model_small.keras`
- [Baseline model artifact](https://github.com/sricharanadontula/next_word_ai/blob/main/models/next_word_model.keras): `models/next_word_model.keras`
- [Fixed model artifact](https://github.com/sricharanadontula/next_word_ai/blob/main/models/next_word_model_fixed.keras): `models/next_word_model_fixed.keras`
- [Small tokenizer artifact](https://github.com/sricharanadontula/next_word_ai/blob/main/models/tokenizer_small.pkl): `models/tokenizer_small.pkl`
- [Tokenizer artifact](https://github.com/sricharanadontula/next_word_ai/blob/main/models/tokenizer.pkl): `models/tokenizer.pkl`

### Training experiments

- [Shakespeare baseline](https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/01_shakespeare_baseline.ipynb): `notebooks/01_shakespeare_baseline.ipynb`
- [Combined corpus model](https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/02_combined_corpus_model.ipynb): `notebooks/02_combined_corpus_model.ipynb`
- [Notebook text dataset](https://github.com/sricharanadontula/next_word_ai/blob/main/notebooks/dataset/text.txt): `notebooks/dataset/text.txt`

### Other components

- **User**

## Connections

- User → Input and results page: enters prompt
- Input and results page → Flask home route: submits form (evidence: `app.py`)
- Flask home route → Text generation loop: calls generation (evidence: `app.py`)
- Flask home route → Input and results page: renders results (evidence: `app.py`)
- Text generation loop → Tokenizer: encodes prompt (evidence: `app.py`)
- Text generation loop → Sequence padding: pads context (evidence: `app.py`)
- Text generation loop → Small LSTM model: predicts probabilities (evidence: `app.py`)
- Text generation loop → Top-k sampler: samples index (evidence: `app.py`)
- Top-k sampler → Word index mapping: resolves word (evidence: `app.py`)
- Shakespeare baseline → Baseline model artifact: trains baseline (evidence: `README.md`)
- Combined corpus model → Combined corpus model: trains combined model (evidence: `README.md`)
- Notebook text dataset → Combined corpus model: supplies text
- Combined corpus model → Fixed model artifact: saves model (evidence: `README.md`)
- Combined corpus model → Tokenizer artifact: saves tokenizer (evidence: `README.md`)
- Shakespeare baseline → Combined corpus model: compares performance (evidence: `README.md`)
- Small tokenizer artifact → Text generation loop: loaded by runtime (evidence: `app.py`)
