DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 16.3h Behind: Catching Human Rights Sentiment Leads with Pulsebit

Your Pipeline Is 16.3h Behind: Catching Human Rights Sentiment Leads with Pulsebit

We recently uncovered a compelling anomaly: a 24-hour momentum spike of -1.243 around the topic of human rights. This negative momentum indicates a notable shift in sentiment, leading to a cluster of articles focused on the FIFA World Cup being held amid a "human rights crisis" in the US, as reported by Al Jazeera. With 16.3 hours of lead time in English press coverage, this spike reveals just how quickly sentiment can shift, and how crucial it is for us to stay on top of these developments.

The Problem

Your model missed this by 16.3 hours. This significant lead time underscores a structural gap in any pipeline that doesn't effectively account for multilingual origins or dominant entities. In this case, English-language articles were driving the narrative, and if your approach relies solely on a single language or fails to recognize the dominant entities, you're left behind. The implications are clear: failing to capture this sentiment shift could mean missing out on critical insights and opportunities for timely decision-making.

English coverage led by 16.3 hours. Af at T+16.3h. Confidenc
English coverage led by 16.3 hours. Af at T+16.3h. Confidence scores: English 0.85, Spanish 0.85, French 0.85 Source: Pulsebit /sentiment_by_lang.

The Code

Here’s how we can catch this anomaly using our API. First, we'll filter by language to focus on English articles. Then, we'll run the cluster reason string through the sentiment scoring endpoint to assess the narrative's framing.

import requests

# Step 1: Geographic origin filter
response = requests.get(
    'https://api.pulsebit.com/v1/sentiment',
    params={
        'topic': 'human rights',
        'lang': 'en',
        'momentum': -1.243
    }
)

![Geographic detection output for human rights. France leads w](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1774928363707.png)
*Geographic detection output for human rights. France leads with 1 articles and sentiment -0.75. Source: Pulsebit /news_recent geographic fields.*


data = response.json()
print(data)

# Step 2: Meta-sentiment moment
cluster_reason = "Clustered by shared themes: least, dead, haiti, massacre, human."
meta_sentiment_response = requests.post(
    'https://api.pulsebit.com/v1/sentiment',
    json={'text': cluster_reason}
)

meta_sentiment_data = meta_sentiment_response.json()
print(meta_sentiment_data)
Enter fullscreen mode Exit fullscreen mode

In this code, the first API call filters sentiment data specifically for English articles about human rights, identifying the negative momentum we observed. The second call processes the cluster reason, giving us insight into how the narrative is framed around the concepts of "least," "dead," "Haiti," and "human." This is where our analysis gets its depth, allowing us to understand not just the surface-level sentiment but the underlying themes driving it.

Left: Python GET /news_semantic call for 'human rights'. Rig
Left: Python GET /news_semantic call for 'human rights'. Right: returned JSON response structure (clusters: 3). Source: Pulsebit /news_semantic.

Three Builds Tonight

Here are three specific builds we can implement based on this pattern:

  1. Signal Detection: Set up a signal that triggers an alert when the sentiment score for "human rights" drops below -0.5 with a momentum threshold of -1.243. This ensures you’re alerted to significant downward shifts in sentiment.

  2. Geo-Filtered Analysis: Create a dashboard that visualizes sentiment trends for "human rights" across different geographic locations, specifically filtering for English-language content. This way, you can spot regional variations in sentiment early.

  3. Meta-Sentiment Loop: Implement a system that automatically fetches cluster reasons for articles with significant sentiment shifts and runs them through the sentiment endpoint. This will help you continuously refine your understanding of the narrative around specific topics like human rights, especially as new stories emerge and old ones fade.

Get Started

Ready to dive in? Check out our documentation for guidance. With just a few lines of code, you can start capturing insights like these in under 10 minutes.

Top comments (0)