# pulindu117/nlp_group_04 architecture

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

- Interactive diagram: https://gitdiagram.com/pulindu117/nlp_group_04
- Repository: https://github.com/pulindu117/nlp_group_04

## Overview

#### Purpose and Entry Points
This repository is an NLP fake-news classification project trained on the WELFake dataset. It provides a notebook-driven training/evaluation workflow and a Streamlit inference UI. Primary entry points are the staged notebooks under `notebooks/` and `streamlit run src/app.py` for serving predictions.

#### Data Boundary
Raw input is the externally downloaded `WELFake_Dataset.csv`, expected beneath `data/` but intentionally absent from version control. The source dataset contains article title/text and binary labels (`0` fake, `1` real). `data/README.md` documents this local-data contract; downstream artifacts are persisted under `models/` and `reports/`.

#### Preprocessing and Feature Pipeline
The workflow begins with member-specific preprocessing notebooks for cleaning, tokenization, and lemmatization, then EDA and feature preparation. Feature paths split by model family: classical models consume TF-IDF vectors, while neural models use padded token sequences, Word2Vec embeddings, or BERT embeddings. Relevant stages are represented in:
- `notebooks/01_preprocessing_irusha_madushan.ipynb`
- `notebooks/03_features_pulindu_pasanjith.ipynb`
- `src/preprocessing.py`

#### Model Training Tracks
Three parallel notebook tracks train six classifiers on a common 80/20 train/test split: Logistic Regression and LSTM; Random Forest and CNN; Gaussian Naive Bayes and fine-tuned BERT. The selected deployment pair is Logistic Regression (best ML) and Word2Vec CNN (best DL). Training/model artifacts include:
- `notebooks/04_models_pulindu_pasanjith.ipynb`
- `notebooks/04_models_irusha_madushan.ipynb`
- `notebooks/05_dl_bert_matheesha_desaman.ipynb`

#### Artifact Contract
Persisted preprocessing/model dependencies form the boundary between notebook training and interactive inference. The committed artifacts include a TF-IDF vectorizer, CNN tokenizer, and train/test label arrays:
- `models/tfidf_vectorizer.pkl`
- `models/cnn_tokenizer.pkl`
- `models/y_train.npy`
Model binaries may be regenerated by the notebooks and are described by `models/README.md`; the application depends on compatible artifact versions and preprocessing behavior.

#### Evaluation and Selection
Individual experiment outputs are consolidated into structured JSON reports and a final cross-model comparison. This comparison ranks the six candidates by common test-set metrics and drives the two-model application choice:
- `reports/irusha_results.json`
- `reports/matheesha_results.json`
- `reports/final_model_comparison.csv`

#### Serving Runtime
`src/app.py` is a Streamlit UI: it accepts article text, applies inference preprocessing/vectorization/tokenization, invokes the chosen ML and DL models, and displays each Real/Fake prediction with confidence. It is a local Python application rather than a networked backend; the only stated external service is Kaggle, used manually to obtain training data.

