# m-swapnil/topic_modelling_with_lsa architecture

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

- Interactive diagram: https://gitdiagram.com/m-swapnil/topic_modelling_with_lsa
- Repository: https://github.com/m-swapnil/topic_modelling_with_lsa

## Overview

##### Component Identification
- Data Repository: The "lsa_data/" directory holds the Reuters SGML files served as the raw text data.
- Data Loader/Parser: A module/function (likely within the main Python script or the notebook) uses BeautifulSoup to load and parse the SGML files, extracting the text from the <body> tags.
- Text Preprocessing Module: Processes and cleans the extracted text. This involves tokenization, normalization, and removal of special characters and numbers. The component uses Gensim’s preprocessing utilities.
- Dictionary & Corpus Builder: Constructs a dictionary from the tokenized documents and creates a bag-of-words (BoW) representation essential for the subsequent LSA step.
- LSA Topic Modeling Engine: Utilizes Gensim’s LSA (or LSI) implementation. This component takes the BoW corpus and generates topics, encapsulating the core topic modeling functionality.
- Coherence Evaluation Module: Computes coherence scores for various topic numbers using Gensim’s CoherenceModel. It also iterates over a range of topics to identify the optimal number based on the scores.
- Visualization Module: Responsible for plotting the coherence scores (and possibly other graphical outputs) to provide insights into the model performance.
- Orchestrator/Main Script: The main pipeline controller (e.g., lsa_topic_modeling.py or the interactive notebook) that sequences these steps.

- Data Flow Sequence:
Data Repository (lsa_data/) → Data Loader (parses SGML files) → Text Preprocessing → Dictionary & Bag-of-Words conversion → LSA Model Building → Coherence Evaluation → Visualization & Output.
- Optionally, indicate feedback loops from the Coherence Evaluation back to the LSA Modeling component if iterative adjustments of the number of topics are made.
- Use connectors between the preprocessing component and both the Dictionary builder and modelling components, showing data dependencies.

##### Architectural Patterns and Design Principles
- Pipeline Architecture: The system is structured as a sequential pipeline where each module feeds its output as input to the next stage.
- Separation of Concerns: Each module (e.g., data loading, preprocessing, modeling, evaluation, visualization) has a distinct responsibility.
- Iterative Evaluation: The coherence evaluation component suggests an iterative design where multiple models (with different topic numbers) are generated and compared.

##### Technologies and Frameworks
- Python 3.7+ as the core programming language.
- Gensim for text preprocessing, dictionary creation, LSA topic modeling, and coherence evaluation.
- BeautifulSoup for parsing Reuters SGML files.
- Matplotlib (or a similar library) for visualizing coherence scores.

## Diagram (Mermaid)

```mermaid
flowchart TD
    O["Orchestrator (Main Script)"]
    DR["Data Repository (lsa_data/)"]

    subgraph "Processing Pipeline"
        DL["Data Loader/Parser (BeautifulSoup)"]
        TP["Text Preprocessing (TokenizationandCleaning)"]
        DC["Dictionary&BoWConversion (Gensim)"]
        LS["LSATopicModelingEngine (GensimLSA/LSI)"]
        CE["CoherenceEvaluation (GensimCoherenceModel)"]
        V["Visualization (CoherencePlotting)"]
    end

    DR --> DL
    O --> DL
    DL --> TP
    TP --> DC
    DC --> LS
    LS --> CE
    CE --> V
    CE -->|"iterative"| LS

    class O orchestrator
    class DR,DL,TP,DC dataProcessing
    class LS modeling
    class CE,V evaluation

    classDef orchestrator fill:#FFD700,stroke:#333,stroke-width:2px
    classDef dataProcessing fill:#ADFF2F,stroke:#333,stroke-width:2px
    classDef modeling fill:#87CEFA,stroke:#333,stroke-width:2px
    classDef evaluation fill:#FFB6C1,stroke:#333,stroke-width:2px

    click DR "https://github.com/m-swapnil/topic_modelling_with_lsa/tree/main/lsa_data/"
    click DL "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
    click TP "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
    click DC "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
    click LS "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
    click CE "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
    click V "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
    click O "https://github.com/m-swapnil/topic_modelling_with_lsa/blob/main/Topic_Modelling(LSA).ipynb"
```
