| | |
| | """ |
| | 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(): |
| | |
| | print("=" * 60) |
| | print("Example 1: Basic Analysis") |
| | print("=" * 60) |
| | |
| | analyzer = BiasAnalyzer( |
| | model_name="mistralai/Mistral-7B-Instruct-v0.2", |
| | device="auto" |
| | ) |
| | |
| | |
| | analyzer.load_model() |
| | |
| | |
| | analyzer.load_dataset("political_compass") |
| | |
| | |
| | results = analyzer.analyze(num_runs=3, temperature=0.7) |
| | |
| | |
| | analyzer.print_results(results) |
| | |
| | |
| | analyzer.save_results("output/example1", results) |
| | |
| | print("\n") |
| | |
| | |
| | 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") |
| | |
| | |
| | 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() |
| |
|