# klaudia-nazarko/nlg-text-generation architecture

> Architecture diagram of the GitHub repository klaudia-nazarko/nlg-text-generation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/klaudia-nazarko/nlg-text-generation
- Repository: https://github.com/klaudia-nazarko/nlg-text-generation

## Overview

##### Main Components and Their Roles
- Data Ingestion & Preprocessing:
- Web Scraper: Represented by the web_scraper.ipynb notebook, which gathers and possibly cleans the raw fairy tale data.
- Data Utilities: Files like Text.py and functions.py likely contain helper functions for text cleaning, tokenization, and preparation.
- Data Splitting: The train_test_split.ipynb notebook suggests a step dedicated to splitting the corpus into training and testing sets.

- Model Implementations:
- Markov Chain Model: Developed in Chain_class.py and demonstrated in markov_chain.ipynb. This model uses a stochastic, memory-less approach based solely on previous words.
- LSTM Neural Network: Implemented in LSTM_class.py and showcased in lstm.ipynb. This component handles sequences with memory to predict the next word.
- GPT-2 Transformer: Shown in gpt_2.ipynb. This notebook introduces transformers with self-attention mechanisms for advanced text generation.

- Result Generation & Evaluation:
- Each model (Markov Chain, LSTM, GPT-2) is tied to its specific notebook where the generation and evaluation (and possibly fine-tuning or training) happens.

##### Relationships and Interactions
- A preprocessing layer (Text.py and functions.py) will transform and prepare the raw data.
- The processed data flows into three parallel model pipelines – each pipeline representing one method (Markov Chain, LSTM, or GPT-2).
- Optional: A train/test splitting component feeding into those pipelines since model training and evaluation are key phases.
- Finally, the output (generated text) can be shown as a common endpoint where the user can view and compare results from the different approaches.

##### Architectural Patterns/Design Elements
- Modular Approach: Even though the project file tree is flat (without subdirectories), the separation of concerns is clear. Each file and notebook plays a specific role (data extraction, model implementation, utility functions).
- Pipeline Structure: The architecture follows a sequential pipeline pattern: Data Extraction → Preprocessing → Model Training/Inference → Output.
- Experimentation Notebooks: Using Jupyter notebooks for different model implementations illustrates an experimental and research-focused design rather than a production API style system.

##### Technologies, Frameworks, and Libraries
- Although not explicitly listed in the tree, the notebooks imply dependencies on deep learning frameworks (likely TensorFlow or PyTorch for LSTM and GPT-2) and standard Python libraries for NLP.
- Markov Chain logic is implemented directly in Python without heavy external libraries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Collection"
        W["Web Scraper"]:::ingestion
    end

    subgraph "Data Preprocessing"
        T["Text.py"]:::preprocessing
        F["functions.py"]:::preprocessing
        S["Train/Test Split"]:::preprocessing
    end

    subgraph "Model Implementations"
        subgraph "Markov Chain Pipeline"
            MC_Model["Markov Chain Model"]:::model
            MC_Impl["Chain_class.py"]:::model
            MC_Demo["Markov Demonstration"]:::model
        end
        subgraph "LSTM Pipeline"
            LSTM_Model["LSTM Neural Network"]:::model
            LSTM_Impl["LSTM_class.py"]:::model
            LSTM_Demo["LSTM Demonstration"]:::model
        end
        subgraph "GPT-2 Pipeline"
            GPT2_Model["Transformer/GPT-2 Model"]:::model
            GPT2_Demo["GPT-2 Demonstration"]:::model
        end
    end

    subgraph "Output Generation & Evaluation"
        E["Result Generation & Evaluation"]:::evaluation
    end

    %% Data flow from Data Collection to Preprocessing
    W --> T
    W --> F
    W --> S

    %% Data flow from Preprocessing to each Model Pipeline
    T --> MC_Model
    F --> MC_Model
    S --> MC_Model

    T --> LSTM_Model
    F --> LSTM_Model
    S --> LSTM_Model

    T --> GPT2_Model
    F --> GPT2_Model
    S --> GPT2_Model

    %% Internal flow within Model Pipelines to Evaluation Component
    MC_Model --> MC_Impl
    MC_Impl --> MC_Demo
    MC_Demo --> E

    LSTM_Model --> LSTM_Impl
    LSTM_Impl --> LSTM_Demo
    LSTM_Demo --> E

    GPT2_Model --> GPT2_Demo
    GPT2_Demo --> E

    %% Click Events
    click W "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/web_scraper.ipynb"
    click T "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/Text.py"
    click F "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/functions.py"
    click S "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/train_test_split.ipynb"
    click MC_Impl "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/Chain_class.py"
    click MC_Demo "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/markov_chain.ipynb"
    click LSTM_Impl "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/LSTM_class.py"
    click LSTM_Demo "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/lstm.ipynb"
    click GPT2_Demo "https://github.com/klaudia-nazarko/nlg-text-generation/blob/main/gpt_2.ipynb"

    %% Styles
    classDef ingestion fill:#fde2e2,stroke:#e85d04,stroke-width:2px;
    classDef preprocessing fill:#fce38a,stroke:#f38181,stroke-width:2px;
    classDef model fill:#95e1d3,stroke:#3d348b,stroke-width:2px;
    classDef evaluation fill:#c1fba4,stroke:#1e5631,stroke-width:2px;
```
