How pulindu117/nlp_group_04 works
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: 03_features_pulindu_pasanjith.ipynb Feature preparation · app.py Streamlit inference UI · irusha_results.json Experiment results · final_model_comparison.csv Final model comparison
Components 18
Notebook Training
Staged offline data, feature, and model workflow.
- Clean, tokenize, lemmatize
notebooks/01_preprocessing_irusha_madushan.ipynb - Feature preparation · Builds model-family-specific feature representations.
notebooks/03_features_pulindu_pasanjith.ipynb - TF-IDF vectors
- Sequences and embeddings · Padded tokens, Word2Vec, and BERT embeddings.
- Classical model training · Trains Logistic Regression and Random Forest.
notebooks/04_models_pulindu_pasanjith.ipynb - Neural model training · Trains LSTM, CNN, Gaussian Naive Bayes, and BERT candidates.
notebooks/04_models_irusha_madushan.ipynb - Fine-tune BERT
notebooks/05_dl_bert_matheesha_desaman.ipynb - Experiment results · Per-track evaluation outputs.
reports/irusha_results.json - BERT results
reports/matheesha_results.json - Final model comparison · Ranks six models on common test metrics.
reports/final_model_comparison.csv
Persisted Artifacts
Compatibility boundary between training and local inference.
- TF-IDF vectorizer
models/tfidf_vectorizer.pkl - CNN tokenizer
models/cnn_tokenizer.pkl - Train/test labels
models/y_train.npy - Model artifact contract · Model binaries can be regenerated and must remain compatible with inference.
models/README.md
Local Serving
Streamlit prediction runtime.
- Inference preprocessing · Shared preprocessing behavior used by the application.
src/preprocessing.py - Streamlit inference UI · Displays Real/Fake predictions and confidence for the selected ML and DL models.
src/app.py
Other components
- WELFake dataset · Locally downloaded CSV with article text, titles, and binary labels.
- Local data contract · Documents the untracked dataset requirement.
data/README.md
Connections 21
- 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