Skip to content

Latest commit

ย 

History

4 Commits

Folders and files

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

Repository files navigation

๐ŸŽฏ AI Ethics Radar

A two-stage multi-label text classification system that automatically identifies AI-related news articles and detects ethical concerns using deep learning.

Python 3.11+ License: MIT Flask Ask DeepWiki


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

Image 1 Image 2

Image 3

AI Ethics Radar is an end-to-end NLP system that analyzes news articles to:

  1. Classify main categories (AI, Technology, Business, Politics, Sports, Others)
  2. Detect AI ethics issues across 12 dimensions when AI content is identified

The system uses a two-stage classification pipeline:

  • Stage 1: Multi-label classification across 6 main categories
  • Stage 2: Multi-label detection of 12 AI ethics issues (only for AI-related articles)

๐Ÿ” Problem Statement

As artificial intelligence becomes increasingly prevalent in news media, there's a growing need to:

  • Automatically identify AI-related content
  • Detect potential ethical concerns in AI applications
  • Provide structured insights into AI ethics dimensions

This project addresses these needs by building an automated system that can process news articles and flag ethical considerations across multiple dimensions.


๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Input Article  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Stage 1: Category      โ”‚
โ”‚  Classification         โ”‚
โ”‚  (TF-IDF + LogReg)      โ”‚
โ”‚  6 Categories           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
    Is AI Related?
         โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”
    โ”‚   NO    โ”‚โ”€โ”€โ–บ Return Category Only
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
        YES
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Stage 2: Ethics        โ”‚
โ”‚  Detection              โ”‚
โ”‚  (RoBERTa + ONNX)       โ”‚
โ”‚  12 Ethics Labels       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Output: Category +     โ”‚
โ”‚  Ethics Radar Chart     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“Š Dataset

Data Collection

  • Source: Web scraping using Selenium from major tech news outlets
    • MIT Technology Review
    • Wired
    • The Verge
    • TechCrunch
    • Ars Technica
  • Total Articles: 26,076
  • AI Articles: 20,502 (78.6%)
  • Scraping Period: November 2025

Labeling Strategy

  • Stage 1: Zero-shot classification using BART-large-MNLI
  • Stage 2: Zero-shot multi-label classification for AI ethics
  • Threshold: 0.6 for converting probabilities to binary labels

Ethics Dimensions (12 Labels)

  1. Bias & Fairness - Algorithmic discrimination and fairness concerns
  2. Privacy & Data Misuse - Personal data handling and privacy violations
  3. Job Displacement - Employment and workforce impacts
  4. Misinformation & Deepfakes - False information and synthetic media
  5. Accountability & Liability - Responsibility and legal concerns
  6. Environmental Impact - Energy consumption and carbon footprint
  7. Surveillance & Regulation - Monitoring and government oversight
  8. Safety & Security - Physical and cybersecurity risks
  9. Intellectual Property - Copyright and ownership issues
  10. Lack of Transparency - Opacity in AI decision-making
  11. Algorithmic Manipulation - Behavioral influence and manipulation
  12. No Ethical Issue Detected - Control label

๐Ÿค– Models & Performance

Stage 1: Main Category Classification

Model Test Micro F1 Test Macro F1 Hamming Loss Training Time
TF-IDF + LogReg โญ 0.8168 0.7006 0.1759 0.88 min
DistilBERT 0.8033 0.6854 0.1791 32.77 min
RoBERTa 0.8162 0.6828 0.1766 230.27 min

Winner: TF-IDF + Logistic Regression (Best balance of speed and accuracy)

Stage 2: AI Ethics Detection

Model Test Micro F1 Test Macro F1 Hamming Loss Training Time
TF-IDF + LogReg 0.7857 0.7511 0.1855 0.73 min
DistilBERT 0.7921 0.7325 0.1790 26.64 min
RoBERTa โญ 0.7983 0.7416 0.1719 52.78 min

Winner: RoBERTa (Best overall performance for multi-label ethics detection)