Main entry points: [`notebooks/03_features_pulindu_pasanjith.ipynb`](https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/03_features_pulindu_pasanjith.ipynb) (Feature preparation), [`src/app.py`](https://github.com/pulindu117/nlp_group_04/blob/main/src/app.py) (Streamlit inference UI), [`reports/irusha_results.json`](https://github.com/pulindu117/nlp_group_04/blob/main/reports/irusha_results.json) (Experiment results), [`reports/final_model_comparison.csv`](https://github.com/pulindu117/nlp_group_04/blob/main/reports/final_model_comparison.csv) (Final model comparison)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Notebook Training"]
  node_preprocessing["Clean, tokenize, lemmatize<br/>notebook stage"]
  node_feature_prep["Feature preparation<br/>notebook stage"]
  node_tfidf_features["TF-IDF vectors<br/>classical features"]
  node_neural_features["Sequences and embeddings<br/>neural features"]
  node_ml_training["Classical model training<br/>notebook track"]
  node_dl_training["Neural model training<br/>notebook track"]
  node_bert_training["Fine-tune BERT<br/>notebook track"]
  node_experiment_reports["Experiment results<br/>JSON reports"]
  node_bert_report["BERT results<br/>JSON report"]
  node_comparison["Final model comparison<br/>evaluation report"]
end

subgraph group_artifacts["Persisted Artifacts"]
  node_tfidf_vectorizer["TF-IDF vectorizer<br/>serialized artifact"]
  node_cnn_tokenizer["CNN tokenizer<br/>serialized artifact<br/>[cnn_tokenizer.pkl]"]
  node_labels["Train/test labels<br/>NumPy artifact<br/>[y_train.npy]"]
  node_model_contract["Model artifact contract<br/>documentation<br/>[README.md]"]
end

subgraph group_serving["Local Serving"]
  node_preprocessing_module["Inference preprocessing<br/>Python module<br/>[preprocessing.py]"]
  node_streamlit_app["Streamlit inference UI<br/>local Python app<br/>[app.py]"]
end

node_raw_data[("WELFake dataset<br/>external dataset")]
node_data_contract["Local data contract<br/>documentation<br/>[README.md]"]

node_data_contract -.->|"documents"| node_raw_data
node_raw_data -->|"article data"| node_preprocessing
node_preprocessing -->|"normalized text"| node_feature_prep
node_feature_prep -->|"builds"| node_tfidf_features
node_feature_prep -->|"builds"| node_neural_features
node_tfidf_features -->|"80/20 split"| node_ml_training
node_neural_features -->|"80/20 split"| node_dl_training
node_neural_features -->|"BERT inputs"| node_bert_training
node_feature_prep -->|"persists"| node_tfidf_vectorizer
node_feature_prep -->|"persists"| node_cnn_tokenizer
node_feature_prep -->|"persists"| node_labels
node_ml_training -->|"evaluates"| node_experiment_reports
node_dl_training -->|"evaluates"| node_experiment_reports
node_bert_training -->|"evaluates"| node_bert_report
node_experiment_reports -->|"consolidates"| node_comparison
node_bert_report -->|"consolidates"| node_comparison
node_comparison -->|"selects Logistic Regression and CNN"| node_streamlit_app
node_model_contract -.->|"defines compatible binaries"| node_streamlit_app
node_tfidf_vectorizer -->|"vectorizes ML input"| node_streamlit_app
node_cnn_tokenizer -->|"tokenizes CNN input"| node_streamlit_app
node_preprocessing_module -->|"preprocesses text"| node_streamlit_app

click node_data_contract "https://github.com/pulindu117/nlp_group_04/blob/main/data/README.md"
click node_preprocessing "https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/01_preprocessing_irusha_madushan.ipynb"
click node_preprocessing_module "https://github.com/pulindu117/nlp_group_04/blob/main/src/preprocessing.py"
click node_feature_prep "https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/03_features_pulindu_pasanjith.ipynb"
click node_ml_training "https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/04_models_pulindu_pasanjith.ipynb"
click node_dl_training "https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/04_models_irusha_madushan.ipynb"
click node_bert_training "https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/05_dl_bert_matheesha_desaman.ipynb"
click node_experiment_reports "https://github.com/pulindu117/nlp_group_04/blob/main/reports/irusha_results.json"
click node_bert_report "https://github.com/pulindu117/nlp_group_04/blob/main/reports/matheesha_results.json"
click node_comparison "https://github.com/pulindu117/nlp_group_04/blob/main/reports/final_model_comparison.csv"
click node_tfidf_vectorizer "https://github.com/pulindu117/nlp_group_04/blob/main/models/tfidf_vectorizer.pkl"
click node_cnn_tokenizer "https://github.com/pulindu117/nlp_group_04/blob/main/models/cnn_tokenizer.pkl"
click node_labels "https://github.com/pulindu117/nlp_group_04/blob/main/models/y_train.npy"
click node_model_contract "https://github.com/pulindu117/nlp_group_04/blob/main/models/README.md"
click node_streamlit_app "https://github.com/pulindu117/nlp_group_04/blob/main/src/app.py"

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_preprocessing,node_feature_prep,node_tfidf_features,node_neural_features,node_ml_training,node_dl_training,node_bert_training,node_experiment_reports,node_bert_report,node_comparison toneBlue
class node_tfidf_vectorizer,node_cnn_tokenizer,node_labels,node_model_contract toneAmber
class node_preprocessing_module,node_streamlit_app toneMint
class node_raw_data,node_data_contract toneNeutral
```

## Components

### Notebook Training

Staged offline data, feature, and model workflow.

- [Clean, tokenize, lemmatize](https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/01_preprocessing_irusha_madushan.ipynb): notebook stage · `notebooks/01_preprocessing_irusha_madushan.ipynb`
- [Feature preparation](https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/03_features_pulindu_pasanjith.ipynb): notebook stage · Builds model-family-specific feature representations. · `notebooks/03_features_pulindu_pasanjith.ipynb`
- **TF-IDF vectors**: classical features
- **Sequences and embeddings**: neural features · Padded tokens, Word2Vec, and BERT embeddings.
- [Classical model training](https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/04_models_pulindu_pasanjith.ipynb): notebook track · Trains Logistic Regression and Random Forest. · `notebooks/04_models_pulindu_pasanjith.ipynb`
- [Neural model training](https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/04_models_irusha_madushan.ipynb): notebook track · Trains LSTM, CNN, Gaussian Naive Bayes, and BERT candidates. · `notebooks/04_models_irusha_madushan.ipynb`
- [Fine-tune BERT](https://github.com/pulindu117/nlp_group_04/blob/main/notebooks/05_dl_bert_matheesha_desaman.ipynb): notebook track · `notebooks/05_dl_bert_matheesha_desaman.ipynb`
- [Experiment results](https://github.com/pulindu117/nlp_group_04/blob/main/reports/irusha_results.json): JSON reports · Per-track evaluation outputs. · `reports/irusha_results.json`
- [BERT results](https://github.com/pulindu117/nlp_group_04/blob/main/reports/matheesha_results.json): JSON report · `reports/matheesha_results.json`
- [Final model comparison](https://github.com/pulindu117/nlp_group_04/blob/main/reports/final_model_comparison.csv): evaluation report · Ranks six models on common test metrics. · `reports/final_model_comparison.csv`

### Persisted Artifacts

Compatibility boundary between training and local inference.

- [TF-IDF vectorizer](https://github.com/pulindu117/nlp_group_04/blob/main/models/tfidf_vectorizer.pkl): serialized artifact · `models/tfidf_vectorizer.pkl`
- [CNN tokenizer](https://github.com/pulindu117/nlp_group_04/blob/main/models/cnn_tokenizer.pkl): serialized artifact · `models/cnn_tokenizer.pkl`
- [Train/test labels](https://github.com/pulindu117/nlp_group_04/blob/main/models/y_train.npy): NumPy artifact · `models/y_train.npy`
- [Model artifact contract](https://github.com/pulindu117/nlp_group_04/blob/main/models/README.md): documentation · Model binaries can be regenerated and must remain compatible with inference. · `models/README.md`

### Local Serving

Streamlit prediction runtime.

- [Inference preprocessing](https://github.com/pulindu117/nlp_group_04/blob/main/src/preprocessing.py): Python module · Shared preprocessing behavior used by the application. · `src/preprocessing.py`
- [Streamlit inference UI](https://github.com/pulindu117/nlp_group_04/blob/main/src/app.py): local Python app · Displays Real/Fake predictions and confidence for the selected ML and DL models. · `src/app.py`

### Other components

- **WELFake dataset**: external dataset · Locally downloaded CSV with article text, titles, and binary labels.
- [Local data contract](https://github.com/pulindu117/nlp_group_04/blob/main/data/README.md): documentation · Documents the untracked dataset requirement. · `data/README.md`

## Connections

- Local data contract → WELFake dataset: documents
- WELFake dataset → Clean, tokenize, lemmatize: article data
- Clean, tokenize, lemmatize → Feature preparation: normalized text
- Feature preparation → TF-IDF vectors: builds
- Feature preparation → Sequences and embeddings: builds
- TF-IDF vectors → Classical model training: 80/20 split
- Sequences and embeddings → Neural model training: 80/20 split
- Sequences and embeddings → Fine-tune BERT: BERT inputs
- Feature preparation → TF-IDF vectorizer: persists
- Feature preparation → CNN tokenizer: persists
- Feature preparation → Train/test labels: persists
- Classical model training → Experiment results: evaluates
- Neural model training → Experiment results: evaluates
- Fine-tune BERT → BERT results: evaluates
- Experiment results → Final model comparison: consolidates
- BERT results → Final model comparison: consolidates
- Final model comparison → Streamlit inference UI: selects Logistic Regression and CNN
- Model artifact contract → Streamlit inference UI: defines compatible binaries
- TF-IDF vectorizer → Streamlit inference UI: vectorizes ML input
- CNN tokenizer → Streamlit inference UI: tokenizes CNN input
- Inference preprocessing → Streamlit inference UI: preprocesses text
