# meetvasoya10/rnn-project architecture

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

- Interactive diagram: https://gitdiagram.com/meetvasoya10/rnn-project
- Repository: https://github.com/meetvasoya10/rnn-project

## Overview

##### Project type and purpose
- This is a single‐service Python ML pipeline for character‐level text generation.
- It trains an LSTM model on Shakespeare’s text and then uses the trained model to generate new, Shakespeare-like text.

##### File structure
- Top-level directories
– data/: raw text corpus (shakespeare.txt) and character mapping (chars.json)
– models/: serialized Keras model weights (lstm_model.keras)
– outputs/: generated text samples
– src/: implementation code
- src/
– model.py: defines the Sequential LSTM architecture
– train.py: orchestrates data loading, preprocessing, model training, model saving
– generate.py: loads model + char map, accepts CLI args (seed, length, temperature), produces text, writes to outputs/

##### README for additional insights
- Clear description of the architecture: Embedding → LSTM → Dense(softmax)
- Usage patterns: two modes (train vs. generate)
- External dependencies: Python 3.10+, TensorFlow 2.12+, NumPy

a. Main components
1. Data Ingestion & Preprocessing
– Input: data/shakespeare.txt
– Output: numeric sequences, vocabulary size, char-to-index map (data/chars.json)
2. Model Definition
– src/model.py: Embedding → LSTM → Dense
3. Training Pipeline
– src/train.py
– Reads preprocessed sequences
– Builds and compiles model
– Runs epochs, checkpoints performance
– Saves final model to models/lstm_model.keras
4. Generation Pipeline
– src/generate.py
– Loads models/lstm_model.keras + chars.json
– Accepts CLI args (seed text, length, temperature)
– Feeds into model in inference loop
– Writes generated text to outputs/generated_TIMESTAMP.txt
5. External Libraries & Environment
– Python runtime, TensorFlow, NumPy

b. Relationships & interactions
- Data → Preprocessing → Model Definition → Training → Model Storage
- Model Storage → Generation Script → Output

c. Architectural patterns & principles
- Pipeline pattern: distinct stages (ingest → train → serve)
- Single executable service (no microservices)
- Clear separation of concerns: model spec, training logic, generation logic

d. Key technologies & libraries
- TensorFlow/Keras for neural network
- Python scripts as orchestration layer
- File-based storage for data, model, and outputs

##### Essential details without over-splitting
- Don’t fragment the model into every layer; group layers under “LSTM Model”
- Don’t merge training and generation; keep them as two explicit pipelines
- Simple linear architecture, but call out the two modes (train vs. generate)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Layer"
        RawData["Raw Data Storage"]:::cyl
        Preprocess["Preprocessor"]:::script
    end

    subgraph "Training Layer"
        ModelDef["LSTM Model Definition"]:::script
        Train["Training Pipeline"]:::script
        ModelStore["Trained Model Storage"]:::cyl
    end

    subgraph "Serving Layer"
        Generate["Generation Pipeline"]:::script
        Output["Generated Text Outputs"]:::cyl
    end

    subgraph "External Dependencies"
        Python["Python 3.10+"]:::dep
        TF["TensorFlow 2.12+"]:::dep
        NumPy["NumPy"]:::dep
    end

    RawData -->|"reads shakespeare.txt & chars.json"| Preprocess
    Preprocess -->|"outputs sequences & char map"| ModelDef
    ModelDef -->|"model object"| Train
    Train -->|"saves lstm_model.keras"| ModelStore
    ModelStore -->|"loaded by"| Generate
    RawData -->|"loads char map"| Generate
    Generate -->|"writes generated text"| Output

    Python --> Preprocess
    Python --> ModelDef
    Python --> Train
    Python --> Generate

    TF --> ModelDef
    TF --> Train
    TF --> Generate

    NumPy --> Preprocess
    NumPy --> Train

    click RawData "https://github.com/meetvasoya10/rnn-project/tree/main/data/"
    click ModelDef "https://github.com/meetvasoya10/rnn-project/blob/main/src/model.py"
    click Train "https://github.com/meetvasoya10/rnn-project/blob/main/src/train.py"
    click ModelStore "https://github.com/meetvasoya10/rnn-project/tree/main/models/"
    click Generate "https://github.com/meetvasoya10/rnn-project/blob/main/src/generate.py"
    click Output "https://github.com/meetvasoya10/rnn-project/tree/main/outputs/"

    classDef script fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef cyl fill:#A2D39C,stroke:#333,stroke-width:1px
    classDef dep fill:#F4A460,stroke:#333,stroke-width:1px
```
