Skip to content

Repository files navigation

News Contrarian

News Contrarian is a machine learning and NLP-powered application that helps users discover viewpoints that challenge their own.

Instead of recommending articles that reinforce existing beliefs, the system retrieves news headlines expressing opposing perspectives on the same topic. The goal is to encourage critical thinking and reduce information bubbles by exposing users to alternative viewpoints.


Overview

Given a user statement such as:

"Clean energy growth is benefiting the world."

The system:

  1. Analyzes the sentiment of the statement.
  2. Searches a collection of news headlines.
  3. Identifies headlines with opposing sentiment.
  4. Ranks them based on textual similarity.
  5. Returns the most relevant contrarian viewpoints.

Features

  • Live news retrieval using NewsAPI
  • Text preprocessing and normalization
  • Sentiment classification using Logistic Regression
  • TF-IDF vectorization for text representation
  • Cosine similarity-based article matching
  • Contrarian article recommendation engine
  • FastAPI backend
  • Interactive web interface

System Architecture

User Input
     |
     v
Text Cleaning
     |
     v
Sentiment Classification
(Logistic Regression)
     |
     v
TF-IDF Vectorization
     |
     v
Cosine Similarity Matching
     |
     v
Contrarian Article Retrieval
     |
     v
Results Display

Technologies Used

Backend

  • Python
  • FastAPI

Machine Learning & NLP

  • Scikit-learn
  • Logistic Regression
  • TF-IDF Vectorizer
  • TextBlob

Data Processing

  • Pandas
  • NumPy

Frontend

  • HTML
  • CSS
  • JavaScript

News Source

  • NewsAPI

NLP Techniques Used

This project uses several classical Natural Language Processing techniques:

  • Text Cleaning
  • Tokenization
  • Sentiment Analysis
  • TF-IDF Vectorization
  • Cosine Similarity Matching
  • Keyword-Based Feature Extraction

The current version focuses on sentiment-aware retrieval rather than full stance detection.


How It Works

Step 1: Fetch News

News headlines are collected using NewsAPI.

Step 2: Preprocess Text

Text is cleaned by:

  • Lowercasing
  • Removing punctuation
  • Removing unnecessary whitespace

Step 3: Sentiment Classification

A Logistic Regression model classifies text into:

  • Positive
  • Negative
  • Neutral

Step 4: Similarity Matching

TF-IDF vectors are generated for all headlines.

Cosine similarity is used to identify headlines discussing similar topics.

Step 5: Contrarian Retrieval

Articles with opposing sentiment are selected and ranked according to similarity.


Current Limitations

  • Uses sentiment as a proxy for viewpoint.
  • Headlines are analyzed instead of full article content.
  • TF-IDF is based on bag-of-words representation and has limited contextual understanding.
  • Negation, sarcasm, and complex linguistic structures are not always handled correctly.
  • Similar sentiment does not always imply the same stance.

Future Improvements

  • Train on stance-detection datasets.
  • Analyze full article content instead of only headlines.
  • Implement contextual embeddings using BERT or RoBERTa.
  • Improve ranking with semantic similarity models.
  • Expand support for multiple news categories.
  • Introduce confidence scoring and explainable recommendations.

Installation

Clone the repository:

git clone <repository-url>
cd news-contrarian

Install dependencies:

pip install -r requirements.txt

Run the FastAPI server:

uvicorn main:app --reload

Open:

http://127.0.0.1:8000/docs

Project Status

Currently under active development.

The focus is on improving stance detection, contextual understanding, and contrarian article ranking to produce more meaningful opposing viewpoints.


License

This project is available for educational and research purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages