Summary
Add a sentiment analysis step to classify each normalized article as positive/neutral/negative.
Motivation
- Enables tracking of sentiment trends for entities and topics over time.
- Supports alerting on sudden sentiment shifts (e.g. negative spikes).
Scope
In scope: implementation, tests
Acceptance Criteria
Additional Context
- Add dependencies
- Add
transformers and torch to /nlp/requirements.txt.
- Core function signature
- In
/nlp/core.py define:
def analyze_sentiment(text: str) -> dict
- Celery task hook
- In
/nlp/tasks.py register:
@app.task
def sentiment_task(article_id: str) -> dict
- CLI entrypoint
- In
/nlp/cli.py expose:
python -m nlp.cli sentiment --article-id=<id>
- Tests & docs
- Create
/nlp/tests/test_sentiment.py to:
- Assert
analyze_sentiment() returns a dict with label and score.
- Assert
sentiment_task() updates the article document with a "sentiment" field.
- Update
/nlp/README.md with:
- How to run
sentiment_task via Celery
- CLI usage for the
sentiment command
Summary
Add a sentiment analysis step to classify each normalized article as positive/neutral/negative.
Motivation
Scope
In scope: implementation, tests
Acceptance Criteria
analyze_sentiment(text)returns a non-emptylabeland numericscore.sentiment_task(article_id)stores a"sentiment"field on the article.Additional Context
transformersandtorchto/nlp/requirements.txt./nlp/core.pydefine:/nlp/tasks.pyregister:/nlp/cli.pyexpose:/nlp/tests/test_sentiment.pyto:analyze_sentiment()returns a dict withlabelandscore.sentiment_task()updates the article document with a"sentiment"field./nlp/README.mdwith:sentiment_taskvia Celerysentimentcommand