Skip to content

Integrate sentiment analysis pipeline #32

@justinmadison

Description

@justinmadison

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

  • analyze_sentiment(text) returns a non-empty label and numeric score.
  • sentiment_task(article_id) stores a "sentiment" field on the article.
  • CLI command runs without errors and prints the sentiment result.
  • All tests pass in CI and README clearly documents both execution paths.

Additional Context

  1. Add dependencies
    • Add transformers and torch to /nlp/requirements.txt.
  2. Core function signature
    • In /nlp/core.py define:
      def analyze_sentiment(text: str) -> dict
      
  3. Celery task hook
    • In /nlp/tasks.py register:
      @app.task
      def sentiment_task(article_id: str) -> dict
      
  4. CLI entrypoint
    • In /nlp/cli.py expose:
      python -m nlp.cli sentiment --article-id=<id>
      
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions