How shamim-al-mamun/twitter-truth-detector works
Project Type and Purpose
• This is a simple full-stack web application with an ML backend:
• Frontend: HTML/CSS user interface
• Backend: Flask server handling HTTP requests
• Machine Learning: Logistic Regression model for inference
• Offline training component to produce serialized artifacts
File Structure
• Top‐level files:
• app.py: Flask routes for GET (render form) and POST (predict)
• train_model.py: Preprocessing and model training pipeline
• model.pkl & vectorizer.pkl: Serialized model + TF-IDF vectorizer
• README.md, documentation.docx, data_set.docx: project docs
• Directories:
• templates/index.html: user-facing HTML form
• static/style.css: UI styling
Main Components
a. User Interface Layer
• Browser / User Agent
• templates/index.html + static/style.css
b. Web Server Layer
• Flask application (app.py)
• HTTP routes:
• GET / → serves index.html
• POST /predict → accepts tweet text
c. Inference Layer
• model.pkl (Logistic Regression)
• vectorizer.pkl (TF-IDF)
• In-memory data flow: incoming text → vectorizer → model → label
d. Training Pipeline (offline)
• train_model.py
• Raw labeled data (data_set.docx)
• Preprocessing: tokenization, stopword removal, TF-IDF
• Model training → produce model.pkl + vectorizer.pkl
e. (Future) External Services
• Twitter API for real-time tweet fetching (planned)
Relationships and Data Flows
• User → [Browser sends HTTP request] → Flask server
• Flask server → [loads vectorizer.pkl & model.pkl] → runs inference
• Server → [HTTP response with prediction] → Browser
• Training pipeline (separate process) → reads raw data → outputs pickles
• (Optional) External Twitter API → feeds into server or training pipeline
Architectural Patterns and Principles
• Separation of concerns: UI, HTTP routing, ML inference, and offline training are distinct
• Stateless request handling: Flask routes load artifacts at startup or per request
• Modular ML artifacts: model and vectorizer are interchangeable for retraining
• Browser / User Interface
• Flask App Server
• ML Inference (model.pkl + vectorizer.pkl)
• Training Pipeline (train_model.py + data_set.docx)
• (Optional) Twitter API external service