Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219· AnthropicHugging Face LMArena Human Preference 140K

Can you suggest a python code for a simple sentiment project?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    Can you suggest a python code for a simple sentiment project?

  2. Claude Assistant

    Here's a simple Python sentiment analysis project using the NLTK library:

    import nltk
    from nltk.sentiment import SentimentIntensityAnalyzer
    import pandas as pd
    
    # Download necessary NLTK data
    nltk.download('vader_lexicon')
    
    def analyze_sentiment(text):
        sia = SentimentIntensityAnalyzer()
        score = sia.polarity_scores(text)
        
        # Determine sentiment based on compound score
        if score['compound'] >= 0.05:
            return 'Positive'
        elif score['compound'] <= -0.05:
            return 'Negative'
        else:
            return 'Neutral'
    
    # Example usage
    if __name__ == "__main__":
        # Sample texts
        texts = [
            "I absolutely loved the movie! The acting was superb.",
            "The service at this restaurant was terrible and the food was cold.",
            "The weather is okay today, nothing special."
        ]
        
        # Analyze and display results
        results = []
        for text in texts:
            sentiment = analyze_sentiment(text)
            score = SentimentIntensityAnalyzer().polarity_scores(text)
            results.append({
                'text': text,
                'sentiment': sentiment,
                'score': score['compound']
            })
        
        # Create a DataFrame for better visualization
        df = pd.DataFrame(results)
        print(df)
    

    Would you like me to explain or break down this code?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.