A focused NLP tool that takes one article URL, parses the article text, and determines whether the writing appears biased or balanced.
- Extracts article text from a URL using
newspaper3k. - Cleans text (whitespace, links, noisy characters).
- Computes sentiment (
VADER+TextBlob). - Uses an unsupervised clustering method (2-cluster k-means over sentence-level linguistic features) to estimate bias.
No hardcoded left/right keyword lists are used.
- The article is split into sentences.
- Each sentence is converted into features:
- polarity
- subjectivity
- normalized sentence length
- Sentences are grouped with 2-cluster k-means.
- A bias score is derived from:
- polarization gap between cluster polarities
- one-sidedness (whether non-neutral sentences lean mostly in one direction)
- Labels:
Likely BiasedPotential BiasLikely BalancedInsufficient Evidence(for very short texts)
pip install -r requirements.txtpython pipeline.py "https://example.com/news/article"Optional output path:
python pipeline.py "https://example.com/news/article" --output article_analysis.jsonA JSON file containing:
urltitlepublished_atcleaned_textsentiment_compoundsentiment_labelsubjectivitybias_scorebias_labelextracted_at
pytest -q