← Back to list

News Sentiment Analysis Using 4 NLP Models

This project collects data using API from NewsAPI. The goal is to compare sentiment outputs from different models. From the data, I only…

Code + Chaos · 2025-10-10 17:04 · 0 claps · 1.6 min read
#nlp #machine-learning #transformers #huggingfacemodels #python-matplotlib
Open on Medium ↗
Wiki topics: ML · Machine Learning EDU · Education & Learning

News Sentiment Analysis Using 4 NLP Models

This project collects data using API from NewsAPI. The goal is to compare sentiment outputs from different models. From the data, I only use the title and description of the articles for the models. These models return a label and score for the sentiments. Later, I plot the result to show the comparison.

The models used for this project:

  • TextBlob
  • VADER
  • DistilBERT (SST-2 finetuned)
  • RoBERTa (JHartmann Emotion Model)

The whole code is on my GitHub -> here

Technologies used for this project:

  • Python, Pandas
  • Matplotlib, Seaborn
  • Hugging Face Transformers
  • TextBlob, VADER
  • Google Colab/ VS Code

These are the results of each model:

After getting the scores and labels of sentiments from the models, I created a dataframe with only these columns, ‘date’, ‘source’, ‘blob_label’, ‘blob_score’, ‘vader_label’, ‘vader_score’, ‘distilbert_label’, ‘distilbert_score’, ‘roberta_label’, ‘roberta_score’. I dropped other columns from the articles as those were unnecessary. Creating this dataframe made it easier to plot the result.

I changed the publishedAt column from the articles into date like this:

date = article.get('publishedAt', '')
date = datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ')
date = date.strftime('%Y-%m-%d')
article['date'] = date

TextBlob and VADER only returns scores and based on these scores I determined the labels. However, RoBERTa and DistilBERT return labels and scores. Raw texts were used for all four of these models to see how they perform.

I used one content at a time for TextBlob and VADER models because they can process contents one at a time but RoBERTa and DistilBERT make the program slow. That’s why I used the contents in a batch for these two models.

It was a fun project to see how different NLP model works on the same data. This project can be further improved into real time sentiment analysis and deployed as Streamlit or Gradio app. I hope to implement this idea some day soon.

Happy Learning!


메타데이터
post_id
ee7bfd84f094
slug
news-sentiment-analysis-using-4-nlp-models-ee7bfd84f094
url
https://medium.com/@munfa2020/news-sentiment-analysis-using-4-nlp-models-ee7bfd84f094
canonical_url
https://medium.com/@munfa2020/news-sentiment-analysis-using-4-nlp-models-ee7bfd84f094
author_url
https://medium.com/@munfa2020
status
ok
fetched_at
2026-08-07 23:12:46