forked from Nikhil-Jones/Fake-News-Detector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomprehensive_test.py
More file actions
179 lines (152 loc) · 9.18 KB
/
comprehensive_test.py
File metadata and controls
179 lines (152 loc) · 9.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from main import ImprovedFakeNewsScorer
def run_comprehensive_tests():
print("="*80)
print("COMPREHENSIVE FAKE NEWS DETECTION TEST")
print("Enhanced System with Foolproof Detection")
print("="*80)
detector = ImprovedFakeNewsScorer()
critical_fake_cases = [
{
"title": "Medical Impossibility #1",
"text": "BREAKING: Scientists confirm chocolate cures all cancer! Doctors hate this one weird trick. Studies show eating 10 chocolate bars daily will make you live forever. Big Pharma doesn't want you to know this secret ancient remedy! SHARE IMMEDIATELY BEFORE THEY DELETE!",
"source": "miracle-health.com",
"expected": "Likely Fake",
},
{
"title": "Absurd Claim #1",
"text": "SHOCKING DISCOVERY!!! BREAKING NEWS!!! Scientists discover miracle herb that cures all diseases overnight! Doctors hate it! Doctors hate this! This incredible breakthrough will revolutionize everything! MUST SEE! SHARE THIS! SHARE IMMEDIATELY BEFORE THEY DELETE! Big Pharma doesn't want you to know! Fake news mainstream media! You won't believe this! Amazing secret remedy! UNBELIEVABLE! This will shock you! VIRAL sensation! Ancient secret! Hidden truth! Scientists refuse to reveal!",
"source": "alien-news.net",
"expected": "Likely Fake",
},
{
"title": "Dangerous Medical Advice",
"text": "UNBELIEVABLE!!! BREAKING NEWS!!! You won't believe this shocking trick to make your body invincible! Big Pharma is furious! This amazing secret remedy they don't want you to know! VIRAL SENSATION! SHARE BEFORE CENSORED! Doctors hate this! Fake news mainstream media trying to hide! Scientists refuse to reveal! Amazing breakthrough! Incredible discovery! Shocking truth! MUST SEE! This will shock you! Hidden truth! Ancient remedy! You won't believe! One weird trick! SHARE IMMEDIATELY!!!",
"source": "health-secrets.org",
"expected": "Likely Fake",
},
{
"title": "Supernatural Impossibility",
"text": "BREAKING NEWS!!! BREAKING!!! President secretly controls the weather using advanced satellites! This incredible coverup by mainstream media is finally revealed! VIRAL spread all over social media! MUST SEE! SHOCKING TRUTH! This will shock you! Amazing discovery! You won't believe! Fake news trying to hide! Scientists refuse to reveal! SHARE IMMEDIATELY! SHARE THIS! Doctors hate this! Big Pharma involved! Ancient secret! Hidden truth! Unbelievable! One weird trick! VIRAL SENSATION!",
"source": "time-travel-news.com",
"expected": "Likely Fake",
},
{
"title": "Medical Conspiracy",
"text": "COVID-19 vaccine turns people into zombies! SHOCKING! MUST SEE shocking results! Big Pharma doesn't want you to know this terrible truth! Scientists refuse to reveal this secret! SHARE IMMEDIATELY!!! BREAKING NEWS!!! This incredible discovery! UNBELIEVABLE! You won't believe! Amazing revelation! Doctors hate this! Fake news mainstream media! VIRAL sensation! This will shock you! SHARE BEFORE DELETED! Hidden truth! Ancient secret! One weird trick! Scientists refuse!",
"source": "natural-cures.net",
"expected": "Likely Fake",
},
{
"title": "Extreme Quantity Claim",
"text": "AMAZING discovery!!! Eating 50 bananas a day will grant immortality! Scientists refuse to reveal this ancient secret remedy! Big Pharma is hiding this incredible breakthrough! VIRAL sensation! SHARE BEFORE DELETED!",
"source": "immortality-secrets.com",
"expected": "Likely Fake",
}
]
legitimate_cases = [
{
"title": "Legitimate Medical Research",
"text": "New study published in peer-reviewed journal shows promising results for cancer treatment.",
"source": "nature.com",
"expected": "Likely Real",
},
{
"title": "Normal News Reporting",
"text": "Local weather forecast predicts rain this weekend across the region.",
"source": "bbc.com",
"expected": "Likely Real",
},
{
"title": "Cautious Medical Reporting",
"text": "Researchers suggest that moderate exercise may help reduce risk of heart disease.",
"source": "reuters.com",
"expected": "Likely Real",
}
]
print("\n🔴 TESTING CRITICAL FAKE CASES (Must be detected as FAKE):")
print("="*80)
fake_detection_score = 0
total_fake_tests = len(critical_fake_cases)
for i, test_case in enumerate(critical_fake_cases, 1):
print(f"\n{i}. {test_case['title']}")
print(f" Text: \"{test_case['text']}\"")
print(f" Source: {test_case['source']}")
print(f" Expected: {test_case['expected']}")
print("-" * 60)
result = detector.classify(
original_text=test_case['text'],
source_analysis={"url": test_case['source']}
)
print("\nAnalysis Result:")
print(f"Label: {result['label']}")
print(f"Probability: {result['probability']:.3f}")
print(f"Confidence: {result['confidence_score']:.3f} ({result['confidence_level']})")
if 'debug' in result:
print("\nDebug Info:")
print(f" Content Score: {result['debug']['content_score']:.3f}")
print(f" Source Score: {result['debug']['source_score']:.3f}")
print(f" Frequency Bias: {result['debug']['frequency_bias']:.3f}")
print(f" Trie Suspicion: {result['debug']['trie_suspicion']:.3f}")
print(f" Medical Score: {result['debug']['medical_score']:.3f}")
print(f" Absurd Score: {result['debug']['absurd_score']:.3f}")
print(f" Found Keywords: {result['debug']['found_keywords']}")
print(f" Fake-Biased Words: {result['debug']['fake_biased_words']}")
print(f" Problematic Patterns: {result['debug']['problematic_patterns']}")
print("\nExplanations:")
for exp in result['explanations']:
print(f" - {exp}")
if result['label'] == test_case['expected']:
print("STATUS: ✅ CORRECTLY DETECTED AS FAKE")
fake_detection_score += 1
else:
print("STATUS: ❌ FAILED TO DETECT AS FAKE")
print("="*80)
print(f"\n🟢 TESTING LEGITIMATE CASES (Should be classified as REAL):")
print("="*80)
real_detection_score = 0
total_real_tests = len(legitimate_cases)
for i, test_case in enumerate(legitimate_cases, 1):
print(f"\n{i}. {test_case['title']}")
print(f" Text: \"{test_case['text']}\"")
print(f" Source: {test_case['source']}")
print(f" Expected: {test_case['expected']}")
print("-" * 60)
result = detector.classify(
original_text=test_case['text'],
source_analysis={"url": test_case['source']}
)
print("\nAnalysis Result:")
print(f"Label: {result['label']}")
print(f"Probability: {result['probability']:.3f}")
print(f"Confidence: {result['confidence_score']:.3f} ({result['confidence_level']})")
if 'debug' in result:
print("\nDebug Info:")
print(f" Content Score: {result['debug']['content_score']:.3f}")
print(f" Source Score: {result['debug']['source_score']:.3f}")
print(f" Frequency Bias: {result['debug']['frequency_bias']:.3f}")
print(f" Trie Suspicion: {result['debug']['trie_suspicion']:.3f}")
print(f" Medical Score: {result['debug']['medical_score']:.3f}")
print(f" Absurd Score: {result['debug']['absurd_score']:.3f}")
print(f" Found Keywords: {result['debug']['found_keywords']}")
print(f" Fake-Biased Words: {result['debug']['fake_biased_words']}")
print(f" Problematic Patterns: {result['debug']['problematic_patterns']}")
print("\nExplanations:")
for exp in result['explanations']:
print(f" - {exp}")
if result['label'] == test_case['expected']:
print("STATUS: ✅ CORRECTLY CLASSIFIED AS REAL")
real_detection_score += 1
else:
print("STATUS: ❌ INCORRECTLY FLAGGED AS FAKE")
print("="*80)
fake_accuracy = (fake_detection_score / total_fake_tests) * 100
real_accuracy = (real_detection_score / total_real_tests) * 100
overall_accuracy = ((fake_detection_score + real_detection_score) / (total_fake_tests + total_real_tests)) * 100
print(f"\n📊 OVERALL PERFORMANCE RESULTS:")
print("="*60)
print(f"Fake News Detection: {fake_detection_score}/{total_fake_tests} ({fake_accuracy:.1f}%)")
print(f"Real News Detection: {real_detection_score}/{total_real_tests} ({real_accuracy:.1f}%)")
print(f"Overall Accuracy: {fake_detection_score + real_detection_score}/{total_fake_tests + total_real_tests} ({overall_accuracy:.1f}%)")
print("="*80)
if _name_ == "_main_":
run_comprehensive_tests()