Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import openai
- import json
- from typing import List, Dict, Tuple
- import os
- from datetime import datetime
- # Configuration
- OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
- MODEL_NAME = 'o3-2025-04-16'
- CSV_FILE_PATH = 'IFP AI Action Plan Database file.csv'
- # IAPS-aligned keywords for filtering relevant recommendations
- # IAPS-aligned keywords for filtering relevant recommendations
- IAPS_KEYWORDS = [
- # Compute governance (core IAPS focus)
- 'compute', 'compute governance', 'compute policy', 'computational resources',
- 'massive ai compute', 'compute access', 'chip', 'semiconductor', 'ai chip',
- 'location verification', 'hardware', 'gpu', 'inference chip',
- # Export controls and enforcement (key priority)
- 'export control', 'export restriction', 'enforcement', 'smuggling', 'tracking',
- 'verification', 'monitoring', 'compliance', 'bureau of industry', 'bis',
- 'illicit transfer', 'diversion', 'chain of custody',
- # AI Safety Institutes and evaluation
- 'ai safety institute', 'aisi', 'evaluation', 'evaluation science',
- 'benchmark', 'testing', 'assessment', 'safety', 'standards',
- 'risk assessment', 'capability evaluation', 'red team', 'external scrutiny',
- 'aspire framework', 'misuse risk', 'dual-use',
- # International governance and US-China competition
- 'international governance', 'us-china', 'china competition', 'global stability',
- 'international coordination', 'ai state capacity', 'international network',
- 'allied', 'coalition', 'bilateral', 'multilateral', 'global ai governance',
- # National security and defense
- 'national security', 'national defense', 'cyber', 'autonomy',
- 'offense-defense balance', 'adversary', 'strategic competition',
- 'military', 'defense industrial base', 'critical infrastructure',
- # Supply chain and information security
- 'supply chain security', 'information security', 'internal model',
- 'unreleased model', 'model weight', 'intellectual property', 'theft',
- # Lab governance and AI agents
- 'lab governance', 'ai lab', 'ai agent', 'agent governance', 'agentic',
- 'autonomous system', 'frontier ai', 'advanced ai system',
- # Strategic and competitive advantage
- 'national competitiveness', 'technological edge', 'strategic advantage',
- 'leadership', 'innovation', 'us leadership', 'competitive edge',
- 'technological superiority', 'strategic computing'
- ]
- def load_database(filepath: str) -> pd.DataFrame:
- """Load the AI Action Database from CSV file."""
- try:
- df = pd.read_csv(filepath, encoding='utf-8')
- print(f"Successfully loaded {len(df)} recommendations from database")
- return df
- except Exception as e:
- print(f"Error loading database: {e}")
- raise
- def filter_relevant_recommendations(df: pd.DataFrame, keywords: List[str]) -> pd.DataFrame:
- """Filter recommendations based on IAPS-aligned keywords."""
- # Create searchable text by combining relevant fields
- df['searchable_text'] = (
- df['Recommendation'].fillna('') + ' ' +
- df['Details'].fillna('') + ' ' +
- df['Justification'].fillna('') + ' ' +
- df['Topic'].fillna('')
- ).str.lower()
- # Filter based on keywords
- keyword_pattern = '|'.join(keywords)
- relevant_df = df[df['searchable_text'].str.contains(keyword_pattern, case=False, na=False)]
- # Additional filtering for quality - ensure substantial content
- relevant_df = relevant_df[
- (relevant_df['Details'].str.len() > 200) &
- (relevant_df['Justification'].str.len() > 100)
- ]
- print(f"Filtered to {len(relevant_df)} relevant recommendations")
- return relevant_df
- def prepare_recommendation_for_scoring(row: pd.Series) -> Dict:
- """Prepare a recommendation for scoring by the o3 model."""
- return {
- 'title': row['Recommendation'],
- 'organization': row['Organization'],
- 'org_type': row['OrgType'],
- 'details': row['Details'][:1000], # Limit to manage token usage
- 'justification': row['Justification'][:500],
- 'topic': row['Topic']
- }
- def score_recommendation(client: openai.OpenAI, recommendation: Dict) -> Tuple[Dict, float]:
- """Score a single recommendation using o3 model."""
- scoring_prompt = f"""
- Analyze this AI policy recommendation for the Institute for AI Policy and Strategy (IAPS).
- IAPS focuses on compute governance, export controls, strategic partnerships, and maintaining US AI leadership.
- Recommendation: {recommendation['title']}
- Organization: {recommendation['organization']} ({recommendation['org_type']})
- Topic: {recommendation['topic']}
- Details: {recommendation['details']}
- Justification: {recommendation['justification']}
- Score this recommendation on the following dimensions (0-10 scale):
- 1. Political Feasibility: How likely is this to gain bipartisan support and be implemented?
- 2. IAPS Alignment: How well does this align with IAPS priorities (compute control, export enforcement, allied cooperation)?
- 3. Innovation Potential: How novel and forward-thinking is this approach?
- 4. Projected Impact: How significantly would this advance US AI leadership and security?
- Provide your response as a JSON object with these keys:
- - political_feasibility: (0-10)
- - iaps_alignment: (0-10)
- - innovation_potential: (0-10)
- - projected_impact: (0-10)
- - total_score: (sum of all scores)
- - brief_rationale: (2-3 sentences explaining the scoring)
- Return only the JSON object, no other text.
- """
- try:
- response = client.chat.completions.create(
- model=MODEL_NAME,
- messages=[
- {"role": "system", "content": "You are an expert AI policy analyst evaluating recommendations for strategic importance."},
- {"role": "user", "content": scoring_prompt}
- ],
- max_completion_tokens=500
- )
- # Parse the JSON response
- score_data = json.loads(response.choices[0].message.content)
- return score_data, score_data['total_score']
- except Exception as e:
- print(f"Error scoring recommendation '{recommendation['title']}': {e}")
- return None, 0
- def analyze_recommendations(filepath: str, num_recommendations: int = 3) -> List[Dict]:
- """Main analysis function to identify top policy recommendations."""
- # Initialize OpenAI client
- client = openai.OpenAI(api_key=OPENAI_API_KEY)
- # Load and filter database
- df = load_database(filepath)
- relevant_df = filter_relevant_recommendations(df, IAPS_KEYWORDS)
- # Limit analysis to top 50 most relevant to manage API costs
- # Sort by relevance (number of keyword matches)
- relevant_df['keyword_matches'] = relevant_df['searchable_text'].apply(
- lambda x: sum(1 for keyword in IAPS_KEYWORDS if keyword in x)
- )
- relevant_df = relevant_df.nlargest(10, 'keyword_matches')
- print(f"\nAnalyzing top {len(relevant_df)} most relevant recommendations...")
- # Score each recommendation
- scored_recommendations = []
- for idx, row in relevant_df.iterrows():
- print(f"Scoring {idx + 1}/{len(relevant_df)}: {row['Recommendation'][:60]}...")
- rec_data = prepare_recommendation_for_scoring(row)
- score_data, total_score = score_recommendation(client, rec_data)
- if score_data:
- scored_recommendations.append({
- 'recommendation': row['Recommendation'],
- 'organization': row['Organization'],
- 'details': row['Details'],
- 'justification': row['Justification'],
- 'scores': score_data,
- 'total_score': total_score
- })
- # Sort by total score and return top N
- scored_recommendations.sort(key=lambda x: x['total_score'], reverse=True)
- top_recommendations = scored_recommendations[:num_recommendations]
- print(f"\n{'='*60}")
- print(f"TOP {num_recommendations} RECOMMENDATIONS FOR IAPS")
- print(f"{'='*60}\n")
- for i, rec in enumerate(top_recommendations, 1):
- print(f"{i}. {rec['recommendation']}")
- print(f" Organization: {rec['organization']}")
- print(f" Total Score: {rec['total_score']}/40")
- print(f" Breakdown: Political={rec['scores']['political_feasibility']}, "
- f"IAPS={rec['scores']['iaps_alignment']}, "
- f"Innovation={rec['scores']['innovation_potential']}, "
- f"Impact={rec['scores']['projected_impact']}")
- print(f" Rationale: {rec['scores']['brief_rationale']}")
- print()
- # Save results to file
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
- output_file = f"iaps_policy_analysis_{timestamp}.json"
- with open(output_file, 'w') as f:
- json.dump({
- 'analysis_date': timestamp,
- 'total_recommendations_analyzed': len(scored_recommendations),
- 'top_recommendations': top_recommendations
- }, f, indent=2)
- print(f"Full results saved to: {output_file}")
- return top_recommendations
- if __name__ == "__main__":
- # Run the analysis
- try:
- top_policies = analyze_recommendations(CSV_FILE_PATH)
- except Exception as e:
- print(f"Analysis failed: {e}")
Advertisement
Add Comment
Please, Sign In to add comment