Model Optimization

  • ONNX Conversion: RoBERTa model converted to ONNX format
  • Quantization: INT8 quantization reduced model size by 74.8%
    • Original: 475.83 MB โ†’ Quantized: 119.75 MB
  • Inference Speed: ~2.04 seconds per article on CPU

๐Ÿš€ Installation

Prerequisites

  • Python 3.11+
  • pip
  • CUDA-capable GPU (optional, for faster inference)

Setup

# Clone the repository
git clone https://github.com/yourusername/ai-ethics-radar.git
cd ai-ethics-radar

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Download models (from releases or trained yourself)
# Place in onnx_models/ directory

๐Ÿ’ป Usage

Flask Web Application

# Run the Flask app
python app.py

# Open browser and navigate to
http://localhost:5000

Python API

from app import predict_main_category, predict_ethics

# Analyze an article
article_text = "Your article text here..."

# Stage 1: Get category
category, confidence = predict_main_category(article_text)
print(f"Category: {category} (confidence: {confidence:.2%})")

# Stage 2: Get ethics predictions (if AI-related)
if category == "Artificial Intelligence":
    ethics_results = predict_ethics(article_text)
    for label, prob in ethics_results.items():
        if prob >= 0.5:
            print(f"  โš ๏ธ {label}: {prob:.2%}")

Example Output

Category: Artificial Intelligence (confidence: 92.3%)

AI Ethics Issues Detected:
  โš ๏ธ Bias & Fairness: 78.5%
  โš ๏ธ Privacy & Data Misuse: 65.2%
  โš ๏ธ Lack of Transparency: 82.1%
  โš ๏ธ Accountability & Liability: 71.3%

๐Ÿ“ Project Structure

ai-ethics-radar/
โ”œโ”€โ”€ app.py                          # Flask application
โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”œโ”€โ”€ README.md                       # This file
โ”‚
โ”œโ”€โ”€ data/                           # Datasets
โ”‚   โ”œโ”€โ”€ articles_classified.jsonl  # Labeled articles
โ”‚   โ”œโ”€โ”€ train_stage1.csv           # Training data (Stage 1)
โ”‚   โ”œโ”€โ”€ train_stage2.csv           # Training data (Stage 2)
โ”‚   โ””โ”€โ”€ ...
โ”‚
โ”œโ”€โ”€ src/                            # Source code
โ”‚   โ”œโ”€โ”€ scraper.py                 # Selenium web scraper
โ”‚   โ”œโ”€โ”€ preprocessing.py           # Data preprocessing
โ”‚   โ””โ”€โ”€ dataset_analysis.py        # EDA scripts
โ”‚
โ”œโ”€โ”€ notebooks/                      # Jupyter notebooks
โ”‚   โ”œโ”€โ”€ 01_data_collection.ipynb
โ”‚   โ”œโ”€โ”€ 02_labeling.ipynb
โ”‚   โ”œโ”€โ”€ 03_training_stage1.ipynb
โ”‚   โ”œโ”€โ”€ 04_training_stage2.ipynb
โ”‚   โ””โ”€โ”€ 05_onnx_conversion.ipynb
โ”‚
โ”œโ”€โ”€ models_stage1/                  # Stage 1 trained models
โ”‚   โ”œโ”€โ”€ distilbert-base-uncased/
โ”‚   โ””โ”€โ”€ roberta-base/
โ”‚
โ”œโ”€โ”€ models_stage2/                  # Stage 2 trained models
โ”‚   โ”œโ”€โ”€ distilbert-base-uncased/
โ”‚   โ””โ”€โ”€ roberta-base/
โ”‚
โ”œโ”€โ”€ onnx_models/                    # Optimized ONNX models
โ”‚   โ”œโ”€โ”€ stage1_tfidf/
โ”‚   โ”‚   โ”œโ”€โ”€ model.pkl
โ”‚   โ”‚   โ”œโ”€โ”€ vectorizer.pkl
โ”‚   โ”‚   โ””โ”€โ”€ labels.json
โ”‚   โ”œโ”€โ”€ stage2_best_model_quantized.onnx
โ”‚   โ””โ”€โ”€ stage2_best_model_tokenizer/
โ”‚
โ”œโ”€โ”€ templates/                      # HTML templates
โ”‚   โ””โ”€โ”€ index.html                 # Main web interface
โ”‚
โ””โ”€โ”€ results/                        # Training results & visualizations
    โ”œโ”€โ”€ stage1_model_comparison.png
    โ”œโ”€โ”€ stage2_model_comparison.png
    โ””โ”€โ”€ *.json                     # Results metadata

