KShoichi commited on
Commit
5031515
Β·
verified Β·
1 Parent(s): 2e4d3f7

Upload debug_rules.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. debug_rules.py +82 -0
debug_rules.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Debug the rule-based detection system
4
+ """
5
+
6
+ import requests
7
+ import json
8
+
9
+ BASE_URL = "http://localhost:8000"
10
+
11
+ def debug_rule_detection():
12
+ """Debug rule detection for specific cases"""
13
+
14
+ print("πŸ” DEBUGGING RULE-BASED DETECTION")
15
+ print("=" * 50)
16
+
17
+ test_cases = [
18
+ {
19
+ "name": "Geography - Wrong Capital",
20
+ "prompt": "Question: What is the capital of France?",
21
+ "response": "London is the capital of France",
22
+ "question": "What is the capital of France?",
23
+ "expected_rule": "Should detect geography contradiction"
24
+ },
25
+ {
26
+ "name": "Science - Wrong Heart Chambers",
27
+ "prompt": "Question: How many chambers does the human heart have?",
28
+ "response": "The human heart has 6 chambers",
29
+ "question": "How many chambers does the human heart have?",
30
+ "expected_rule": "Should detect science contradiction"
31
+ },
32
+ {
33
+ "name": "Physics - Wrong Planet Size",
34
+ "prompt": "Question: Which is larger, Earth or Jupiter?",
35
+ "response": "Earth is larger than Jupiter",
36
+ "question": "Which is larger, Earth or Jupiter?",
37
+ "expected_rule": "Should detect physics contradiction"
38
+ }
39
+ ]
40
+
41
+ for i, test in enumerate(test_cases, 1):
42
+ print(f"\nπŸ§ͺ Debug Test {i}: {test['name']}")
43
+ print(f"❓ Question: {test['question']}")
44
+ print(f"πŸ“„ Response: {test['response']}")
45
+ print(f"πŸ” Expected Rule: {test['expected_rule']}")
46
+
47
+ payload = {
48
+ "prompt": test["prompt"],
49
+ "response": test["response"],
50
+ "question": test["question"],
51
+ "use_cache": False
52
+ }
53
+
54
+ try:
55
+ # Use debug endpoint
56
+ response = requests.post(f"{BASE_URL}/api/debug-predict", json=payload, timeout=10)
57
+ if response.status_code == 200:
58
+ result = response.json()
59
+ print(f"πŸ€– Raw Model Output: '{result.get('raw_model_output', '')}'")
60
+ print(f"πŸ“Š Is Hallucination: {result.get('is_hallucination', False)}")
61
+ print(f"πŸ“Š Confidence: {result.get('confidence_score', 0):.1%}")
62
+
63
+ # Also test regular endpoint
64
+ response2 = requests.post(f"{BASE_URL}/api/predict", json=payload, timeout=10)
65
+ if response2.status_code == 200:
66
+ result2 = response2.json()
67
+ print(f"πŸ”§ Final Is Hallucination: {result2.get('is_hallucination', False)}")
68
+ print(f"πŸ”§ Final Confidence: {result2.get('confidence_score', 0):.1%}")
69
+
70
+ # Check if confidence changed (indicating rule assistance)
71
+ if abs(result.get('confidence_score', 0) - result2.get('confidence_score', 0)) > 0.01:
72
+ print("βœ… RULE ASSISTANCE DETECTED")
73
+ else:
74
+ print("❌ NO RULE ASSISTANCE")
75
+ else:
76
+ print(f"❌ Error: {response.status_code}")
77
+
78
+ except Exception as e:
79
+ print(f"❌ Error: {e}")
80
+
81
+ if __name__ == "__main__":
82
+ debug_rule_detection()