ML Pipeline & Ensemble Scoring
Relevant source files
The following files were used as context for generating this wiki page:
The ML Pipeline & Ensemble Scoring system is the core analytical engine of TrueLens. It orchestrates a multi-signal analysis process that evaluates content authenticity by combining transformer-based machine learning models with advanced stylometric and heuristic analysis. The pipeline is designed to handle various content types including raw text, URLs, and uploaded documents, providing a unified "Trust Score" and categorical verdict for each scan.
The system operates as an asynchronous workflow, utilizing Celery for task orchestration in the backend, while also maintaining a client-side implementation for rapid prototype analysis. This dual approach ensures comprehensive coverage across text stylometry, domain reputation, image forensics, and document integrity.
Sources: truelens-backend/app/tasks/ml_pipeline.py:1-15, truelens-app/src/lib/analysis.ts:153-157
Pipeline Orchestration
The backend pipeline is centered around the process_scan_task Celery task. This task manages the lifecycle of a scan, from initial database status updates to the execution of specialized analysis services.
Data Flow & Execution Logic
The pipeline branches its logic based on the input type provided in the Scan model. If a URL is provided, the system first performs domain analysis and provenance checks before attempting to scrape the URL content for deep text analysis. For raw text inputs, it directly engages the ensemble text analysis services.
The diagram shows the conditional execution paths within the Celery task based on the scan's content type.
Sources: truelens-backend/app/tasks/ml_pipeline.py:126-200
Ensemble Scoring Engine
The ensemble scoring engine synthesizes individual scores from diverse analytical signals into a single, weighted Trust Score. This score represents the mathematical inverse of the weighted average probability that the content is inauthentic or AI-generated.
Weighted Signal Calculation
Each signal provides a score (0-100, where higher indicates inauthenticity) and a confidence (0-1). The final score is calculated using predefined weights for different signal types.
| Signal Type | Default Weight | Description |
|---|---|---|
text | 0.40 | AI detection and stylometric patterns |
metadata | 0.25 | Domain WHOIS, TLD reputation, and EXIF |
image | 0.20 | GAN detection and error level analysis |
news | 0.20 | Journalistic integrity and fake news detection |
review | 0.10 | Behavioral checks for fake product reviews |
provenance | 0.05 | Fact-checking and historical record matches |
Sources: truelens-backend/app/tasks/ml_pipeline.py:41-50, truelens-app/src/lib/analysis.ts:241-247
Trust Score and Verdict Mapping
The Trust Score is derived by calculating 100 minus the weighted average of the signals. This score is then mapped to a VerdictEnum:
- Authentic: Score ≥ 80
- Suspicious: 40 ≤ Score < 80
- AI-Generated: Score < 40
Sources: truelens-backend/app/tasks/ml_pipeline.py:53-89, truelens-app/src/lib/analysis.ts:291-294
Component Analysis Services
Text Analysis Ensemble
The text analysis service uses a dual-mode approach combining deep learning and linguistic heuristics.
- Transformer Analysis: Utilizes RoBERTa-based models (e.g.,
roberta-base-openai-detector) to classify text as real or AI-generated. - Stylometry Analysis: Evaluates "Burstiness" (paragraph length variation), vocabulary richness, and sentence length variance.
Sources: truelens-backend/app/services/text_analysis.py:27-45, truelens-backend/app/services/text_analysis.py:165-180
News & Review Specializations
Specific heuristics are applied for context-aware analysis:
- News Analysis: Checks for sensationalist language, clickbait patterns, and journalistic source attribution (e.g., "according to", "reported").
- Review Analysis: Identifies excessive capitalization, cliché marketing phrases (e.g., "highly recommend"), and extreme sentiment coupled with low lexical diversity.
Sources: truelens-backend/app/services/news_analysis.py:58-95, truelens-backend/app/services/review_analysis.py:46-82
Document Integrity Pipeline
For files and images, the pipeline performs structural and forensic analysis:
- Tamper Detection: OCR-based arithmetic validation (checking if invoice items sum to the total) and Verhoeff checksum validation for Aadhaar cards.
- Structural Analysis: Font consistency checks where excessive font variety flags potential splicing/forgery.
Sources: truelens-backend/app/services/document_analysis.py:105-145, truelens-backend/app/services/document_analysis.py:340-380
Implementation Details
Scoring Algorithm Snippet
def _calculate_trust_score(signals: List[Dict[str, Any]]) -> int:
weighted_sum = 0.0
weight_total = 0.0
for signal in signals:
sig_type = signal.get("type", "text")
weight = SIGNAL_WEIGHTS.get(sig_type, 0.10)
confidence = signal.get("confidence", 0.5)
effective_weight = weight * confidence
weighted_sum += signal["score"] * effective_weight
weight_total += effective_weight
avg_fake_probability = weighted_sum / weight_total
return int(100 - avg_fake_probability)
Sources: truelens-backend/app/tasks/ml_pipeline.py:53-76
Summary
The ML Pipeline and Ensemble Scoring system provides a robust framework for content verification by integrating diverse analytical signals. By leveraging asynchronous task execution and a sophisticated weighting engine, TrueLens delivers explainable authenticity verdicts supported by transformer-based evidence and structural heuristics.