Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Analyzing Media Bias and Sentiment | Automation and Content Analysis in the Newsroom
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Journalists and Media

bookAnalyzing Media Bias and Sentiment

Understanding how language shapes public perception is crucial in journalism. Sentiment analysis and bias detection are two important tools that help journalists and readers evaluate the tone and objectivity of news articles. Sentiment analysis aims to determine whether a piece of text expresses a positive, negative, or neutral attitude. Bias detection goes a step further by identifying whether reporting might favor one viewpoint over another. These methods support media literacy by helping you spot patterns that could influence how stories are told and received.

123456789101112131415161718192021222324252627
# Simple sentiment analysis for news headlines using word lists positive_words = {"progress", "success", "improve", "growth", "win", "benefit"} negative_words = {"crisis", "fail", "decline", "loss", "problem", "threat"} headlines = [ "Economy shows signs of growth amid recovery", "Political crisis threatens regional stability", "Local school wins national award for improvement", "Unemployment rates decline after new policies", "Budget cuts pose threat to public services", "City celebrates success of community project" ] def score_sentiment(headline): words = set(headline.lower().split()) if words & positive_words: return "positive" elif words & negative_words: return "negative" else: return "neutral" sentiment_scores = [score_sentiment(h) for h in headlines] for h, s in zip(headlines, sentiment_scores): print(f'"{h}" => {s}')
copy

This approach uses simple lists of positive and negative words to classify the sentiment of each headline. While this method is easy to implement and can reveal general trends, it has clear limitations. Headlines often contain nuance, sarcasm, or context that basic word lists cannot detect. For instance, a headline might use a positive word in a negative context, or vice versa. Additionally, this method does not account for the overall structure or intent of the article. However, even basic sentiment analysis can provide a quick overview of tone across many headlines, which can be useful for initial content analysis or as a starting point for deeper investigation.

1234567891011
# Calculate the proportion of positive, negative, and neutral headlines from collections import Counter counts = Counter(sentiment_scores) total = len(sentiment_scores) proportions = {sentiment: count / total for sentiment, count in counts.items()} for sentiment, prop in proportions.items(): print(f"{sentiment.capitalize()} headlines: {prop:.2%}")
copy

1. What is sentiment analysis?

2. Why is it important to analyze media bias?

3. Fill in the blank: To calculate the proportion of items in a category, use _ _ _.

question mark

What is sentiment analysis?

Select the correct answer

question mark

Why is it important to analyze media bias?

Select the correct answer

question-icon

Fill in the blank: To calculate the proportion of items in a category, use _ _ _.

additionsubtractionmultiplication

Click or drag`n`drop items and fill in the blanks

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 6

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

bookAnalyzing Media Bias and Sentiment

Scorri per mostrare il menu

Understanding how language shapes public perception is crucial in journalism. Sentiment analysis and bias detection are two important tools that help journalists and readers evaluate the tone and objectivity of news articles. Sentiment analysis aims to determine whether a piece of text expresses a positive, negative, or neutral attitude. Bias detection goes a step further by identifying whether reporting might favor one viewpoint over another. These methods support media literacy by helping you spot patterns that could influence how stories are told and received.

123456789101112131415161718192021222324252627
# Simple sentiment analysis for news headlines using word lists positive_words = {"progress", "success", "improve", "growth", "win", "benefit"} negative_words = {"crisis", "fail", "decline", "loss", "problem", "threat"} headlines = [ "Economy shows signs of growth amid recovery", "Political crisis threatens regional stability", "Local school wins national award for improvement", "Unemployment rates decline after new policies", "Budget cuts pose threat to public services", "City celebrates success of community project" ] def score_sentiment(headline): words = set(headline.lower().split()) if words & positive_words: return "positive" elif words & negative_words: return "negative" else: return "neutral" sentiment_scores = [score_sentiment(h) for h in headlines] for h, s in zip(headlines, sentiment_scores): print(f'"{h}" => {s}')
copy

This approach uses simple lists of positive and negative words to classify the sentiment of each headline. While this method is easy to implement and can reveal general trends, it has clear limitations. Headlines often contain nuance, sarcasm, or context that basic word lists cannot detect. For instance, a headline might use a positive word in a negative context, or vice versa. Additionally, this method does not account for the overall structure or intent of the article. However, even basic sentiment analysis can provide a quick overview of tone across many headlines, which can be useful for initial content analysis or as a starting point for deeper investigation.

1234567891011
# Calculate the proportion of positive, negative, and neutral headlines from collections import Counter counts = Counter(sentiment_scores) total = len(sentiment_scores) proportions = {sentiment: count / total for sentiment, count in counts.items()} for sentiment, prop in proportions.items(): print(f"{sentiment.capitalize()} headlines: {prop:.2%}")
copy

1. What is sentiment analysis?

2. Why is it important to analyze media bias?

3. Fill in the blank: To calculate the proportion of items in a category, use _ _ _.

question mark

What is sentiment analysis?

Select the correct answer

question mark

Why is it important to analyze media bias?

Select the correct answer

question-icon

Fill in the blank: To calculate the proportion of items in a category, use _ _ _.

additionsubtractionmultiplication

Click or drag`n`drop items and fill in the blanks

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 6
some-alt