Skip to content

Latest commit

ย 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NewsLens ๐Ÿ”Ž

AI-Powered News Perspective Analyzer

NewsLens is a web application that helps users explore how different news sources present the same topic.

The application retrieves relevant news articles, extracts their content, generates concise summaries, and uses a fine-tuned RoBERTa model to classify the political perspective of each article as Left, Center, or Right.

The goal is not to determine whether an article is true or false, but to help users compare different perspectives on the same topic.


โœจ Features

  • ๐Ÿ”Ž Search for news topics

  • ๐Ÿ“ฐ Retrieve articles from multiple news sources

  • โœ‚๏ธ Generate concise article summaries using BART

  • ๐Ÿง  Predict political perspective using a fine-tuned RoBERTa model

  • โš–๏ธ Classify articles as:

    • Left
    • Center
    • Right
  • ๐Ÿ“Š Group articles by political perspective

  • ๐ŸŒ React-based user interface

  • โšก FastAPI backend for AI inference and news processing


๐Ÿ—๏ธ System Architecture

                    User
                     โ”‚
                     โ–ผ
              React Frontend
                     โ”‚
                     โ”‚ HTTP Request
                     โ–ผ
              FastAPI Backend
                     โ”‚
                     โ–ผ
                 NewsAPI
                     โ”‚
                     โ–ผ
             Article Extraction
                     โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ–ผ             โ–ผ
        BART Summarizer   RoBERTa
              โ”‚             โ”‚
              โ–ผ             โ–ผ
           Summary      Bias Prediction
                            โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ–ผ       โ–ผ       โ–ผ
                  Left    Center   Right
                    โ”‚       โ”‚       โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ–ผ
                     React Frontend

๐Ÿค– AI Pipeline

1. Article Retrieval

The user enters a search query through the React frontend.

The backend sends the query to NewsAPI and retrieves relevant article metadata and URLs.

2. Article Extraction

The backend extracts the full text from the returned article URLs.

3. Summarization

The extracted article text is passed to BART (facebook/bart-large-cnn).

BART generates a shorter summary containing the main information from the article.

4. Tokenization

Before text is processed by the transformer models, it is converted into tokens using Hugging Face tokenizers.

Raw Text
   โ†“
Tokenizer
   โ†“
Token IDs
   โ†“
Transformer Model
   โ†“
Prediction / Summary

5. Political Perspective Classification

The article text is passed to our fine-tuned RoBERTa classification model.

The model predicts one of three categories:

Left
Center
Right

The predicted category is then returned to the frontend.


๐Ÿง  Models Used

Model Purpose
BART Abstractive news summarization
RoBERTa Political perspective classification

BART

facebook/bart-large-cnn is used to generate concise summaries of retrieved news articles.

RoBERTa

A RoBERTa-based sequence classification model was fine-tuned using a labeled news-bias dataset to classify articles into Left, Center, and Right political perspectives.


๐Ÿ“Š Dataset

The political perspective classifier was trained using the following dataset:

News Bias Detection Dataset

Hugging Face Dataset

The dataset contains political perspective categories including:

  • Political Left
  • Political Center
  • Political Right

The dataset provides training, validation, and test splits.


๐Ÿ“ˆ Model Performance

The trained RoBERTa model achieved the following validation results:

Metric Score
Accuracy 86.60%
Precision 86.68%
Recall 86.60%
F1 Score 86.60%

๐Ÿ› ๏ธ Tech Stack

Frontend

  • React
  • TypeScript
  • Tailwind CSS
  • Axios
  • Vite

Backend

  • Python
  • FastAPI
  • Uvicorn
  • Requests
  • NewsAPI

Machine Learning

  • PyTorch
  • Hugging Face Transformers
  • RoBERTa
  • BART
  • Hugging Face Tokenizers

Development

  • Google Colab
  • Git
  • GitHub
  • VS Code

๐Ÿ“ Project Structure

AI-News-Perspective-Analyzer/
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ””โ”€โ”€ search.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ article_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ inference_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ news_service.py
โ”‚   โ”‚   โ””โ”€โ”€ summary_service.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ app.py
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ””โ”€โ”€ types/
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

Trained model weights are excluded from the Git repository because of their large file size.


๐Ÿš€ Running the Project

1. Clone the repository

git clone <repository-url>
cd AI-News-Perspective-Analyzer

2. Backend Setup

Create a Python virtual environment:

python -m venv venv

Activate it on Windows:

venv\Scripts\activate

Install dependencies:

pip install -r backend/requirements.txt

Create a .env file inside the backend:

NEWS_API_KEY=your_newsapi_key

Start the FastAPI server:

uvicorn app:app --reload

The backend will run at:

http://127.0.0.1:8000

FastAPI documentation will be available at:

http://127.0.0.1:8000/docs

3. Frontend Setup

Navigate to the frontend:

cd frontend

Install dependencies:

npm install

Start the development server:

npm run dev

The frontend will normally be available at:

http://localhost:5173

๐Ÿ” Environment Variables

The project requires API credentials that should not be committed to Git.

Example:

NEWS_API_KEY=your_api_key

Add .env to .gitignore.


โš ๏ธ Limitations

  • Political perspective classification is a model prediction and should not be treated as an objective fact.
  • Classification performance depends on the quality and distribution of the training data.
  • Article extraction may fail for websites that restrict automated access.
  • Summarization quality can vary depending on article structure and length.
  • The current system primarily supports English-language news content.

๐Ÿ”ฎ Future Improvements

  • Improve classification accuracy with larger and more diverse datasets
  • Add multilingual news analysis
  • Add more news sources and APIs
  • Provide confidence visualization for predictions
  • Improve long-article summarization using chunking
  • Deploy the complete application online
  • Add article-to-article comparison
  • Provide additional transparency about model predictions

๐Ÿ‘จโ€๐Ÿ’ป Authors

Ganesh Karthik B.Tech Computer Science Engineering IIITDM Jabalpur

GitHub: ganeshkarthik016


๐Ÿ“„ License

This project is licensed under the MIT License.

See LICENSE for details.


โš–๏ธ Disclaimer

NewsLens is an educational and research-oriented project.

The political perspective labels are AI-generated predictions based on patterns learned from the training data. They do not represent an absolute judgment of an article's political ideology, factual accuracy, or credibility.

Users should consult the original articles and multiple reliable sources when evaluating news.


Built for learning, experimentation, and better news comparison.

About

AI-powered news analysis platform that summarizes articles and classifies their political perspective as Left, Center, or Right.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages