Message Propagation & Semantic Mutation Analyzer
An end-to-end Machine Learning pipeline designed to track, quantify, and visualize how factual information mutates into dangerous misinformation as it propagates through social networks. This system uses HuggingFace Transformers, Graph theory, and XGBoost to calculate a live "Threat Level" for forwarding chains.
Frontend & Visualization
- Streamlit: Interactive web framework.
- Plotly: Live network graph rendering.
- Custom HTML/CSS: WhatsApp-style responsive chat UI with
difflibtext highlighting.
Machine Learning & NLP (Local Inference)
- HuggingFace Transformers:
cross-encoder/nli-distilroberta-base(Zero-shot exaggeration detection). - SentenceTransformers:
all-MiniLM-L6-v2(Semantic drift via cosine similarity). - XGBoost:
XGBClassifier(Probability scoring for misinformation risk). - NetworkX: Graph topology and propagation depth modeling.
- Data Processing: Pandas, NumPy, Scikit-learn.
This system abandons black-box LLM APIs in favor of a robust, deterministic, and locally-hosted architecture split into two distinct pipelines:
- Offline Training Pipeline: Ingests highly nested, non-linear social media threads (e.g., the PHEME dataset). It utilizes Transformer embeddings and Graph metrics to engineer features like Information Mutation Rate and Semantic Drift, training an XGBoost classifier to output a calibrated risk probability.
- Online Inference Engine: A real-time Streamlit dashboard that simulates social media spread. It feeds messages one-by-one into the inference engine, calculating live feature deltas and updating the UI dynamically without recalculating the entire graph.
- Scenario Selection: User selects a pre-loaded dataset (e.g., Sydney Siege) or inputs a custom rumor chain.
- NLP Feature Extraction: The message is passed through DistilRoBERTa and MiniLM to extract semantic embeddings and zero-shot panic/conspiracy probabilities.
- Graph Topology Update: NetworkX updates the directed acyclic graph (DAG) to calculate the message's hop depth and branching factor.
- Threat Scoring: The engineered feature vector
[semantic_drift, exaggeration_score, graph_depth, mutation_rate]is passed to the cached XGBoost model. - UI Rendering: The dashboard updates the Live Threat Meter, plots the new node on the Plotly graph, and highlights the mutated text in red inside the WhatsApp-style chat interface.
misinformation-drift-detector/
│
├── app/
│ └── app.py # Streamlit frontend & simulation loop
│
├── data/
│ ├── raw/ # Optional: Raw dataset JSONs
│ └── models/
│ └── xgb_model.pkl # Trained XGBoost artifact
│
├── demo/ # Screenshots for README
│
├── src/
│ ├── __init__.py
│ ├── data_model.py # Message dataclass definition
│ ├── graph_model.py # NetworkX graph topology engine
│ │
│ ├── data_pipeline/
│ │ └── dataset_parser.py # Parses complex thread trees (PHEME format)
│ │
│ ├── ml/
│ │ ├── feature_engineer.py # Maps text/graph data to tabular Pandas structures
│ │ └── train_model.py # XGBoost training and evaluation script
│ │
│ └── nlp/
│ └── transformer_engine.py # HuggingFace inference pipelines
│
├── requirements.txt
├── .gitignore
└── README.md
1. Clone the repository
git clone [https://github.com/yourusername/misinformation-drift-detector.git](https://github.com/yourusername/misinformation-drift-detector.git)
cd misinformation-drift-detector2. Create and activate a virtual environment
# Windows
python -m venv venv
venv\Scripts\activate
# Mac/Linux
python3 -m venv venv
source venv/bin/activate3. Install dependencies Note: This project uses the CPU-only version of PyTorch for maximum compatibility and lightweight deployment.
pip install torch torchvision torchaudio --index-url [https://download.pytorch.org/whl/cpu](https://download.pytorch.org/whl/cpu)
pip install -r requirements.txt4. Train the ML Model (Offline Pipeline)
Before running the app, you must train the XGBoost classifier to generate the .pkl artifact.
python src/ml/train_model.py5. Launch the Application
streamlit run app/app.py