๐Ÿ“ˆ Results & Analysis

Stage 1: Category Distribution

Stage 1 Distribution

  • Most Common: Artificial Intelligence (78.6%), Technology (85.9%)
  • Least Common: Sports (17.6%), Politics (21.7%)
  • Challenge: Severe class imbalance addressed with class_weight='balanced'

Stage 2: Ethics Issues Distribution

Stage 2 Distribution

Top 5 Most Detected Issues:

  1. Lack of Transparency (56.4%)
  2. Accountability & Liability (55.9%)
  3. Algorithmic Manipulation (51.1%)
  4. Privacy & Data Misuse (47.0%)
  5. Bias & Fairness (44.2%)

Key Insights:

  • 80.8% of AI articles have at least one ethical concern
  • Average of 5.2 ethics labels per AI article
  • Only 19.2% flagged as "No Ethical Issue Detected"

Model Comparison

Model Comparison

Key Findings:

  • TF-IDF surprisingly competitive despite simplicity
  • RoBERTa best for nuanced multi-label classification
  • ONNX quantization maintains 98%+ accuracy with 4x smaller size

๐ŸŒ Deployment

Local Development

python app.py
# Access at http://localhost:5000

Render Deployment

# Create Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]

# Push to GitHub and connect to Render
# Render will automatically build and deploy

Hugging Face Spaces (Coming Soon)

  • Gradio-based demo interface
  • Simplified deployment without server management

๐Ÿ”ฎ Future Work

Short-term Improvements

  • Add per-class F1 scores and confusion matrices
  • Implement batch processing for multiple articles
  • Add confidence calibration for probability outputs
  • Create API documentation with Swagger/OpenAPI

Long-term Enhancements

  • Real-time scraping and continuous learning pipeline
  • Expand to 20+ ethics dimensions
  • Multi-language support (Spanish, French, German, etc.)
  • Fine-grained entity extraction (companies, people, technologies)
  • Temporal analysis of ethics trends over time
  • Integration with news APIs for automated monitoring

Research Extensions

  • Explainability: LIME/SHAP analysis for predictions
  • Active learning for efficient labeling
  • Cross-domain transfer learning (social media, research papers)
  • Benchmark against human expert annotations

๐Ÿ‘ฅ Contributors

Sourav Das

  • NLP Project
  • December 2024

Acknowledgments

  • HuggingFace for transformer models
  • Tech news outlets for article sources

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ“š Citation

If you use this project in your research or work, please cite:

@software{ai_ethics_radar_2024,
  author = {Das, Sourav},
  title = {AI Ethics Radar: Automated Detection of Ethical Issues in AI News},
  year = {2024},
  url = {https://github.com/yourusername/ai-ethics-radar}
}

Development Setup

# Fork the repo and clone your fork
git clone https://github.com/yourusername/ai-ethics-radar.git

# Create a feature branch
git checkout -b feature/amazing-feature

# Make your changes and commit
git commit -m 'Add amazing feature'

# Push and create a pull request
git push origin feature/amazing-feature

About

A two-stage deep learning pipeline that automatically classifies news articles into 6 categories and detects 12 AI ethics issues using TF-IDF, RoBERTa, and ONNX optimization. Achieves 81.7% F1-score on category classification and 79.8% on multi-label ethics detection across 26K+ articles. All the data is scraped from different portals.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages