DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 29.2h Behind: Catching Defence Sentiment Leads with Pulsebit

A 24h momentum spike of +0.390 caught our attention recently, particularly in the context of discussions surrounding "defence." This anomaly aligns with a notable article cluster, "Ayush Shetty storms into Badminton Asia Championships final," which seems to have pulled the narrative focus towards sports while our sentiment signal is rooted in serious themes about global defence. This juxtaposition raises some intriguing questions about how we track sentiment across different domains and languages.

Your model missed this by 29.2 hours. The leading language in this narrative is English, but the dominant sentiment on the topic of defence seems to be rising, driven by a relatively small number of articles. When your pipeline doesn't account for multilingual origins or entity dominance, you risk overlooking critical developments. In this case, while the sports story is buzzing, the underlying sentiment in defence is evolving, and you’re lagging behind in detecting that shift.

English coverage led by 29.2 hours. Tl at T+29.2h. Confidenc
English coverage led by 29.2 hours. Tl at T+29.2h. Confidence scores: English 0.95, Spanish 0.95, French 0.95 Source: Pulsebit /sentiment_by_lang.

To catch this anomaly, let's dive into the code. We can use our API to filter articles by language and assess how the narrative is framing the sentiment. Here’s how you can get started:

import requests

# Define the parameters for the API call to filter by English language
api_url = "https://pulsebit.lojenterprise.com/sentiment"
params = {
    "topic": "defence",
    "score": +0.267,
    "confidence": 0.95,
    "momentum": +0.390,
    "lang": "en"
}

![Left: Python GET /news_semantic call for 'defence'. Right: r](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_code_output_split_1775918462717.png)
*Left: Python GET /news_semantic call for 'defence'. Right: returned JSON response structure (clusters: 3). Source: Pulsebit /news_semantic.*


# Make the GET request
response = requests.get(api_url, params=params)
data = response.json()
print(data)
Enter fullscreen mode Exit fullscreen mode

To understand the narrative framing itself, we need to run the cluster reason string back through the sentiment analysis. This will allow us to score how the themes are being portrayed:

# Define the cluster reason string for meta-sentiment scoring
cluster_reason = "Clustered by shared themes: world, ayush, shetty, storms, into."

# Make a POST request to analyze the sentiment of the narrative framing
response_meta = requests.post(api_url, json={"text": cluster_reason})
meta_sentiment_data = response_meta.json()
print(meta_sentiment_data)
Enter fullscreen mode Exit fullscreen mode

Now that we have the mechanics down, here are three specific builds we can implement using this pattern:

  1. Geographic Origin Filter: Create a function that not only checks for sentiment spikes around the topic of defence but also filters results by geographical origins. Set a threshold for momentum, say +0.300, and alert when it appears in English articles. This can help you catch regional sentiments early.

Geographic detection output for defence. India leads with 10
Geographic detection output for defence. India leads with 10 articles and sentiment +0.45. Source: Pulsebit /news_recent geographic fields.

  1. Meta-Sentiment Loop: Develop an alert system that triggers when the cluster reason indicates a shift in sentiment, such as "forming: defence(+0.00)." Use the meta-sentiment analysis to identify changes in framing, scoring anything above a +0.200 as noteworthy.

  2. Cross-Topic Analysis: Build a comparison tool that juxtaposes sentiment around defence with trending sports stories. Set a flag for when the sentiment score on defence rises while the sports narrative dominates, allowing you to visualize potential overlaps or conflicts in public sentiment.

If you want to get started, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste the code snippets above and run them in under 10 minutes. This approach not only enhances your pipeline but also ensures you stay ahead of significant shifts in sentiment, whether they arise from sports or serious geopolitical discussions.

Top comments (0)