Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Analyzing Media Bias and Sentiment | Automation and Content Analysis in the Newsroom
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

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 6

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookAnalyzing Media Bias and Sentiment

Deslize para mostrar o 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

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 6
some-alt