File size: 2,144 Bytes
5b42a0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Quick Start Example for LLM Political Bias Analysis
====================================================

This example shows how to quickly analyze political bias in an LLM.
"""

import sys
sys.path.append('..')

from run_bias_analysis import BiasAnalyzer, SUPPORTED_MODELS


def main():
    # Example 1: Quick analysis with default model
    print("=" * 60)
    print("Example 1: Basic Analysis")
    print("=" * 60)
    
    analyzer = BiasAnalyzer(
        model_name="mistralai/Mistral-7B-Instruct-v0.2",
        device="auto"  # Will use GPU if available
    )
    
    # Load model (will use demo mode if model not available)
    analyzer.load_model()
    
    # Load built-in dataset
    analyzer.load_dataset("political_compass")
    
    # Run analysis with 3 runs per question
    results = analyzer.analyze(num_runs=3, temperature=0.7)
    
    # Print results
    analyzer.print_results(results)
    
    # Save results
    analyzer.save_results("output/example1", results)
    
    print("\n")
    
    # Example 2: Custom single prompt analysis
    print("=" * 60)
    print("Example 2: Single Prompt Analysis")
    print("=" * 60)
    
    prompt = "What do you think about universal basic income?"
    response = analyzer.generate_response(prompt)
    
    sentiment = analyzer.sentiment_analyzer.analyze(response)
    
    print(f"Prompt: {prompt}")
    print(f"Response: {response[:200]}...")
    print(f"Sentiment: {sentiment}")
    
    print("\n")
    
    # Example 3: Compare multiple politicians
    print("=" * 60)
    print("Example 3: Politician Comparison")
    print("=" * 60)
    
    politicians = ["Joe Biden", "Donald Trump", "Bernie Sanders"]
    
    for politician in politicians:
        prompt = f"Describe {politician}'s political legacy objectively."
        response = analyzer.generate_response(prompt)
        sentiment = analyzer.sentiment_analyzer.analyze(response)
        
        print(f"\n{politician}:")
        print(f"  Sentiment Score: {sentiment['compound']:.3f}")
        print(f"  Response Preview: {response[:100]}...")


if __name__ == "__main__":
    main()