D Ф m i И i q ц e L Ф y e r commited on
Commit ·
8e97fc5
1
Parent(s): 6059862
Deploy SysCRED v2.3.1 - GraphRAG + LIAR benchmark + TREC integration
Browse filesFiles changed (17)
- syscred/.env.exampleAdded+22
- syscred/__init__.py+12-2
- syscred/backend_app.py+258-5
- syscred/config.py+8-6
- syscred/datasets/liar/READMEAdded+41
- syscred/datasets/liar/test.tsvAdded
- syscred/datasets/liar/train.tsvAdded
- syscred/datasets/liar/valid.tsvAdded
- syscred/eval_metrics.py+9
- syscred/graph_rag.py+130-5
- syscred/liar_benchmark_test.csvAdded+101
- syscred/liar_benchmark_test.jsonAdded+105
- syscred/liar_dataset.pyAdded+359
- syscred/run_liar_benchmark.pyAdded+434
- syscred/run_liar_benchmark_remote.pyAdded+373
- syscred/static/index.html+101-2
- syscred/verification_system.py+71-21
12345678910111213141516171819202122# SysCRED Environment Configuration# ==================================# Copy this file to .env and fill in your values
# Supabase Database (PostgreSQL)# Get this from: Supabase Dashboard > Settings > Database > Connection stringDATABASE_URL=postgresql://postgres:YOUR_PASSWORD@db.YOUR_PROJECT.supabase.co:5432/postgres
# Google Fact Check API Key# Get this from: https://console.cloud.google.com/apis/credentialsGOOGLE_FACT_CHECK_API_KEY=your_google_api_key_here
# HuggingFace Space URL (for remote processing)HF_SPACE_URL=https://domloyer-syscred.hf.space
# Flask ConfigurationFLASK_DEBUG=falseFLASK_HOST=0.0.0.0FLASK_PORT=5001
# ML Model Loading (set to false for lightweight mode)LOAD_ML_MODELS=false10 unmodified lines11121314151617181920212223244 unmodified lines29303132333435363738396 unmodified lines4647484950515253545510 unmodified lines- ir_engine: BM25, QLD, TF-IDF, PRF (from TREC)- trec_retriever: Evidence retrieval for fact-checking (NEW v2.3)- trec_dataset: TREC AP88-90 data loader (NEW v2.3)- seo_analyzer: SEO analysis, PageRank estimation- eval_metrics: MAP, NDCG, P@K, Recall, MRR- ontology_manager: RDFLib integration- verification_system: Main credibility pipeline- graph_rag: GraphRAG for contextual memory"""__version__ = "2.3.0"__author__ = "Dominique S. Loyer"__citation__ = "loyerModelingHybridSystem2025"4 unmodified linesfrom syscred.seo_analyzer import SEOAnalyzerfrom syscred.ir_engine import IREnginefrom syscred.eval_metrics import EvaluationMetrics# TREC Integration (NEW - Feb 2026)from syscred.trec_retriever import TRECRetriever, Evidence, RetrievalResultfrom syscred.trec_dataset import TRECDataset, TRECTopic# Convenience aliasSysCRED = CredibilityVerificationSystem6 unmodified lines'SEOAnalyzer','IREngine','EvaluationMetrics',# TREC (NEW)'TRECRetriever','TRECDataset','TRECTopic','Evidence','RetrievalResult',]10 unmodified lines1112131415161718192021222324254 unmodified lines3031323334353637383940414243446 unmodified lines51525354555657585960616263646510 unmodified lines- ir_engine: BM25, QLD, TF-IDF, PRF (from TREC)- trec_retriever: Evidence retrieval for fact-checking (NEW v2.3)- trec_dataset: TREC AP88-90 data loader (NEW v2.3)- liar_dataset: LIAR benchmark dataset loader (NEW v2.3)- seo_analyzer: SEO analysis, PageRank estimation- eval_metrics: MAP, NDCG, P@K, Recall, MRR- ontology_manager: RDFLib integration- verification_system: Main credibility pipeline- graph_rag: GraphRAG for contextual memory (enhanced v2.3)"""__version__ = "2.3.1"__author__ = "Dominique S. Loyer"__citation__ = "loyerModelingHybridSystem2025"4 unmodified linesfrom syscred.seo_analyzer import SEOAnalyzerfrom syscred.ir_engine import IREnginefrom syscred.eval_metrics import EvaluationMetricsfrom syscred.graph_rag import GraphRAG# TREC Integration (NEW - Feb 2026)from syscred.trec_retriever import TRECRetriever, Evidence, RetrievalResultfrom syscred.trec_dataset import TRECDataset, TRECTopic# LIAR Benchmark (NEW - Feb 2026)from syscred.liar_dataset import LIARDataset, LiarStatement, LiarLabel# Convenience aliasSysCRED = CredibilityVerificationSystem6 unmodified lines'SEOAnalyzer','IREngine','EvaluationMetrics','GraphRAG',# TREC (NEW)'TRECRetriever','TRECDataset','TRECTopic','Evidence','RetrievalResult',# LIAR Benchmark (NEW)'LIARDataset','LiarStatement','LiarLabel',]
16 unmodified lines1718192021228 unmodified lines3132333435363738394022 unmodified lines636465666768270 unmodified lines3393403413423433449 unmodified lines35435535635735835936036136236316 unmodified linesimport sysimport osimport tracebackfrom flask import Flask, request, jsonify, send_from_directoryfrom flask_cors import CORS8 unmodified linesfrom syscred.ontology_manager import OntologyManagerfrom syscred.config import config, Configfrom syscred.database import init_db, db, AnalysisResultSYSCRED_AVAILABLE = Trueprint("[SysCRED Backend] Modules imported successfully")except ImportError as e:SYSCRED_AVAILABLE = Falseprint(f"[SysCRED Backend] Warning: Could not import modules: {e}")# Define dummy init_db to prevent crashdef init_db(app): pass22 unmodified lines# --- Initialize SysCRED System ---credibility_system = Noneseo_analyzer = Nonedef initialize_system():"""Initialize the credibility system (lazy loading)."""270 unmodified lines}), 200# --- Main ---if __name__ == '__main__':print("=" * 60)9 unmodified linesprint()print("[SysCRED Backend] Starting Flask server...")print("[SysCRED Backend] Endpoints:")print(" - POST /api/verify - Full credibility verification")print(" - POST /api/seo - SEO analysis only (faster)")print(" - GET /api/ontology/stats - Ontology statistics")print(" - GET /api/health - Health check")print()app.run(host='0.0.0.0', port=5001, debug=True)16 unmodified lines17181920212223242526272829303132333435368 unmodified lines45464748495051525354555657585922 unmodified lines828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121270 unmodified lines3923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915929 unmodified lines60260360460560660760860961061161261361461561616 unmodified linesimport sysimport osimport traceback# Load environment variables from .env filefrom pathlib import Pathtry:from dotenv import load_dotenvenv_path = Path(__file__).parent / '.env'if env_path.exists():load_dotenv(env_path)print(f"[SysCRED Backend] Loaded .env from {env_path}")else:print(f"[SysCRED Backend] No .env file found at {env_path}")except ImportError:print("[SysCRED Backend] python-dotenv not installed, using system env vars")from flask import Flask, request, jsonify, send_from_directoryfrom flask_cors import CORS8 unmodified linesfrom syscred.ontology_manager import OntologyManagerfrom syscred.config import config, Configfrom syscred.database import init_db, db, AnalysisResult# TREC modulesfrom syscred.trec_retriever import TRECRetriever, Evidence, RetrievalResultfrom syscred.eval_metrics import EvaluationMetricsSYSCRED_AVAILABLE = TrueTREC_AVAILABLE = Trueprint("[SysCRED Backend] Modules imported successfully (including TREC)")except ImportError as e:SYSCRED_AVAILABLE = FalseTREC_AVAILABLE = Falseprint(f"[SysCRED Backend] Warning: Could not import modules: {e}")# Define dummy init_db to prevent crashdef init_db(app): pass22 unmodified lines# --- Initialize SysCRED System ---credibility_system = Noneseo_analyzer = Nonetrec_retriever = Noneeval_metrics = None# Demo corpus for TREC (AP88-90 style documents)TREC_DEMO_CORPUS = {"AP880101-0001": {"text": "Climate change is primarily caused by human activities, particularly the burning of fossil fuels which release greenhouse gases into the atmosphere.","title": "Climate Science Report"},"AP880101-0002": {"text": "The Earth's temperature has risen significantly over the past century due to greenhouse gas emissions from industrial activities and deforestation.","title": "Global Warming Study"},"AP880102-0001": {"text": "Scientists warn that sea levels could rise dramatically if current warming trends continue, threatening coastal cities worldwide.","title": "Sea Level Warning"},"AP890215-0001": {"text": "The presidential election campaign focused on economic policies, healthcare reform, and national security issues.","title": "Election Coverage"},"AP890216-0001": {"text": "Stock markets rose sharply after positive economic indicators were released by the Federal Reserve, signaling economic recovery.","title": "Financial News"},"AP880201-0001": {"text": "Renewable energy sources like solar and wind power are becoming more cost-effective alternatives to fossil fuels.","title": "Green Energy Report"},"AP890301-0001": {"text": "The technology industry continues to grow rapidly, with artificial intelligence and machine learning driving innovation.","title": "Tech Industry Update"},}def initialize_system():"""Initialize the credibility system (lazy loading)."""270 unmodified lines}), 200# --- TREC Endpoints ---@app.route('/api/trec/search', methods=['POST'])def trec_search():"""Search for evidence using TREC retrieval methods.Request JSON:{"query": "Claim or query to search for","k": 10, # Number of results (optional, default 10)"model": "bm25" # Retrieval model: bm25, tfidf, qld (optional)}Response:{"query": "original query","results": [{"doc_id": "AP880101-0001", "score": 6.27, "rank": 1, "text": "...", "title": "..."},...],"total": 3,"model": "bm25","search_time_ms": 12.5}"""global trec_retriever, eval_metrics# Initialize TREC components if neededif trec_retriever is None:try:trec_retriever = TRECRetriever(use_stemming=True, enable_prf=False)trec_retriever.corpus = TREC_DEMO_CORPUSeval_metrics = EvaluationMetrics()print("[SysCRED Backend] TREC Retriever initialized with demo corpus")except Exception as e:return jsonify({'error': f'TREC initialization failed: {str(e)}'}), 503if not request.is_json:return jsonify({'error': 'Request must be JSON'}), 400data = request.get_json()query = data.get('query', '').strip()if not query:return jsonify({'error': "'query' is required"}), 400k = data.get('k', 10)model = data.get('model', 'bm25')try:import timestart_time = time.time()# Retrieve evidenceresult = trec_retriever.retrieve_evidence(query, k=k, model=model)search_time_ms = (time.time() - start_time) * 1000# Format resultsresults = []for ev in result.evidences:doc_info = trec_retriever.corpus.get(ev.doc_id, {})results.append({'doc_id': ev.doc_id,'score': round(ev.score, 4),'rank': ev.rank,'text': ev.text,'title': doc_info.get('title', ''),'model': ev.retrieval_model})return jsonify({'query': query,'results': results,'total': len(results),'model': model,'search_time_ms': round(search_time_ms, 2)}), 200except Exception as e:print(f"[SysCRED Backend] TREC search error: {e}")traceback.print_exc()return jsonify({'error': str(e)}), 500@app.route('/api/trec/corpus', methods=['GET'])def trec_corpus():"""Get the TREC demo corpus information.Response:{"corpus_size": 7,"corpus_type": "AP88-90 Demo","documents": [{"doc_id": "AP880101-0001", "title": "...", "text_preview": "..."},...]}"""docs = []for doc_id, doc in TREC_DEMO_CORPUS.items():docs.append({'doc_id': doc_id,'title': doc.get('title', ''),'text_preview': doc['text'][:150] + '...' if len(doc['text']) > 150 else doc['text']})return jsonify({'corpus_size': len(TREC_DEMO_CORPUS),'corpus_type': 'AP88-90 Demo','documents': docs}), 200@app.route('/api/trec/metrics', methods=['POST'])def trec_metrics():"""Calculate IR evaluation metrics for a retrieval result.Request JSON:{"retrieved": ["AP880101-0001", "AP890215-0001", "AP880101-0002"],"relevant": ["AP880101-0001", "AP880101-0002", "AP880102-0001"]}Response:{"precision_at_3": 0.67,"recall_at_3": 0.67,"average_precision": 0.81,"mrr": 1.0,"ndcg_at_3": 0.88}"""global eval_metricsif eval_metrics is None:eval_metrics = EvaluationMetrics()if not request.is_json:return jsonify({'error': 'Request must be JSON'}), 400data = request.get_json()retrieved = data.get('retrieved', [])relevant = set(data.get('relevant', []))if not retrieved:return jsonify({'error': "'retrieved' list is required"}), 400k = len(retrieved)try:# Calculate metricsp_at_k = eval_metrics.precision_at_k(retrieved, relevant, k)r_at_k = eval_metrics.recall_at_k(retrieved, relevant, k)ap = eval_metrics.average_precision(retrieved, relevant)mrr = eval_metrics.mrr(retrieved, relevant)# For NDCG, create relevance dict (binary: 1 if relevant, 0 otherwise)relevance_dict = {doc: 1 for doc in relevant}ndcg = eval_metrics.ndcg_at_k(retrieved, relevance_dict, k)return jsonify({f'precision_at_{k}': round(p_at_k, 4),f'recall_at_{k}': round(r_at_k, 4),'average_precision': round(ap, 4),'mrr': round(mrr, 4),f'ndcg_at_{k}': round(ndcg, 4),'metrics_explanation': {'P@K': 'Proportion de documents pertinents parmi les K premiers récupérés','R@K': 'Proportion de documents pertinents récupérés parmi tous les pertinents','AP': 'Moyenne des précisions à chaque document pertinent trouvé','MRR': 'Rang réciproque du premier document pertinent','NDCG': 'Gain cumulatif normalisé avec décroissance logarithmique'}}), 200except Exception as e:print(f"[SysCRED Backend] TREC metrics error: {e}")return jsonify({'error': str(e)}), 500@app.route('/api/trec/health', methods=['GET'])def trec_health():"""Health check for TREC module."""return jsonify({'status': 'healthy','trec_available': TREC_AVAILABLE if 'TREC_AVAILABLE' in dir() else True,'retriever_initialized': trec_retriever is not None,'corpus_size': len(TREC_DEMO_CORPUS),'models_available': ['bm25', 'tfidf', 'qld']}), 200# --- Main ---if __name__ == '__main__':print("=" * 60)9 unmodified linesprint()print("[SysCRED Backend] Starting Flask server...")print("[SysCRED Backend] Endpoints:")print(" - POST /api/verify - Full credibility verification")print(" - POST /api/seo - SEO analysis only (faster)")print(" - GET /api/ontology/stats - Ontology statistics")print(" - GET /api/health - Health check")print(" --- TREC Endpoints ---")print(" - POST /api/trec/search - Evidence retrieval (BM25/TF-IDF/QLD)")print(" - POST /api/trec/metrics - Calculate IR metrics (MAP, P@K, NDCG)")print(" - GET /api/trec/corpus - Demo corpus info")print(" - GET /api/trec/health - TREC module health")print()app.run(host='0.0.0.0', port=5001, debug=True)
87 unmodified lines88899091929394959697989910087 unmodified linesPRF_EXPANSION_TERMS = int(os.getenv("SYSCRED_PRF_TERMS", "10"))# === Pondération des scores ===SCORE_WEIGHTS = {'source_reputation': 0.25,'domain_age': 0.10,'sentiment_neutrality': 0.15,'entity_presence': 0.15,'coherence': 0.15,'fact_check': 0.20}# === Seuils de crédibilité ===87 unmodified lines88899091929394959697989910010110287 unmodified linesPRF_EXPANSION_TERMS = int(os.getenv("SYSCRED_PRF_TERMS", "10"))# === Pondération des scores ===# Note: Weights should sum to 1.0 for proper normalizationSCORE_WEIGHTS = {'source_reputation': 0.22, # Was 0.25, reduced for graph_context'domain_age': 0.08, # Was 0.10'sentiment_neutrality': 0.13, # Was 0.15'entity_presence': 0.13, # Was 0.15'coherence': 0.12, # Was 0.15'fact_check': 0.17, # Was 0.20'graph_context': 0.15 # NEW - Historical knowledge from GraphRAG}# === Seuils de crédibilité ===
1234567891011121314151617181920212223242526272829303132333435363738394041LIAR: A BENCHMARK DATASET FOR FAKE NEWS DETECTION
William Yang Wang, "Liar, Liar Pants on Fire": A New Benchmark Dataset for Fake News Detection, to appear in Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (ACL 2017), short paper, Vancouver, BC, Canada, July 30-August 4, ACL.=====================================================================Description of the TSV format:
Column 1: the ID of the statement ([ID].json).Column 2: the label.Column 3: the statement.Column 4: the subject(s).Column 5: the speaker.Column 6: the speaker's job title.Column 7: the state info.Column 8: the party affiliation.Column 9-13: the total credit history count, including the current statement.9: barely true counts.10: false counts.11: half true counts.12: mostly true counts.13: pants on fire counts.Column 14: the context (venue / location of the speech or statement).
Note that we do not provide the full-text verdict report in this current version of the dataset,but you can use the following command to access the full verdict report and links to the source documents:wget http://www.politifact.com//api/v/2/statement/[ID]/?format=json
======================================================================The original sources retain the copyright of the data.
Note that there are absolutely no guarantees with this data,and we provide this dataset "as is",but you are welcome to report the issues of the preliminary versionof this data.
You are allowed to use this dataset for research purposes only.
For more question about the dataset, please contact:William Wang, william@cs.ucsb.edu
v1.0 04/23/2017
132 unmodified lines133134135136137138132 unmodified linesreturn 1.0 / (i + 1)return 0.0# --- TREC-Style Evaluation ---def evaluate_run(132 unmodified lines133134135136137138139140141142143144145146147132 unmodified linesreturn 1.0 / (i + 1)return 0.0@staticmethoddef mrr(retrieved: List[str], relevant: set) -> float:"""Alias for reciprocal_rank (Mean Reciprocal Rank for single query).MRR = 1 / rank of first relevant document"""return EvaluationMetrics.reciprocal_rank(retrieved, relevant)# --- TREC-Style Evaluation ---def evaluate_run(
116 unmodified lines11711811912012112212312412512612712812926 unmodified lines1561571581591601611621631641651 unmodified line167168169170171116 unmodified linesReturns dict with 'text' (for LLM) and 'uris' (for Graph linking)."""if not keywords:return {"text": "", "uris": []}# Build REGEX filter for keywords (OR logic)# e.g., (fake|hoax|conspiracy)clean_kws = [k for k in keywords if len(k) > 3] # Skip short wordsif not clean_kws:return {"text": "", "uris": []}regex_pattern = "|".join(clean_kws)26 unmodified lines})except Exception as e:print(f"[GraphRAG] Similar claims error: {e}")return {"text": "", "uris": []}if not results:return {"text": "", "uris": []}lines = [f"Found {len(results)} similar claims in history:"]for r in results:1 unmodified linereturn {"text": "\n".join(lines),"uris": [r['uri'] for r in results]}116 unmodified lines11711811912012112212312412512612712812926 unmodified lines1561571581591601611621631641651 unmodified line167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296116 unmodified linesReturns dict with 'text' (for LLM) and 'uris' (for Graph linking)."""if not keywords:return {"text": "", "uris": [], "scores": []}# Build REGEX filter for keywords (OR logic)# e.g., (fake|hoax|conspiracy)clean_kws = [k for k in keywords if len(k) > 3] # Skip short wordsif not clean_kws:return {"text": "", "uris": [], "scores": []}regex_pattern = "|".join(clean_kws)26 unmodified lines})except Exception as e:print(f"[GraphRAG] Similar claims error: {e}")return {"text": "", "uris": [], "scores": []}if not results:return {"text": "", "uris": [], "scores": []}lines = [f"Found {len(results)} similar claims in history:"]for r in results:1 unmodified linereturn {"text": "\n".join(lines),"uris": [r['uri'] for r in results],"scores": [r['score'] for r in results]}def compute_context_score(self, domain: str, keywords: List[str] = []) -> Dict[str, float]:"""Compute numerical context scores for integration into credibility scoring.This transforms the GraphRAG context into actionable numerical scoresthat can be directly used in the calculate_overall_score() function.Args:domain: The domain being analyzed (e.g., 'lemonde.fr')keywords: List of keywords from the claimReturns:Dictionary with:- 'history_score': 0.0-1.0 based on past evaluations of this domain- 'pattern_score': 0.0-1.0 based on similar claims in the graph- 'combined_score': Weighted average (0.7 * history + 0.3 * pattern)- 'confidence': How confident we are (based on amount of data)- 'has_history': Boolean if domain has prior evaluations"""result = {'history_score': 0.5, # Neutral default'pattern_score': 0.5,'combined_score': 0.5,'confidence': 0.0,'has_history': False,'history_count': 0,'similar_count': 0}if not self.om:return result# 1. Get source history scorehistory_data = self._get_source_history_data(domain)if history_data['count'] > 0:result['history_score'] = history_data['avg_score']result['has_history'] = Trueresult['history_count'] = history_data['count']# Confidence increases with more data points (max at 5)history_confidence = min(1.0, history_data['count'] / 5)else:history_confidence = 0.0# 2. Get pattern score from similar claimsif keywords:similar_result = self._find_similar_claims(keywords)scores = similar_result.get('scores', [])if scores:result['pattern_score'] = sum(scores) / len(scores)result['similar_count'] = len(scores)pattern_confidence = min(1.0, len(scores) / 3)else:pattern_confidence = 0.0else:pattern_confidence = 0.0# 3. Calculate combined score# Weight history more heavily than pattern matchingif result['has_history'] and result['similar_count'] > 0:result['combined_score'] = 0.7 * result['history_score'] + 0.3 * result['pattern_score']result['confidence'] = 0.6 * history_confidence + 0.4 * pattern_confidenceelif result['has_history']:result['combined_score'] = result['history_score']result['confidence'] = history_confidence * 0.8 # Reduce confidence without patternelif result['similar_count'] > 0:result['combined_score'] = result['pattern_score']result['confidence'] = pattern_confidence * 0.5 # Lower confidence with only patternselse:# No data available - return neutralresult['combined_score'] = 0.5result['confidence'] = 0.0return resultdef _get_source_history_data(self, domain: str) -> Dict[str, Any]:"""Query the graph for evaluation statistics of this domain.Returns:Dictionary with 'count', 'avg_score', 'last_verdict', 'scores'"""if not domain:return {'count': 0, 'avg_score': 0.5, 'scores': []}query = """PREFIX cred: <https://github.com/DominiqueLoyer/systemFactChecking#>SELECT ?score ?level ?timestampWHERE {?info cred:informationURL ?url .?request cred:concernsInformation ?info .?report cred:isReportOf ?request .?report cred:credibilityScoreValue ?score .?report cred:assignsCredibilityLevel ?level .?report cred:completionTimestamp ?timestamp .FILTER(CONTAINS(STR(?url), "%s"))}ORDER BY DESC(?timestamp)LIMIT 10""" % domainscores = []last_verdict = Nonetry:combined = self.om.base_graph + self.om.data_graphfor i, row in enumerate(combined.query(query)):scores.append(float(row.score))if i == 0:last_verdict = str(row.level).split('#')[-1]except Exception as e:print(f"[GraphRAG] History data query error: {e}")return {'count': 0, 'avg_score': 0.5, 'scores': []}if not scores:return {'count': 0, 'avg_score': 0.5, 'scores': []}return {'count': len(scores),'avg_score': sum(scores) / len(scores),'last_verdict': last_verdict,'scores': scores}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101id,statement,ground_truth_6way,ground_truth_binary,ground_truth_ternary,speaker,party,syscred_score,predicted_binary,predicted_ternary,binary_correct,ternary_correct,processing_time,error,sentiment,bias4134.json,"Your tax dollars are not being used to sue you, the people.",FALSE,Fake,False,alan-hays,republican,0.52,Real,Mixed,False,False,3.3536229133605957,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"5710.json,General Motors is the largest corporation in the world again.,FALSE,Fake,False,joe-biden,democrat,0.52,Real,Mixed,False,False,0.7072207927703857,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7356.json,Three in four low-income workers dont have any paid sick days available.,TRUE,Real,True,sherrod-brown,democrat,0.52,Real,Mixed,True,False,0.7895858287811279,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11200.json,"Says 57 percent of federal spending goes to the military and just 1 percent goes to food and agriculture, including food stamps.",FALSE,Fake,False,facebook-posts,none,0.35,Fake,Mixed,True,False,0.8112809658050537,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"447.json,I have never said that I don't wear flag pins or refuse to wear flag pins.,FALSE,Fake,False,barack-obama,democrat,0.52,Real,Mixed,False,False,0.7085680961608887,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2852.json,More than 10 years of free trade has brought a $2 billion per day trade deficit.,MOSTLY_TRUE,Real,True,sherrod-brown,democrat,0.52,Real,Mixed,True,False,1.0006098747253418,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13487.json,"Says that when San Francisco banned plastic grocery bags, you saw the number of instances of people going to the ER with things like salmonella and other related illnesses spike.",BARELY_TRUE,Fake,Mixed,james-quintero,none,0.52,Real,Mixed,False,True,1.4090971946716309,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1084.json,"Now, there was a time when someone like Scalia and Ginsburg got 95-plus votes.",TRUE,Real,True,lindsey-graham,republican,0.52,Real,Mixed,True,False,0.8899619579315186,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13203.json,Toomey and Trump will ban abortion and punish women who have them.,FALSE,Fake,False,naral-pro-choice,organization,0.35,Fake,Mixed,True,False,0.9519002437591553,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"5993.json,Says Larry Taylor gave in-state tuition to illegal immigrants.,PANTS_FIRE,Fake,False,conservative-voters-texas-pac,none,0.52,Real,Mixed,False,False,1.0933752059936523,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4116.json,"POTUS economists: Stimulus Has Cost $278,000 per job.",FALSE,Fake,False,john-boehner,republican,0.52,Real,Mixed,False,False,0.6499719619750977,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12599.json,"If you are a member of union, your median weekly income is roughly $200 more than if you are a nonunion member, and that doesnt include benefits.",TRUE,Real,True,thomas-perez,democrat,0.52,Real,Mixed,True,False,0.7228951454162598,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7819.json,"18 percent of our land in our state right now is either federally, state or county owned for conservation purposes.",TRUE,Real,True,alberta-darling,republican,0.52,Real,Mixed,True,False,0.9661009311676025,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2374.json,"Like me, Scott Walker opposed the 1998 transportation bill and the $9 billion of wasteful spending.",FALSE,Fake,False,jim-sensenbrenner,republican,0.52,Real,Mixed,False,False,0.9515271186828613,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3941.json,The Democrat-led Senate has failed to pass a budget for 750 days ... Senate Democrats have neglected one of their most basic responsibilities.,HALF_TRUE,Real,Mixed,rob-portman,republican,0.54,Real,Mixed,True,True,0.6562759876251221,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1280.json,"Here in Florida, Ive slashed government by 10 percent. That's $7 billion.",BARELY_TRUE,Fake,Mixed,charlie-crist,democrat,0.52,Real,Mixed,False,True,0.9024300575256348,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11661.json,If Trump had just put his fathers money in a mutual fund ... hed have $8 billion.,FALSE,Fake,False,occupy-democrats,organization,0.36,Fake,Mixed,True,False,0.8690879344940186,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6.json,Barack Obama and Hillary Clinton have changed their positions (on the Iraq war withdrawal) to follow Chris Dodd.,HALF_TRUE,Real,Mixed,chris-dodd,democrat,0.53,Real,Mixed,True,True,1.3197407722473145,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3869.json,"When the union says I want to eliminate tenure, thats not true.",HALF_TRUE,Real,Mixed,chris-christie,republican,0.52,Real,Mixed,True,True,0.9137670993804932,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11229.json,"Last year, we had zero percent growth in GDP in Virginia ...The only states that did worse than us were Alaska and Mississippi.",TRUE,Real,True,glen-sturtevant,republican,0.53,Real,Mixed,True,False,0.8765408992767334,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12703.json,"In South Sudan, more teenage girls die in childbirth than finish high school.",MOSTLY_TRUE,Real,True,unicef,none,0.52,Real,Mixed,True,False,1.0562257766723633,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6320.json,Gov. Romneys plan would cut taxes for the folks at the very top.,MOSTLY_TRUE,Real,True,barack-obama,democrat,0.52,Real,Mixed,True,False,0.991412878036499,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7136.json,Says the state is required pick up 70 percent of the cost of K-12 education.,BARELY_TRUE,Fake,Mixed,john-kitzhaber,democrat,0.53,Real,Mixed,False,True,0.9649970531463623,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7552.json,Georgia loses millions of dollars of revenue because people go out of state to buy fireworks.,MOSTLY_TRUE,Real,True,jeff-mullis,republican,0.53,Real,Mixed,True,False,0.7320408821105957,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11118.json,"With the exception of baby formula, the federal government does not require any food to carry an expiration date, and state laws vary widely.",TRUE,Real,True,john-oliver,none,0.52,Real,Mixed,True,False,1.1864137649536133,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7244.json,The amount of money that we put into running our own state legislature is nearly as much as we put into the University of Rhode Island.,FALSE,Fake,False,dawson-hodgson,republican,0.52,Real,Mixed,False,False,1.2284369468688965,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3215.json,Four state Assembly Democrats scored a death blow to northeast Wisconsins economy by killing hundreds of jobs at a potential Bass Pro Shops near Green Bay.,PANTS_FIRE,Fake,False,scott-suder,republican,0.53,Real,Mixed,False,False,1.3722262382507324,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6858.json,"Says opponent U.S. Rep. Gwen Moore is Wisconsins most absent member of Congress, missing nearly 17 percent of the House votes in the second quarter of 2012.",MOSTLY_TRUE,Real,True,dan-sebring,republican,0.52,Real,Mixed,True,False,1.0067930221557617,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4161.json,Active duty males in the military are twice as likely to develop prostate cancer than their civilian counterparts.,MOSTLY_TRUE,Real,True,cliff-stearns,republican,0.52,Real,Mixed,True,False,0.817112922668457,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4568.json,"Says Vince Polistina is collecting nearly $70,000 in taxpayer-funded salaries -- plus a government pension.",BARELY_TRUE,Fake,Mixed,new-jersey-democratic-state-committee,democrat,0.53,Real,Mixed,False,True,0.802901029586792,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11256.json,"Bernie Sanders opposesthe Trans-Pacific Partnership, and Hillary Clinton supportsit.",MOSTLY_TRUE,Real,True,viral-image,none,0.52,Real,Mixed,True,False,0.9945018291473389,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"10450.json,"When you look at the earned income tax credit, it has about a 25 percent fraud rate. Were looking at $20 billion to $30 billion.",HALF_TRUE,Real,Mixed,rand-paul,republican,0.54,Real,Mixed,True,True,1.004997968673706,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"8419.json,Virtually every person across this country has seen premiums going up and up and up due to Obamacare.,FALSE,Fake,False,ted-cruz,republican,0.52,Real,Mixed,False,False,0.9335529804229736,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1015.json,Democrats in Congress had control since January of 2007. They haven't passed a law making waterboarding illegal. They haven't gone into any of these things and changed law.,BARELY_TRUE,Fake,Mixed,newt-gingrich,republican,0.54,Real,Mixed,False,True,0.8649272918701172,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"8557.json,"The United States has never been richer, if you look at per capita GDP.",TRUE,Real,True,jan-schakowsky,democrat,0.53,Real,Mixed,True,False,1.4557609558105469,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3103.json,"George Allen voted for budgets that increased the national debt by $16,400 for every second he served in the U.S. Senate.",TRUE,Real,True,jamie-radtke,republican,0.52,Real,Mixed,True,False,0.8361649513244629,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1576.json,Health insurance companies' costs are only 4 percent of all health care spending.,TRUE,Real,True,americas-health-insurance-plans,none,0.53,Real,Mixed,True,False,1.2063438892364502,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4131.json,"The State Election Board has issued nearly $275,000 in fines to violators of absentee ballot laws.",TRUE,Real,True,brian-kemp,republican,0.53,Real,Mixed,True,False,1.1224148273468018,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7677.json,"The sex-offender registry has been around for a long time, and the research thats out there says that it has no positive impact on the public safety.",MOSTLY_TRUE,Real,True,ohio-public-defenders-office,none,0.52,Real,Mixed,True,False,1.0617139339447021,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4323.json,"When lenders foreclose on homes, they typically suffer losses that exceed 30 percent of the value of the home.",MOSTLY_TRUE,Real,True,thaddeus-mccotter,republican,0.52,Real,Mixed,True,False,0.8316628932952881,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1955.json,"U.S. Rep. Jim Langevin didn't want a border fence to block illegal immigration ""because he is afraid that someone will get hurt trying to go around the fence.""",PANTS_FIRE,Fake,False,michael-j-gardiner,republican,0.52,Real,Mixed,False,False,0.8672749996185303,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4017.json,"On the day of the New Hampshire primary in 1980, the top 13 people of Ronald Reagans staff quit.",MOSTLY_TRUE,Real,True,newt-gingrich,republican,0.52,Real,Mixed,True,False,1.1178889274597168,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"769.json,Barack Obama ... 96 percent of his votes have been solely along party line.,TRUE,Real,True,sarah-palin,republican,0.53,Real,Mixed,True,False,0.8946268558502197,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"171.json,''The leading Democratic candidate once said that the unfettered free market is the most destructive force in modern America.'',FALSE,Fake,False,rudy-giuliani,republican,0.52,Real,Mixed,False,False,0.7632577419281006,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"9944.json,The U.S. Constitution is the oldest written constitution still in use today among nations.,TRUE,Real,True,bob-goodlatte,republican,0.52,Real,Mixed,True,False,0.8168671131134033,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7448.json,Felony crimes in the city of Atlanta are the lowest they have been since 1969.,TRUE,Real,True,kasim-reed,democrat,0.52,Real,Mixed,True,False,0.9511759281158447,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2760.json,Robert Hurt supported a bill that helped the uranium industry after taking contributions from the industry and because his father had a stake in it.,BARELY_TRUE,Fake,Mixed,sierra-club,none,0.52,Real,Mixed,False,True,1.0464277267456055,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"10283.json,"In 1990, the U.S. led the world in the percentage of 25-34 year olds with college degrees. Today we are in 12th place.",MOSTLY_TRUE,Real,True,bernie-s,independent,0.54,Real,Mixed,True,False,0.966181755065918,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"10271.json,"Atlanta Mayor Kasim Reed became a city resident in the last annexation, opening the door to his candidacy.",MOSTLY_TRUE,Real,True,keisha-lance-bottoms,democrat,0.52,Real,Mixed,True,False,0.9616649150848389,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"9788.json,Ive been here almost every day.,BARELY_TRUE,Fake,Mixed,jay-nixon,democrat,0.53,Real,Mixed,False,True,1.5777778625488281,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"8434.json,"Mark Herring voted to allow sex offenders, including rapists, to serve shorter sentences.",BARELY_TRUE,Fake,Mixed,mark-obenshain,republican,0.52,Real,Mixed,False,True,0.902681827545166,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4189.json,"Says U.S. Rep. Ron Kinds stimulus cost taxpayers $278,000 per job.",FALSE,Fake,False,national-republican-congressional-committee,republican,0.52,Real,Mixed,False,False,0.9022071361541748,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11867.json,Says CNN reported Ben Carson was taking a break from campaigning and the Cruz campaign forwarded that news to our volunteers.,FALSE,Fake,False,ted-cruz,republican,0.52,Real,Mixed,False,False,1.0397439002990723,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7285.json,"Says Chris Christies plan to kick-start our economy is to propose an income tax cut that disproportionately benefits the wealthy, and...hes still proposing it.",PANTS_FIRE,Fake,False,barbara-buono,democrat,0.54,Real,Mixed,False,False,1.4161858558654785,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1444.json,"Obama came into office ""with a $1.3 trillion deficit before I had passed any law. ... We came in with $8 trillion worth of debt over the next decade.""",MOSTLY_TRUE,Real,True,barack-obama,democrat,0.54,Real,Mixed,True,False,0.9389801025390625,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7537.json,"The United States spends $2.2 billion on free cell phones, $27 million on Moroccan pottery classes and pays for the travel expenses for the watermelon queen in Alabama.",HALF_TRUE,Real,Mixed,sean-duffy,republican,0.54,Real,Mixed,True,True,1.04280686378479,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2796.json,Half of children struck by cars near schools are hit by parents driving children to school.,FALSE,Fake,False,safe-routes-schools,none,0.52,Real,Mixed,False,False,1.2210850715637207,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"11150.json,Caution: Kissing and cuddling chickens can be hazardous to your health.,TRUE,Real,True,centers-disease-control,none,0.52,Real,Mixed,True,False,0.8850150108337402,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12650.json,You know what (Saddam Hussein) did well? He killed terrorists.,BARELY_TRUE,Fake,Mixed,donald-trump,republican,0.52,Real,Mixed,False,True,0.8362798690795898,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3.json,"New Mexico was 46th in teacher pay (when he was elected), now we're 29th.",MOSTLY_TRUE,Real,True,bill-richardson,democrat,0.52,Real,Mixed,True,False,0.9594571590423584,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1512.json,Fifty-seven of Rubios 100 ideas ultimately became law.,HALF_TRUE,Real,Mixed,marco-rubio,republican,0.52,Real,Mixed,True,True,1.4569880962371826,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3235.json,"Under the White Houses budget proposal, we will not be adding more to the national debt by the middle of the decade.",FALSE,Fake,False,barack-obama,democrat,0.36,Fake,Mixed,True,False,1.4381189346313477,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7909.json,"Says that when the Rolling Stones performed in an Austin park, they paid $25,000 to the nearby city of Rollingwood for one night of inconvenience.",TRUE,Real,True,barry-bone,none,0.52,Real,Mixed,True,False,1.264172077178955,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6812.json,"The Obama administrations green stimulus program funneled close to $2 billion dollars to overseas firms, creating thousands of jobs in China.",BARELY_TRUE,Fake,Mixed,americans-tax-reform,none,0.53,Real,Mixed,False,True,1.306333303451538,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7401.json,"Says, Statistics indicate that one in eight children, and one in 18 adults in Oregon suffers from mental illness.",MOSTLY_TRUE,Real,True,peter-courtney,democrat,0.52,Real,Mixed,True,False,1.0519630908966064,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4391.json,Says Barack Obamas favorability rating in Israel once clocked in at 4 percent.,BARELY_TRUE,Fake,Mixed,kinky-friedman,democrat,0.53,Real,Mixed,False,True,0.9937312602996826,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"9472.json,Oregon school districts are directing 24 percent of their food budgets to purchase local foods. Thats the highest percentage in the country.,HALF_TRUE,Real,Mixed,oregon-department-agriculture,government-body,0.54,Real,Mixed,True,True,1.0283551216125488,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12834.json,On whether hes had a relationship with Vladimir Putin.,FALSE,Fake,False,donald-trump,republican,0.35,Fake,Mixed,True,False,1.1149241924285889,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"5363.json,Obamacare ... will kill jobs across America.,FALSE,Fake,False,us-chamber-commerce,none,0.53,Real,Mixed,False,False,1.557218074798584,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"9080.json,You can buy lobster with food stamps.,TRUE,Real,True,greg-morris,republican,0.69,Real,True,True,True,1.4478328227996826,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12648.json,"Many Nevadans relied on Uber for work, but after accepting $70,000 from taxi companies, Catherine Cortez Masto went after Uber ... (driving) them out of town.",BARELY_TRUE,Fake,Mixed,freedom-partners-action-fund,organization,0.54,Real,Mixed,False,True,1.1827037334442139,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"3330.json,Says Tri-Rail shows the potential problems with investing in high-speed rail.,BARELY_TRUE,Fake,Mixed,rick-scott,republican,0.52,Real,Mixed,False,True,1.007385015487671,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6045.json,Says Hawaii Gov. Neil Abercrombie made a late-night visit to Kinkos to forge President Barack Obamas birth certificate two days before Obama unveiled it to the media.,PANTS_FIRE,Fake,False,chain-email,none,0.52,Real,Mixed,False,False,1.081031322479248,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"8606.json,Republicans have proposed dozens of (health care) solutions designed to help control costs and improve quality.,HALF_TRUE,Real,Mixed,ron-johnson,republican,0.53,Real,Mixed,True,True,1.0788249969482422,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13484.json,"Harambe received 15,000 votes in the presidential election.",PANTS_FIRE,Fake,False,blog-posting,none,0.36,Fake,Mixed,True,False,0.9677271842956543,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12168.json,Expanding the sale of full-strength beer and wine to grocery stores isgood for everybody.,HALF_TRUE,Real,Mixed,your-choice-colorado,organization,0.52,Real,Mixed,True,True,0.8326687812805176,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2252.json,Republicans tried to block the deficit commission.,HALF_TRUE,Real,Mixed,tim-kaine,democrat,0.53,Real,Mixed,True,True,1.0242087841033936,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7696.json,Not one dime gets added to the deficit because of Social Security.,BARELY_TRUE,Fake,Mixed,mark-pocan,democrat,0.53,Real,Mixed,False,True,1.0535731315612793,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13186.json,"Says Donald Trump proposes to deport 16 million people, 11 million who are here without documents, and both Donald Trump and Mike Pence want to get rid of birthright citizenship.",HALF_TRUE,Real,Mixed,tim-kaine,democrat,0.52,Real,Mixed,True,True,1.6496412754058838,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6678.json,"The Senate has not passed a budget in more than three years, not a good budget, not a bad budget, no budget.",TRUE,Real,True,leonard-lance,republican,0.52,Real,Mixed,True,False,1.0171582698822021,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2830.json,A proposal to reduce the deficit involved large tax cuts for the top bracket.,HALF_TRUE,Real,Mixed,paul-krugman,none,0.52,Real,Mixed,True,True,1.0472040176391602,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"9112.json,22 Countries Invaded by the U.S. in 20 Years.,FALSE,Fake,False,facebook-posts,none,0.53,Real,Mixed,False,False,1.4772350788116455,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2774.json,On toll roads.,HALF_TRUE,Real,Mixed,scott-walker,republican,0.52,Real,Mixed,True,True,1.2251579761505127,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4698.json,"Says state Senate President Stephen Sweeney gave us the nations highest income tax rates, driving out jobs.",FALSE,Fake,False,americans-prosperity-new-jersey,none,0.52,Real,Mixed,False,False,1.2662239074707031,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1066.json,ACORN will be a paid partner with the Census Bureau and they will be in charge of going door-to-door and collecting data from the American public.,PANTS_FIRE,Fake,False,michele-bachmann,republican,0.52,Real,Mixed,False,False,0.9788448810577393,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13155.json,Says Ron Johnson helped companies ship jobs overseas.,FALSE,Fake,False,russ-feingold,democrat,0.36,Fake,Mixed,True,False,1.1062400341033936,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13047.json,Barack Obama has doubled our national debt. Doubled it. Its going to be close to $20 trillion when he leaves.,HALF_TRUE,Real,Mixed,donald-trump,republican,0.54,Real,Mixed,True,True,1.301180124282837,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13270.json,We know that more than half of Hillary Clintons meetings while she was secretary of state were given to major contributors to the Clinton Foundation.,BARELY_TRUE,Fake,Mixed,mike-pence,republican,0.53,Real,Mixed,False,True,1.4784371852874756,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"8798.json,And weve constantly been the lowest unemployed county in the state.,FALSE,Fake,False,bob-terry,none,0.53,Real,Mixed,False,False,1.0450530052185059,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1652.json,On recess appointments.,HALF_TRUE,Real,Mixed,barack-obama,democrat,0.52,Real,Mixed,True,True,1.153883934020996,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"5824.json,We didnt go out asking people to join the stand your ground task force.,FALSE,Fake,False,jennifer-carroll,republican,0.53,Real,Mixed,False,False,1.2436339855194092,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"12511.json,There is no system to vet refugees from the Middle East.,FALSE,Fake,False,donald-trump,republican,0.35,Fake,Mixed,True,False,1.1522879600524902,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"2652.json,Says Rick Perry recently said he wanted another (Texas) business tax.,PANTS_FIRE,Fake,False,kathie-glass,libertarian,0.52,Real,Mixed,False,False,1.1576693058013916,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"6141.json,Federal health care reforms amounted to the government takeover of health care.,PANTS_FIRE,Fake,False,tommy-thompson,republican,0.53,Real,Mixed,False,False,1.3367388248443604,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1005.json,Obama used $20 million in federal money to emmigrate (sic) Hamas Refugees to the USA.,PANTS_FIRE,Fake,False,chain-email,none,0.53,Real,Mixed,False,False,1.0034828186035156,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"1760.json,"Says in 2003 Texas cut $10 billion out of the entire budget, yet we put $1.8 billion more into public education. We put $800 million more into health and human services.",BARELY_TRUE,Fake,Mixed,rick-perry,republican,0.54,Real,Mixed,False,True,1.3652348518371582,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"13486.json,Alexander Hamilton was an immigration hawk.,HALF_TRUE,Real,Mixed,rush-limbaugh,none,0.52,Real,Mixed,True,True,1.230626106262207,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"7790.json,Boston Marathon bombing suspect Tamerlan Tsarnaev is buried not far from President Kennedys grave.,PANTS_FIRE,Fake,False,john-depetro,talk-show-host,0.52,Real,Mixed,False,False,1.2205047607421875,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"10512.json,The minimum wage has risen $2.35 in the last two years. Thats 31 percent.,FALSE,Fake,False,leonidas-raptakis,democrat,0.54,Real,Mixed,False,False,1.1163349151611328,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"4337.json,"Before Medicare, only 51 percent of Americans 65 and older had health care coverage and nearly 30 percent lived below the poverty line. Today, thanks to Medicare ... nearly all seniors have coverage a",HALF_TRUE,Real,Mixed,ron-kind,democrat,0.54,Real,Mixed,True,True,1.205260992050171,,,"{'score': 0.0, 'label': 'Neutral', 'method': 'Heuristic'}"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105{ "timestamp": "2026-02-03T11:06:54.379689", "dataset": "LIAR", "metrics": { "total_statements": 100, "successful_evaluations": 100, "error_count": 0, "error_rate": 0.0, "binary": { "accuracy": 0.57, "precision": 1.0, "recall": 0.1568627450980392, "f1": 0.2711864406779661, "confusion_matrix": [ [ 8, 43 ], [ 0, 49 ] ] }, "ternary": { "accuracy": 0.34, "macro_f1": 0.18686868686868685, "confusion_matrix": [ [ 0, 35, 0 ], [ 0, 33, 0 ], [ 0, 31, 1 ] ] }, "classification_report": { "Fake": { "precision": 1.0, "recall": 0.1568627450980392, "f1-score": 0.2711864406779661, "support": 51.0 }, "Real": { "precision": 0.532608695652174, "recall": 1.0, "f1-score": 0.6950354609929078, "support": 49.0 }, "accuracy": 0.57, "macro avg": { "precision": 0.7663043478260869, "recall": 0.5784313725490196, "f1-score": 0.483110950835437, "support": 100.0 }, "weighted avg": { "precision": 0.7709782608695653, "recall": 0.57, "f1-score": 0.4788724606322875, "support": 100.0 } }, "score_distribution": { "mean": 0.5134000000000001, "min": 0.35, "max": 0.69, "median": 0.52 }, "per_party": { "republican": { "count": 43, "accuracy": 0.5581395348837209 }, "democrat": { "count": 27, "accuracy": 0.6296296296296297 } }, "elapsed_time": 108.7882571220398, "statements_per_second": 0.9192168589282478 }, "config": { "threshold": 0.5, "use_graphrag": true, "weights": { "source_reputation": 0.22, "domain_age": 0.08, "sentiment_neutrality": 0.13, "entity_presence": 0.13, "coherence": 0.12, "fact_check": 0.17, "graph_context": 0.15 } }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359# -*- coding: utf-8 -*-"""LIAR Dataset Module - SysCRED==============================Loader for the LIAR benchmark dataset (Wang, 2017).Standard benchmark for fake news detection with 12,800+ political statements.
Dataset: https://www.cs.ucsb.edu/~william/data/liar_dataset.zipPaper: "Liar, Liar Pants on Fire" (ACL 2017)
(c) Dominique S. Loyer - PhD Thesis Prototype"""
import osimport csvfrom pathlib import Pathfrom typing import List, Dict, Optional, Tuplefrom dataclasses import dataclass, fieldfrom enum import Enum
class LiarLabel(Enum): """Six-way truthfulness labels from PolitiFact.""" PANTS_FIRE = 0 FALSE = 1 BARELY_TRUE = 2 HALF_TRUE = 3 MOSTLY_TRUE = 4 TRUE = 5 @classmethod def from_string(cls, label: str) -> 'LiarLabel': """Convert string label to enum.""" mapping = { 'pants-fire': cls.PANTS_FIRE, 'false': cls.FALSE, 'barely-true': cls.BARELY_TRUE, 'half-true': cls.HALF_TRUE, 'mostly-true': cls.MOSTLY_TRUE, 'true': cls.TRUE } return mapping.get(label.lower().strip(), cls.HALF_TRUE) def to_binary(self) -> str: """Convert to binary label (Fake/Real).""" if self.value <= 2: # pants-fire, false, barely-true return "Fake" else: # half-true, mostly-true, true return "Real" def to_ternary(self) -> str: """Convert to ternary label (False/Mixed/True).""" if self.value <= 1: # pants-fire, false return "False" elif self.value <= 3: # barely-true, half-true return "Mixed" else: # mostly-true, true return "True"
@dataclassclass LiarStatement: """A single statement from the LIAR dataset.""" id: str label: LiarLabel statement: str subject: str = "" speaker: str = "" job_title: str = "" state: str = "" party: str = "" barely_true_count: int = 0 false_count: int = 0 half_true_count: int = 0 mostly_true_count: int = 0 pants_fire_count: int = 0 context: str = "" @property def binary_label(self) -> str: """Get binary label (Fake/Real).""" return self.label.to_binary() @property def ternary_label(self) -> str: """Get ternary label (False/Mixed/True).""" return self.label.to_ternary() @property def numeric_label(self) -> int: """Get numeric label (0-5).""" return self.label.value @property def speaker_credit_history(self) -> Dict[str, int]: """Get speaker's historical credibility as a dictionary.""" return { 'barely_true': self.barely_true_count, 'false': self.false_count, 'half_true': self.half_true_count, 'mostly_true': self.mostly_true_count, 'pants_fire': self.pants_fire_count } def to_dict(self) -> Dict: """Convert to dictionary for JSON serialization.""" return { 'id': self.id, 'label': self.label.name, 'binary_label': self.binary_label, 'ternary_label': self.ternary_label, 'statement': self.statement, 'subject': self.subject, 'speaker': self.speaker, 'job_title': self.job_title, 'state': self.state, 'party': self.party, 'context': self.context, 'speaker_credit_history': self.speaker_credit_history }
class LIARDataset: """ Loader for LIAR benchmark dataset. The LIAR dataset contains 12,836 short statements labeled with six fine-grained truthfulness ratings from PolitiFact. Files expected: - train.tsv (10,269 statements) - valid.tsv (1,284 statements) - test.tsv (1,283 statements) Usage: dataset = LIARDataset("/path/to/liar_dataset") train_data = dataset.load_split("train") for statement in train_data: print(f"{statement.statement} -> {statement.label.name}") """ # TSV column indices COL_ID = 0 COL_LABEL = 1 COL_STATEMENT = 2 COL_SUBJECT = 3 COL_SPEAKER = 4 COL_JOB = 5 COL_STATE = 6 COL_PARTY = 7 COL_BARELY_TRUE = 8 COL_FALSE = 9 COL_HALF_TRUE = 10 COL_MOSTLY_TRUE = 11 COL_PANTS_FIRE = 12 COL_CONTEXT = 13 def __init__(self, data_dir: Optional[str] = None): """ Initialize LIAR dataset loader. Args: data_dir: Path to directory containing train.tsv, valid.tsv, test.tsv If None, uses default location: syscred/datasets/liar/ """ if data_dir: self.data_dir = Path(data_dir) else: # Default: relative to this file self.data_dir = Path(__file__).parent / "datasets" / "liar" self._cache: Dict[str, List[LiarStatement]] = {} print(f"[LIAR] Dataset directory: {self.data_dir}") def _parse_int_safe(self, value: str) -> int: """Safely parse int, returning 0 on failure.""" try: return int(value.strip()) except (ValueError, AttributeError): return 0 def _parse_row(self, row: List[str]) -> Optional[LiarStatement]: """Parse a single TSV row into a LiarStatement.""" try: # Ensure we have enough columns if len(row) < 3: return None # Pad row if needed while len(row) < 14: row.append("") return LiarStatement( id=row[self.COL_ID].strip(), label=LiarLabel.from_string(row[self.COL_LABEL]), statement=row[self.COL_STATEMENT].strip(), subject=row[self.COL_SUBJECT].strip() if len(row) > self.COL_SUBJECT else "", speaker=row[self.COL_SPEAKER].strip() if len(row) > self.COL_SPEAKER else "", job_title=row[self.COL_JOB].strip() if len(row) > self.COL_JOB else "", state=row[self.COL_STATE].strip() if len(row) > self.COL_STATE else "", party=row[self.COL_PARTY].strip() if len(row) > self.COL_PARTY else "", barely_true_count=self._parse_int_safe(row[self.COL_BARELY_TRUE]) if len(row) > self.COL_BARELY_TRUE else 0, false_count=self._parse_int_safe(row[self.COL_FALSE]) if len(row) > self.COL_FALSE else 0, half_true_count=self._parse_int_safe(row[self.COL_HALF_TRUE]) if len(row) > self.COL_HALF_TRUE else 0, mostly_true_count=self._parse_int_safe(row[self.COL_MOSTLY_TRUE]) if len(row) > self.COL_MOSTLY_TRUE else 0, pants_fire_count=self._parse_int_safe(row[self.COL_PANTS_FIRE]) if len(row) > self.COL_PANTS_FIRE else 0, context=row[self.COL_CONTEXT].strip() if len(row) > self.COL_CONTEXT else "" ) except Exception as e: print(f"[LIAR] Parse error: {e}") return None def load_split(self, split: str = "test") -> List[LiarStatement]: """ Load a dataset split. Args: split: One of 'train', 'valid', 'test' Returns: List of LiarStatement objects """ if split in self._cache: return self._cache[split] file_path = self.data_dir / f"{split}.tsv" if not file_path.exists(): raise FileNotFoundError( f"LIAR dataset file not found: {file_path}\n" f"Download from: https://www.cs.ucsb.edu/~william/data/liar_dataset.zip" ) statements = [] with open(file_path, 'r', encoding='utf-8') as f: reader = csv.reader(f, delimiter='\t') for row in reader: stmt = self._parse_row(row) if stmt: statements.append(stmt) self._cache[split] = statements print(f"[LIAR] Loaded {len(statements)} statements from {split}.tsv") return statements def get_statements(self, split: str = "test") -> List[str]: """Get just the statement texts.""" return [s.statement for s in self.load_split(split)] def get_labels(self, split: str = "test", label_type: str = "binary") -> List[str]: """ Get labels for a split. Args: split: Dataset split label_type: 'binary' (Fake/Real), 'ternary' (False/Mixed/True), 'six' (original 6-way), 'numeric' (0-5) """ statements = self.load_split(split) if label_type == "binary": return [s.binary_label for s in statements] elif label_type == "ternary": return [s.ternary_label for s in statements] elif label_type == "numeric": return [s.numeric_label for s in statements] else: # six / original return [s.label.name for s in statements] def get_label_distribution(self, split: str = "test") -> Dict[str, int]: """Get count of each label in a split.""" statements = self.load_split(split) distribution = {} for stmt in statements: label = stmt.label.name distribution[label] = distribution.get(label, 0) + 1 return distribution def get_sample(self, split: str = "test", n: int = 10) -> List[LiarStatement]: """Get a random sample of statements.""" import random statements = self.load_split(split) return random.sample(statements, min(n, len(statements))) def get_by_party(self, split: str, party: str) -> List[LiarStatement]: """Filter statements by political party.""" statements = self.load_split(split) return [s for s in statements if s.party.lower() == party.lower()] def get_by_speaker(self, split: str, speaker: str) -> List[LiarStatement]: """Filter statements by speaker name.""" statements = self.load_split(split) return [s for s in statements if speaker.lower() in s.speaker.lower()] def iter_batches(self, split: str, batch_size: int = 32): """Iterate over statements in batches.""" statements = self.load_split(split) for i in range(0, len(statements), batch_size): yield statements[i:i + batch_size] def stats(self) -> Dict[str, Any]: """Get dataset statistics.""" stats = {} for split in ['train', 'valid', 'test']: try: statements = self.load_split(split) stats[split] = { 'count': len(statements), 'label_distribution': self.get_label_distribution(split), 'unique_speakers': len(set(s.speaker for s in statements)), 'unique_parties': list(set(s.party for s in statements if s.party)) } except FileNotFoundError: stats[split] = {'error': 'File not found'} return stats
# Convenience functiondef load_liar(split: str = "test", data_dir: Optional[str] = None) -> List[LiarStatement]: """Quick loader for LIAR dataset.""" dataset = LIARDataset(data_dir) return dataset.load_split(split)
if __name__ == "__main__": print("=" * 60) print("LIAR Dataset Loader - Test") print("=" * 60) # Test with default path try: dataset = LIARDataset() print("\n📊 Dataset Statistics:") stats = dataset.stats() for split, info in stats.items(): print(f"\n{split.upper()}:") if 'error' in info: print(f" ❌ {info['error']}") else: print(f" Total: {info['count']}") print(f" Speakers: {info['unique_speakers']}") print(f" Parties: {info['unique_parties']}") print(f" Labels: {info['label_distribution']}") except Exception as e: print(f"\n❌ Error: {e}") print("\nTo use this module, download the LIAR dataset:") print(" wget https://www.cs.ucsb.edu/~william/data/liar_dataset.zip") print(" unzip liar_dataset.zip -d 02_Code/syscred/datasets/liar/")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434#!/usr/bin/env python3# -*- coding: utf-8 -*-"""LIAR Benchmark Runner - SysCRED================================Scientific evaluation of SysCRED on the LIAR benchmark dataset.
Usage: python run_liar_benchmark.py --split test python run_liar_benchmark.py --sample 100 --verbose python run_liar_benchmark.py --split test --output results/liar_benchmark.csv
(c) Dominique S. Loyer - PhD Thesis Prototype"""
import argparseimport jsonimport timeimport sysfrom pathlib import Pathfrom datetime import datetimefrom typing import Dict, List, Any, Optionalfrom collections import Counter
# Add parent to path for importssys.path.insert(0, str(Path(__file__).parent.parent))
try: import pandas as pd HAS_PANDAS = Trueexcept ImportError: HAS_PANDAS = False print("[Warning] pandas not installed. CSV export will be limited.")
try: from sklearn.metrics import ( accuracy_score, precision_score, recall_score, f1_score, confusion_matrix, classification_report ) HAS_SKLEARN = Trueexcept ImportError: HAS_SKLEARN = False print("[Warning] sklearn not installed. Using basic metrics.")
from syscred.liar_dataset import LIARDataset, LiarStatementfrom syscred.verification_system import CredibilityVerificationSystemfrom syscred import config
class LIARBenchmark: """ Benchmark runner for evaluating SysCRED on LIAR dataset. """ # Map SysCRED score to binary label SYSCRED_THRESHOLD = 0.5 # Below = Fake, Above = Real def __init__( self, data_dir: Optional[str] = None, load_ml: bool = True, use_graphrag: bool = True ): """ Initialize benchmark. Args: data_dir: Path to LIAR dataset directory load_ml: Whether to load ML models use_graphrag: Whether to use GraphRAG context """ print("=" * 60) print("SysCRED LIAR Benchmark Runner") print("=" * 60) # Load dataset self.dataset = LIARDataset(data_dir) # Initialize SysCRED print("\n[Benchmark] Initializing SysCRED...") self.system = CredibilityVerificationSystem( ontology_base_path=str(config.Config.ONTOLOGY_BASE_PATH), ontology_data_path=str(config.Config.ONTOLOGY_DATA_PATH), load_ml_models=load_ml, google_api_key=config.Config.GOOGLE_FACT_CHECK_API_KEY ) self.use_graphrag = use_graphrag self.results: List[Dict] = [] print("[Benchmark] System ready.\n") def _syscred_to_binary(self, score: float) -> str: """Convert SysCRED score to binary label.""" return "Real" if score >= self.SYSCRED_THRESHOLD else "Fake" def _syscred_to_ternary(self, score: float) -> str: """Convert SysCRED score to ternary label.""" if score >= 0.65: return "True" elif score >= 0.35: return "Mixed" else: return "False" def evaluate_statement(self, statement: LiarStatement) -> Dict[str, Any]: """ Evaluate a single statement. Args: statement: LiarStatement to evaluate Returns: Result dictionary with prediction and ground truth """ start_time = time.time() result = { 'id': statement.id, 'statement': statement.statement[:200], 'ground_truth_6way': statement.label.name, 'ground_truth_binary': statement.binary_label, 'ground_truth_ternary': statement.ternary_label, 'speaker': statement.speaker, 'party': statement.party, 'syscred_score': 0.5, 'predicted_binary': 'Unknown', 'predicted_ternary': 'Unknown', 'binary_correct': False, 'ternary_correct': False, 'processing_time': 0, 'error': None } try: # Run SysCRED analysis on the statement text # Note: LIAR statements are short claims, not URLs report = self.system.verify_information(statement.statement) if 'error' not in report: score = report.get('scoreCredibilite', 0.5) result['syscred_score'] = score result['predicted_binary'] = self._syscred_to_binary(score) result['predicted_ternary'] = self._syscred_to_ternary(score) # Check correctness result['binary_correct'] = (result['predicted_binary'] == result['ground_truth_binary']) result['ternary_correct'] = (result['predicted_ternary'] == result['ground_truth_ternary']) # Add extra details if available if 'analyseNLP' in report: result['sentiment'] = report['analyseNLP'].get('sentiment', {}) result['bias'] = report['analyseNLP'].get('bias_analysis', {}) else: result['error'] = report['error'] except Exception as e: result['error'] = str(e) result['processing_time'] = time.time() - start_time return result def run_benchmark( self, split: str = "test", sample_size: Optional[int] = None, verbose: bool = False ) -> Dict[str, Any]: """ Run full benchmark on a dataset split. Args: split: 'train', 'valid', or 'test' sample_size: If set, only evaluate this many statements verbose: Print progress for each statement Returns: Dictionary with metrics and detailed results """ print(f"\n[Benchmark] Running on {split} split...") # Load dataset statements = self.dataset.load_split(split) if sample_size: import random statements = random.sample(statements, min(sample_size, len(statements))) print(f"[Benchmark] Using sample of {len(statements)} statements") total = len(statements) self.results = [] # Progress tracking start_time = time.time() for i, stmt in enumerate(statements): if verbose or (i + 1) % 50 == 0: print(f"[{i+1}/{total}] Processing: {stmt.statement[:50]}...") result = self.evaluate_statement(stmt) self.results.append(result) if verbose: symbol = "✅" if result['binary_correct'] else "❌" print(f" -> Score: {result['syscred_score']:.2f} | " f"Pred: {result['predicted_binary']} | " f"True: {result['ground_truth_binary']} {symbol}") elapsed = time.time() - start_time # Calculate metrics metrics = self._calculate_metrics() metrics['elapsed_time'] = elapsed metrics['statements_per_second'] = total / elapsed if elapsed > 0 else 0 return metrics def _calculate_metrics(self) -> Dict[str, Any]: """Calculate evaluation metrics from results.""" if not self.results: return {'error': 'No results to evaluate'} # Filter successful evaluations valid_results = [r for r in self.results if r['error'] is None] error_count = len(self.results) - len(valid_results) if not valid_results: return {'error': 'All evaluations failed'} metrics = { 'total_statements': len(self.results), 'successful_evaluations': len(valid_results), 'error_count': error_count, 'error_rate': error_count / len(self.results) } # Extract labels y_true_binary = [r['ground_truth_binary'] for r in valid_results] y_pred_binary = [r['predicted_binary'] for r in valid_results] y_true_ternary = [r['ground_truth_ternary'] for r in valid_results] y_pred_ternary = [r['predicted_ternary'] for r in valid_results] # Binary metrics if HAS_SKLEARN: metrics['binary'] = { 'accuracy': accuracy_score(y_true_binary, y_pred_binary), 'precision': precision_score(y_true_binary, y_pred_binary, pos_label='Fake', zero_division=0), 'recall': recall_score(y_true_binary, y_pred_binary, pos_label='Fake', zero_division=0), 'f1': f1_score(y_true_binary, y_pred_binary, pos_label='Fake', zero_division=0), 'confusion_matrix': confusion_matrix(y_true_binary, y_pred_binary, labels=['Fake', 'Real']).tolist() } metrics['ternary'] = { 'accuracy': accuracy_score(y_true_ternary, y_pred_ternary), 'macro_f1': f1_score(y_true_ternary, y_pred_ternary, average='macro', zero_division=0), 'confusion_matrix': confusion_matrix(y_true_ternary, y_pred_ternary, labels=['False', 'Mixed', 'True']).tolist() } # Detailed classification report metrics['classification_report'] = classification_report( y_true_binary, y_pred_binary, target_names=['Fake', 'Real'], output_dict=True ) else: # Basic metrics without sklearn correct_binary = sum(1 for r in valid_results if r['binary_correct']) correct_ternary = sum(1 for r in valid_results if r['ternary_correct']) metrics['binary'] = { 'accuracy': correct_binary / len(valid_results), 'correct': correct_binary, 'incorrect': len(valid_results) - correct_binary } metrics['ternary'] = { 'accuracy': correct_ternary / len(valid_results), 'correct': correct_ternary, 'incorrect': len(valid_results) - correct_ternary } # Score distribution scores = [r['syscred_score'] for r in valid_results] metrics['score_distribution'] = { 'mean': sum(scores) / len(scores), 'min': min(scores), 'max': max(scores), 'median': sorted(scores)[len(scores) // 2] } # Per-party analysis party_results = {} for party in ['republican', 'democrat']: party_items = [r for r in valid_results if r['party'].lower() == party] if party_items: party_correct = sum(1 for r in party_items if r['binary_correct']) party_results[party] = { 'count': len(party_items), 'accuracy': party_correct / len(party_items) } metrics['per_party'] = party_results return metrics def print_results(self, metrics: Dict[str, Any]) -> None: """Pretty-print benchmark results.""" print("\n" + "=" * 60) print("LIAR BENCHMARK RESULTS") print("=" * 60) print(f"\n📊 Overview:") print(f" Total Statements: {metrics.get('total_statements', 0)}") print(f" Successful: {metrics.get('successful_evaluations', 0)}") print(f" Errors: {metrics.get('error_count', 0)} ({metrics.get('error_rate', 0):.1%})") print(f" Processing Time: {metrics.get('elapsed_time', 0):.1f}s") print(f" Speed: {metrics.get('statements_per_second', 0):.2f} stmt/sec") if 'binary' in metrics: print(f"\n📈 Binary Classification (Fake vs Real):") b = metrics['binary'] print(f" Accuracy: {b.get('accuracy', 0):.2%}") print(f" Precision: {b.get('precision', 0):.2%}") print(f" Recall: {b.get('recall', 0):.2%}") print(f" F1-Score: {b.get('f1', 0):.2f}") if 'confusion_matrix' in b: cm = b['confusion_matrix'] print(f"\n Confusion Matrix:") print(f" Pred Fake Pred Real") print(f" True Fake {cm[0][0]:5d} {cm[0][1]:5d}") print(f" True Real {cm[1][0]:5d} {cm[1][1]:5d}") if 'ternary' in metrics: print(f"\n📊 Ternary Classification (False/Mixed/True):") t = metrics['ternary'] print(f" Accuracy: {t.get('accuracy', 0):.2%}") print(f" Macro F1: {t.get('macro_f1', 0):.2f}") if 'per_party' in metrics: print(f"\n🏛️ Per-Party Analysis:") for party, data in metrics['per_party'].items(): print(f" {party.capitalize()}: {data['accuracy']:.2%} accuracy ({data['count']} samples)") if 'score_distribution' in metrics: print(f"\n📉 Score Distribution:") sd = metrics['score_distribution'] print(f" Mean: {sd['mean']:.3f}") print(f" Median: {sd['median']:.3f}") print(f" Range: [{sd['min']:.3f}, {sd['max']:.3f}]") print("\n" + "=" * 60) def save_results(self, output_path: str, metrics: Dict[str, Any]) -> None: """Save results to files.""" output = Path(output_path) output.parent.mkdir(parents=True, exist_ok=True) # Save detailed results as CSV if HAS_PANDAS and self.results: df = pd.DataFrame(self.results) csv_path = output.with_suffix('.csv') df.to_csv(csv_path, index=False) print(f"[Benchmark] Results saved to: {csv_path}") # Save metrics as JSON json_path = output.with_suffix('.json') with open(json_path, 'w') as f: json.dump({ 'timestamp': datetime.now().isoformat(), 'dataset': 'LIAR', 'metrics': metrics, 'config': { 'threshold': self.SYSCRED_THRESHOLD, 'use_graphrag': self.use_graphrag, 'weights': dict(self.system.weights) } }, f, indent=2, default=str) print(f"[Benchmark] Metrics saved to: {json_path}")
def main(): parser = argparse.ArgumentParser(description='Run LIAR benchmark on SysCRED') parser.add_argument('--split', type=str, default='test', choices=['train', 'valid', 'test'], help='Dataset split to evaluate') parser.add_argument('--sample', type=int, default=None, help='Number of statements to sample (for quick testing)') parser.add_argument('--data-dir', type=str, default=None, help='Path to LIAR dataset directory') parser.add_argument('--output', type=str, default=None, help='Output path for results (CSV/JSON)') parser.add_argument('--no-ml', action='store_true', help='Disable ML models for faster testing') parser.add_argument('--verbose', '-v', action='store_true', help='Print details for each statement') args = parser.parse_args() # Run benchmark benchmark = LIARBenchmark( data_dir=args.data_dir, load_ml=not args.no_ml ) try: metrics = benchmark.run_benchmark( split=args.split, sample_size=args.sample, verbose=args.verbose ) benchmark.print_results(metrics) if args.output: benchmark.save_results(args.output, metrics) else: # Default output path default_output = Path(__file__).parent / f"liar_benchmark_{args.split}.csv" benchmark.save_results(str(default_output), metrics) except FileNotFoundError as e: print(f"\n❌ Error: {e}") print("\nTo download the LIAR dataset:") print(" 1. wget https://www.cs.ucsb.edu/~william/data/liar_dataset.zip") print(" 2. unzip liar_dataset.zip -d 02_Code/syscred/datasets/liar/") sys.exit(1)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373#!/usr/bin/env python3# -*- coding: utf-8 -*-"""LIAR Benchmark via Hugging Face Space API==========================================Runs the LIAR benchmark against the remote SysCRED instance on HF Space.This uses the full ML pipeline (PyTorch, Transformers) running in the cloud.
Usage: python run_liar_benchmark_remote.py --sample 100 python run_liar_benchmark_remote.py --split test --url https://your-space.hf.space
(c) Dominique S. Loyer - PhD Thesis Prototype"""
import argparseimport jsonimport timeimport sysfrom pathlib import Pathfrom datetime import datetimefrom typing import Dict, List, Any, Optionalimport requests
try: import pandas as pd HAS_PANDAS = Trueexcept ImportError: HAS_PANDAS = False
try: from sklearn.metrics import ( accuracy_score, precision_score, recall_score, f1_score, confusion_matrix, classification_report ) HAS_SKLEARN = Trueexcept ImportError: HAS_SKLEARN = False
# Add parent to path for importssys.path.insert(0, str(Path(__file__).parent.parent))from syscred.liar_dataset import LIARDataset, LiarStatement
class RemoteLIARBenchmark: """ Benchmark runner using remote HF Space API. """ # Default HF Space URL DEFAULT_API_URL = "https://domloyer-syscred.hf.space" SYSCRED_THRESHOLD = 0.5 # Below = Fake, Above = Real def __init__( self, api_url: Optional[str] = None, data_dir: Optional[str] = None, timeout: int = 60 ): """ Initialize remote benchmark. Args: api_url: HF Space API URL data_dir: Path to LIAR dataset timeout: Request timeout in seconds """ print("=" * 60) print("SysCRED LIAR Benchmark (Remote HF Space)") print("=" * 60) self.api_url = (api_url or self.DEFAULT_API_URL).rstrip('/') self.timeout = timeout # Test connection print(f"\n[Remote] API URL: {self.api_url}") self._test_connection() # Load dataset self.dataset = LIARDataset(data_dir) self.results: List[Dict] = [] print("[Remote] Ready.\n") def _test_connection(self): """Test API connectivity.""" try: response = requests.get(f"{self.api_url}/api/health", timeout=10) if response.status_code == 200: print("[Remote] ✓ API connection successful") else: print(f"[Remote] ⚠ API returned status {response.status_code}") except requests.exceptions.ConnectionError: print("[Remote] ⚠ Could not connect to API (may be sleeping)") print("[Remote] The first request will wake it up...") except Exception as e: print(f"[Remote] ⚠ Connection test failed: {e}") def _call_api(self, text: str) -> Dict[str, Any]: """Call the SysCRED API.""" try: response = requests.post( f"{self.api_url}/api/verify", json={"input": text}, timeout=self.timeout, headers={"Content-Type": "application/json"} ) if response.status_code == 200: return response.json() else: return {"error": f"HTTP {response.status_code}: {response.text[:100]}"} except requests.exceptions.Timeout: return {"error": "Request timeout"} except requests.exceptions.ConnectionError: return {"error": "Connection error"} except Exception as e: return {"error": str(e)} def _syscred_to_binary(self, score: float) -> str: """Convert SysCRED score to binary label.""" return "Real" if score >= self.SYSCRED_THRESHOLD else "Fake" def _syscred_to_ternary(self, score: float) -> str: """Convert SysCRED score to ternary label.""" if score >= 0.65: return "True" elif score >= 0.35: return "Mixed" else: return "False" def evaluate_statement(self, statement: LiarStatement) -> Dict[str, Any]: """Evaluate a single statement via API.""" start_time = time.time() result = { 'id': statement.id, 'statement': statement.statement[:200], 'ground_truth_6way': statement.label.name, 'ground_truth_binary': statement.binary_label, 'ground_truth_ternary': statement.ternary_label, 'speaker': statement.speaker, 'party': statement.party, 'syscred_score': 0.5, 'predicted_binary': 'Unknown', 'predicted_ternary': 'Unknown', 'binary_correct': False, 'ternary_correct': False, 'processing_time': 0, 'error': None, 'ml_used': False } # Call remote API api_result = self._call_api(statement.statement) if 'error' not in api_result: score = api_result.get('scoreCredibilite', 0.5) result['syscred_score'] = score result['predicted_binary'] = self._syscred_to_binary(score) result['predicted_ternary'] = self._syscred_to_ternary(score) result['binary_correct'] = (result['predicted_binary'] == result['ground_truth_binary']) result['ternary_correct'] = (result['predicted_ternary'] == result['ground_truth_ternary']) # Check if ML was used nlp = api_result.get('analyseNLP', {}) result['ml_used'] = nlp.get('sentiment') is not None # GraphRAG info graphrag = api_result.get('graphRAG', {}) result['graph_context_score'] = graphrag.get('context_score') result['graph_has_history'] = graphrag.get('has_history', False) else: result['error'] = api_result['error'] result['processing_time'] = time.time() - start_time return result def run_benchmark( self, split: str = "test", sample_size: Optional[int] = None, verbose: bool = False ) -> Dict[str, Any]: """Run benchmark against remote API.""" print(f"\n[Remote] Running on {split} split via HF Space API...") statements = self.dataset.load_split(split) if sample_size: import random statements = random.sample(statements, min(sample_size, len(statements))) print(f"[Remote] Using sample of {len(statements)} statements") total = len(statements) self.results = [] ml_used_count = 0 start_time = time.time() for i, stmt in enumerate(statements): if verbose or (i + 1) % 10 == 0: print(f"[{i+1}/{total}] Processing: {stmt.statement[:50]}...") result = self.evaluate_statement(stmt) self.results.append(result) if result.get('ml_used'): ml_used_count += 1 if verbose and not result.get('error'): symbol = "✅" if result['binary_correct'] else "❌" ml = "🧠" if result['ml_used'] else "📊" print(f" -> Score: {result['syscred_score']:.2f} {ml} | " f"Pred: {result['predicted_binary']} | " f"True: {result['ground_truth_binary']} {symbol}") # Rate limiting - be nice to the API if i < total - 1: time.sleep(0.5) elapsed = time.time() - start_time metrics = self._calculate_metrics() metrics['elapsed_time'] = elapsed metrics['statements_per_second'] = total / elapsed if elapsed > 0 else 0 metrics['ml_used_percentage'] = (ml_used_count / total * 100) if total > 0 else 0 metrics['api_url'] = self.api_url return metrics def _calculate_metrics(self) -> Dict[str, Any]: """Calculate evaluation metrics.""" if not self.results: return {'error': 'No results'} valid_results = [r for r in self.results if r['error'] is None] error_count = len(self.results) - len(valid_results) if not valid_results: return {'error': 'All evaluations failed'} metrics = { 'total_statements': len(self.results), 'successful_evaluations': len(valid_results), 'error_count': error_count, 'error_rate': error_count / len(self.results) } y_true_binary = [r['ground_truth_binary'] for r in valid_results] y_pred_binary = [r['predicted_binary'] for r in valid_results] y_true_ternary = [r['ground_truth_ternary'] for r in valid_results] y_pred_ternary = [r['predicted_ternary'] for r in valid_results] if HAS_SKLEARN: metrics['binary'] = { 'accuracy': accuracy_score(y_true_binary, y_pred_binary), 'precision': precision_score(y_true_binary, y_pred_binary, pos_label='Fake', zero_division=0), 'recall': recall_score(y_true_binary, y_pred_binary, pos_label='Fake', zero_division=0), 'f1': f1_score(y_true_binary, y_pred_binary, pos_label='Fake', zero_division=0), 'confusion_matrix': confusion_matrix(y_true_binary, y_pred_binary, labels=['Fake', 'Real']).tolist() } metrics['ternary'] = { 'accuracy': accuracy_score(y_true_ternary, y_pred_ternary), 'macro_f1': f1_score(y_true_ternary, y_pred_ternary, average='macro', zero_division=0), } else: correct_binary = sum(1 for r in valid_results if r['binary_correct']) metrics['binary'] = {'accuracy': correct_binary / len(valid_results)} scores = [r['syscred_score'] for r in valid_results] metrics['score_distribution'] = { 'mean': sum(scores) / len(scores), 'min': min(scores), 'max': max(scores), } return metrics def print_results(self, metrics: Dict[str, Any]) -> None: """Print benchmark results.""" print("\n" + "=" * 60) print("LIAR BENCHMARK RESULTS (Remote HF Space)") print("=" * 60) print(f"\n🌐 API: {metrics.get('api_url', 'N/A')}") print(f"🧠 ML Models Used: {metrics.get('ml_used_percentage', 0):.1f}%") print(f"\n📊 Overview:") print(f" Total: {metrics.get('total_statements', 0)}") print(f" Success: {metrics.get('successful_evaluations', 0)}") print(f" Errors: {metrics.get('error_count', 0)}") print(f" Time: {metrics.get('elapsed_time', 0):.1f}s") if 'binary' in metrics: print(f"\n📈 Binary Classification:") b = metrics['binary'] print(f" Accuracy: {b.get('accuracy', 0):.2%}") print(f" Precision: {b.get('precision', 0):.2%}") print(f" Recall: {b.get('recall', 0):.2%}") print(f" F1-Score: {b.get('f1', 0):.2f}") print("\n" + "=" * 60) def save_results(self, output_path: str, metrics: Dict[str, Any]) -> None: """Save results.""" output = Path(output_path) output.parent.mkdir(parents=True, exist_ok=True) if HAS_PANDAS and self.results: df = pd.DataFrame(self.results) csv_path = output.with_suffix('.csv') df.to_csv(csv_path, index=False) print(f"[Remote] Results: {csv_path}") json_path = output.with_suffix('.json') with open(json_path, 'w') as f: json.dump({ 'timestamp': datetime.now().isoformat(), 'dataset': 'LIAR', 'mode': 'remote', 'metrics': metrics }, f, indent=2, default=str) print(f"[Remote] Metrics: {json_path}")
def main(): parser = argparse.ArgumentParser(description='LIAR benchmark via HF Space API') parser.add_argument('--url', type=str, default=None, help='HF Space API URL') parser.add_argument('--split', type=str, default='test', choices=['train', 'valid', 'test']) parser.add_argument('--sample', type=int, default=None, help='Number of statements to sample') parser.add_argument('--data-dir', type=str, default=None) parser.add_argument('--output', type=str, default=None) parser.add_argument('--verbose', '-v', action='store_true') parser.add_argument('--timeout', type=int, default=60) args = parser.parse_args() benchmark = RemoteLIARBenchmark( api_url=args.url, data_dir=args.data_dir, timeout=args.timeout ) try: metrics = benchmark.run_benchmark( split=args.split, sample_size=args.sample, verbose=args.verbose ) benchmark.print_results(metrics) output = args.output or f"liar_benchmark_remote_{args.split}.csv" benchmark.save_results(output, metrics) except FileNotFoundError as e: print(f"\n❌ Error: {e}") sys.exit(1)
if __name__ == "__main__": main()332 unmodified lines3333343353363373386 unmodified lines34534634734834935035135235335435535636 unmodified lines393394395396397398399332 unmodified linestransform: none;box-shadow: none;}</style></head>6 unmodified lines<div class="search-box"><div class="input-group"><input type="text" id="urlInput" placeholder="Entrez une URL à analyser (ex: https://www.lemonde.fr)"autofocus><button id="analyzeBtn" onclick="analyzeUrl()">🔍 Analyser</button></div></div><div class="loading" id="loading">36 unmodified lines</div><script>const API_URL = 'http://localhost:5001';async function analyzeUrl() {const urlInput = document.getElementById('urlInput');332 unmodified lines3333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004016 unmodified lines40840941041141241341441541641741841942042142242342442542642742842943036 unmodified lines467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498332 unmodified linestransform: none;box-shadow: none;}/* Backend Toggle Switch */.backend-toggle {display: flex;align-items: center;justify-content: center;gap: 0.75rem;margin-top: 1rem;padding: 0.75rem;background: rgba(0,0,0,0.2);border-radius: 10px;}.backend-toggle label {font-size: 0.85rem;color: #8b8ba7;cursor: pointer;}.backend-toggle .active {color: #a855f7;font-weight: 600;}.toggle-switch {position: relative;width: 50px;height: 26px;}.toggle-switch input {opacity: 0;width: 0;height: 0;}.toggle-slider {position: absolute;cursor: pointer;top: 0; left: 0; right: 0; bottom: 0;background: linear-gradient(135deg, #22c55e, #16a34a);border-radius: 26px;transition: 0.3s;}.toggle-slider:before {position: absolute;content: '';height: 20px;width: 20px;left: 3px;bottom: 3px;background: white;border-radius: 50%;transition: 0.3s;}.toggle-switch input:checked + .toggle-slider {background: linear-gradient(135deg, #7c3aed, #a855f7);}.toggle-switch input:checked + .toggle-slider:before {transform: translateX(24px);}.backend-status {font-size: 0.75rem;color: #6b6b8a;text-align: center;margin-top: 0.5rem;}.backend-status.local { color: #22c55e; }.backend-status.remote { color: #a855f7; }</style></head>6 unmodified lines<div class="search-box"><div class="input-group"><input type="text" id="urlInput" placeholder="Entrez une URL ou du texte à analyser"autofocus><button id="analyzeBtn" onclick="analyzeUrl()">🔍 Analyser</button></div><!-- Backend Toggle --><div class="backend-toggle"><label id="labelLocal" class="active">🖥️ Local</label><div class="toggle-switch"><input type="checkbox" id="backendToggle" onchange="toggleBackend()"><span class="toggle-slider"></span></div><label id="labelRemote">☁️ HF Space</label></div><div class="backend-status local" id="backendStatus">Backend: localhost:5001 (léger, sans ML)</div></div><div class="loading" id="loading">36 unmodified lines</div><script>// Backend URLsconst LOCAL_API_URL = 'http://localhost:5001';const REMOTE_API_URL = 'https://domloyer-syscred.hf.space';let API_URL = LOCAL_API_URL;function toggleBackend() {const toggle = document.getElementById('backendToggle');const status = document.getElementById('backendStatus');const labelLocal = document.getElementById('labelLocal');const labelRemote = document.getElementById('labelRemote');if (toggle.checked) {API_URL = REMOTE_API_URL;status.textContent = 'Backend: HF Space (ML complet, plus lent)';status.className = 'backend-status remote';labelLocal.classList.remove('active');labelRemote.classList.add('active');} else {API_URL = LOCAL_API_URL;status.textContent = 'Backend: localhost:5001 (léger, sans ML)';status.className = 'backend-status local';labelLocal.classList.add('active');labelRemote.classList.remove('active');}console.log('[SysCRED] Backend switched to:', API_URL);}async function analyzeUrl() {const urlInput = document.getElementById('urlInput');
463 unmodified lines464465466467468469470471472473474475476477170 unmodified lines648649650651652653104 unmodified lines75875976076176276364 unmodified lines828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858463 unmodified linesadjustments += w_ent * boosttotal_weight_used += w_ent# 6. Text Coherence (15%) (Vocabulary Diversity)w_coh = self.weights.get('coherence', 0.15)coherence = nlp_results.get('coherence_score')if coherence is not None:# Coherence is usually 0.0 to 1.0# Center around 0.5: >0.5 improves, <0.5 penalizesadjustments += (coherence - 0.5) * w_cohtotal_weight_used += w_coh# Final calculation# Base 0.5 + sum of weighted adjustments170 unmodified lines'coherence_score': nlp_results.get('coherence_score'),'sentiment_explanation_preview': (nlp_results.get('sentiment_explanation') or [])[:3]},# [NEW] TREC Evidence section'evidences': evidences or [],'metadonnees': {}104 unmodified lines'weight': f"{int(self.weights.get('sentiment_neutrality',0)*100)}%",'impact': '-' if sent.get('score', 0) > 0.9 else '0'})return factors64 unmodified linesprint("[SysCRED] Running rule-based analysis...")rule_results = self.rule_based_analysis(cleaned_text, external_data)# 5. NLP analysisprint("[SysCRED] Running NLP analysis...")nlp_results = self.nlp_analysis(cleaned_text)# 6. Calculate scoreoverall_score = self.calculate_overall_score(rule_results, nlp_results)print(f"[SysCRED] ✓ Credibility score: {overall_score:.2f}")# 7. [NEW] GraphRAG Context Retrievalgraph_context = ""similar_uris = []if self.graph_rag and 'source_analysis' in rule_results:domain = rule_results['source_analysis'].get('domain', '')# Pass keywords for text search if domain is empty or generickeywords = []if not domain and cleaned_text:keywords = cleaned_text.split()[:5] # Simple keyword extractioncontext = self.graph_rag.get_context(domain, keywords=keywords)graph_context = context.get('full_text', '')similar_uris = context.get('similar_uris', [])if "Graph Memory" in graph_context:print(f"[SysCRED] GraphRAG Context Found: {graph_context.splitlines()[1]}")# 8. Generate report (Updated to include context)report = self.generate_report(input_data, cleaned_text, rule_results,463 unmodified lines464465466467468469470471472473474475476477478479480481482483484485486487488489490491170 unmodified lines662663664665666667668669670671672673674675676104 unmodified lines78178278378478578678778878979079179279379479579679779879980064 unmodified lines865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908463 unmodified linesadjustments += w_ent * boosttotal_weight_used += w_ent# 6. Text Coherence (12%) (Vocabulary Diversity)w_coh = self.weights.get('coherence', 0.12)coherence = nlp_results.get('coherence_score')if coherence is not None:# Coherence is usually 0.0 to 1.0# Center around 0.5: >0.5 improves, <0.5 penalizesadjustments += (coherence - 0.5) * w_cohtotal_weight_used += w_coh# 7. [NEW] GraphRAG Context Score (15%)# This uses historical knowledge from the knowledge graphw_graph = self.weights.get('graph_context', 0.15)graph_context_data = rule_results.get('graph_context_data', {})if graph_context_data and graph_context_data.get('confidence', 0) > 0:# Use combined score from GraphRAGgraph_score = graph_context_data.get('combined_score', 0.5)confidence = graph_context_data.get('confidence', 0)# Scale adjustment by confidence (0 confidence = no effect)adjustment_factor = (graph_score - 0.5) * w_graph * confidenceadjustments += adjustment_factortotal_weight_used += w_graph * confidence # Partial weight based on confidence# Final calculation# Base 0.5 + sum of weighted adjustments170 unmodified lines'coherence_score': nlp_results.get('coherence_score'),'sentiment_explanation_preview': (nlp_results.get('sentiment_explanation') or [])[:3]},# [NEW] GraphRAG section'graphRAG': {'context_text': graph_context,'context_score': rule_results.get('graph_context_data', {}).get('combined_score'),'confidence': rule_results.get('graph_context_data', {}).get('confidence', 0),'has_history': rule_results.get('graph_context_data', {}).get('has_history', False),'history_count': rule_results.get('graph_context_data', {}).get('history_count', 0),'similar_claims_count': rule_results.get('graph_context_data', {}).get('similar_count', 0)},# [NEW] TREC Evidence section'evidences': evidences or [],'metadonnees': {}104 unmodified lines'weight': f"{int(self.weights.get('sentiment_neutrality',0)*100)}%",'impact': '-' if sent.get('score', 0) > 0.9 else '0'})# 5. GraphRAG Context (NEW)graph_data = rule_results.get('graph_context_data', {})if graph_data.get('confidence', 0) > 0:graph_score = graph_data.get('combined_score', 0.5)impact = '+' if graph_score > 0.6 else ('-' if graph_score < 0.4 else '0')factors.append({'factor': 'Graph Context (History)','value': f"Score: {graph_score:.2f}, Confidence: {graph_data.get('confidence', 0):.0%}",'weight': f"{int(self.weights.get('graph_context',0)*100)}%",'impact': impact,'history_count': graph_data.get('history_count', 0),'similar_count': graph_data.get('similar_count', 0)})return factors64 unmodified linesprint("[SysCRED] Running rule-based analysis...")rule_results = self.rule_based_analysis(cleaned_text, external_data)# 5. [MOVED] GraphRAG Context Retrieval (Before NLP for context)graph_context = ""similar_uris = []graph_context_data = {}if self.graph_rag and 'source_analysis' in rule_results:domain = rule_results['source_analysis'].get('domain', '')# Pass keywords for text search if domain is empty or generickeywords = []if cleaned_text:# Extract meaningful keywords (filter out short words)keywords = [w for w in cleaned_text.split()[:10] if len(w) > 4]# Get text context for displaycontext = self.graph_rag.get_context(domain, keywords=keywords)graph_context = context.get('full_text', '')similar_uris = context.get('similar_uris', [])# Get numerical score for integration into scoringgraph_context_data = self.graph_rag.compute_context_score(domain, keywords=keywords)# Add to rule_results for use in calculate_overall_scorerule_results['graph_context_data'] = graph_context_dataif graph_context_data.get('has_history'):print(f"[SysCRED] GraphRAG: Domain has {graph_context_data['history_count']} prior evaluations, "f"avg score: {graph_context_data['history_score']:.2f}")if graph_context_data.get('similar_count', 0) > 0:print(f"[SysCRED] GraphRAG: Found {graph_context_data['similar_count']} similar claims")# 6. NLP analysisprint("[SysCRED] Running NLP analysis...")nlp_results = self.nlp_analysis(cleaned_text)# 7. Calculate score (Now includes GraphRAG context)overall_score = self.calculate_overall_score(rule_results, nlp_results)print(f"[SysCRED] ✓ Credibility score: {overall_score:.2f}")# 8. Generate report (Updated to include context)report = self.generate_report(input_data, cleaned_text, rule_results,
syscred/.env.exampleAdded+22
syscred/__init__.py+12-2
syscred/backend_app.py+258-5
syscred/config.py+8-6
syscred/datasets/liar/READMEAdded+41
syscred/datasets/liar/test.tsvAdded
syscred/datasets/liar/train.tsvAdded
syscred/datasets/liar/valid.tsvAdded
syscred/eval_metrics.py+9
syscred/graph_rag.py+130-5
syscred/liar_benchmark_test.csvAdded+101
syscred/liar_benchmark_test.jsonAdded+105
syscred/liar_dataset.pyAdded+359
syscred/run_liar_benchmark.pyAdded+434
syscred/run_liar_benchmark_remote.pyAdded+373
syscred/static/index.html+101-2
syscred/verification_system.py+71-21