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.
Given a user statement such as:
"Clean energy growth is benefiting the world."
The system:
- Analyzes the sentiment of the statement.
- Searches a collection of news headlines.
- Identifies headlines with opposing sentiment.
- Ranks them based on textual similarity.
- Returns the most relevant contrarian viewpoints.
- 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
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
- Python
- FastAPI
- Scikit-learn
- Logistic Regression
- TF-IDF Vectorizer
- TextBlob
- Pandas
- NumPy
- HTML
- CSS
- JavaScript
- NewsAPI
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.
News headlines are collected using NewsAPI.
Text is cleaned by:
- Lowercasing
- Removing punctuation
- Removing unnecessary whitespace
A Logistic Regression model classifies text into:
- Positive
- Negative
- Neutral
TF-IDF vectors are generated for all headlines.
Cosine similarity is used to identify headlines discussing similar topics.
Articles with opposing sentiment are selected and ranked according to similarity.
- 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.
- 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.
Clone the repository:
git clone <repository-url>
cd news-contrarianInstall dependencies:
pip install -r requirements.txtRun the FastAPI server:
uvicorn main:app --reloadOpen:
http://127.0.0.1:8000/docs
Currently under active development.
The focus is on improving stance detection, contextual understanding, and contrarian article ranking to produce more meaningful opposing viewpoints.
This project is available for educational and research purposes.