How m-swapnil/topic_modelling_with_lsa works
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.