Challenge: Sentiment Analysis of Headlines
Sentiment analysis is a powerful tool for editorial teams, allowing you to quickly assess the tone of news content and understand how stories might be perceived by audiences. By systematically scoring headlines or articles as positive, negative, or neutral, you can uncover patterns in coverage, identify potential biases, and inform decisions about story selection or framing. This technique is especially valuable when reviewing large volumes of content, where manual assessment would be impractical.
1234567891011121314151617181920212223242526272829303132333435363738# Predefined lists of positive and negative words positive_words = ["success", "growth", "win", "improve", "benefit", "progress", "record", "boost"] negative_words = ["decline", "loss", "fail", "drop", "crisis", "scandal", "risk", "cut"] # Sample list of news headlines headlines = [ "City sees record growth in tech sector", "Local school faces budget cuts amid crisis", "Community benefits from new park opening", "Economy at risk as markets decline", "Team wins championship after tough season", "Government faces criticism over policy fail", "Residents celebrate progress in recycling efforts" ] def score_sentiment(headline): words = headline.lower().split() score = 0 for word in words: if word in positive_words: score += 1 elif word in negative_words: score -= 1 return score def classify_sentiment(score): if score > 0: return "positive" elif score < 0: return "negative" else: return "neutral" # Analyze each headline for headline in headlines: score = score_sentiment(headline) sentiment = classify_sentiment(score) print(f"'{headline}' => {sentiment} (score: {score})")
When newsroom teams use sentiment analysis, you gain a data-driven perspective on how your headlines and stories might affect public perception. Regularly reviewing sentiment scores can help editors spot trends—such as a tendency toward negative framing or a lack of positive stories—and lead to productive discussions about editorial balance. This process can also provide insights into how coverage aligns with audience expectations and organizational values, ultimately supporting more informed, intentional journalism.
Swipe to start coding
Write a script to analyze the sentiment of a list of news headlines using predefined positive and negative word lists.
- For each headline in the
headlineslist, score the sentiment using thescore_sentimentfunction. - Classify each headline as positive, negative, or neutral using the
classify_sentimentfunction. - Count the number of headlines in each sentiment category.
- Calculate the percentage of headlines in each sentiment category.
- Output a summary report showing the count and percentage for each sentiment category.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Incrível!
Completion taxa melhorada para 4.76
Challenge: Sentiment Analysis of Headlines
Deslize para mostrar o menu
Sentiment analysis is a powerful tool for editorial teams, allowing you to quickly assess the tone of news content and understand how stories might be perceived by audiences. By systematically scoring headlines or articles as positive, negative, or neutral, you can uncover patterns in coverage, identify potential biases, and inform decisions about story selection or framing. This technique is especially valuable when reviewing large volumes of content, where manual assessment would be impractical.
1234567891011121314151617181920212223242526272829303132333435363738# Predefined lists of positive and negative words positive_words = ["success", "growth", "win", "improve", "benefit", "progress", "record", "boost"] negative_words = ["decline", "loss", "fail", "drop", "crisis", "scandal", "risk", "cut"] # Sample list of news headlines headlines = [ "City sees record growth in tech sector", "Local school faces budget cuts amid crisis", "Community benefits from new park opening", "Economy at risk as markets decline", "Team wins championship after tough season", "Government faces criticism over policy fail", "Residents celebrate progress in recycling efforts" ] def score_sentiment(headline): words = headline.lower().split() score = 0 for word in words: if word in positive_words: score += 1 elif word in negative_words: score -= 1 return score def classify_sentiment(score): if score > 0: return "positive" elif score < 0: return "negative" else: return "neutral" # Analyze each headline for headline in headlines: score = score_sentiment(headline) sentiment = classify_sentiment(score) print(f"'{headline}' => {sentiment} (score: {score})")
When newsroom teams use sentiment analysis, you gain a data-driven perspective on how your headlines and stories might affect public perception. Regularly reviewing sentiment scores can help editors spot trends—such as a tendency toward negative framing or a lack of positive stories—and lead to productive discussions about editorial balance. This process can also provide insights into how coverage aligns with audience expectations and organizational values, ultimately supporting more informed, intentional journalism.
Swipe to start coding
Write a script to analyze the sentiment of a list of news headlines using predefined positive and negative word lists.
- For each headline in the
headlineslist, score the sentiment using thescore_sentimentfunction. - Classify each headline as positive, negative, or neutral using the
classify_sentimentfunction. - Count the number of headlines in each sentiment category.
- Calculate the percentage of headlines in each sentiment category.
- Output a summary report showing the count and percentage for each sentiment category.
Solução
Obrigado pelo seu feedback!
single