DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently discovered a striking anomaly: a 24h momentum spike of -0.796 in defence sentiment. This isn't just another number; it indicates a significant shift in the narrative surrounding defence, particularly in the context of the ongoing conflict in Ukraine. When we see a momentum drop like this, it’s a call to action for any sentiment analysis pipeline. The leading language for this spike is English, lagging behind Portuguese by 28.7 hours. If your model isn’t equipped to handle multilingual origin or entity dominance, you might be missing essential insights.

English coverage led by 28.7 hours. Portuguese at T+28.7h. C
English coverage led by 28.7 hours. Portuguese at T+28.7h. Confidence scores: English 0.85, Spanish 0.85, French 0.85 Source: Pulsebit /sentiment_by_lang.

What does this mean for you? Your model missed this critical spike by 28.7 hours, leaving you blind to emerging discussions that are already gaining traction in the English-speaking media. The dominant entities here are clear: Ukraine and the war with Russia. If your pipeline isn’t capable of recognizing and adapting to these nuances, you risk operating with outdated information that can lead to poor decision-making.

Let’s dive into the code that can help you catch this anomaly. We’ll be using our API to filter by geographic origin and analyze the sentiment narrative for the clustered themes.

import requests

# Step 1: Geographic origin filter
url = "https://api.pulsebit.com/sentiment"
params = {
    "topic": "defence",
    "score": -0.158,
    "confidence": 0.85,
    "momentum": -0.796,
    "lang": "en"  # Filter by English
}

response = requests.get(url, params=params)
data = response.json()

# Check the response
print(data)
Enter fullscreen mode Exit fullscreen mode

This API call filters the sentiment analysis specifically for the defence topic in English, giving us a focused view of the narrative surrounding it.

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

Next, we’ll run the cluster reason string back through our sentiment analysis endpoint for a deeper understanding of the narrative framing itself.

# Step 2: Meta-sentiment moment
meta_sentiment_url = "https://api.pulsebit.com/sentiment"
cluster_reason = "Clustered by shared themes: ukraine, russia’s, war, support, patriot."

meta_params = {
    "text": cluster_reason
}

meta_response = requests.post(meta_sentiment_url, json=meta_params)
meta_data = meta_response.json()

# Output the meta sentiment analysis
print(meta_data)
Enter fullscreen mode Exit fullscreen mode

By running the clustered themes through our sentiment analysis, we can get a clearer picture of how these narratives are being framed, which can help you adjust your strategy accordingly.

So, what can you build with this newfound information? Here are three actionable ideas to implement tonight:

  1. Geographic Filter Analysis: Use the geographic origin filter mentioned above to catch emerging narratives in English before they hit the mainstream. Monitor spikes like this one with a threshold of -0.75 for immediate alerts.

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

  1. Meta-Sentiment Loop: Implement a routine that runs the meta-sentiment analysis on clustered themes at regular intervals. Set a threshold for negative sentiment scores (e.g., less than -0.2) to trigger deeper investigations into the narratives.

  2. Forming Themes Dashboard: Create a dashboard that visualizes forming themes, such as defence, Trump, and budget topics, against mainstream narratives like Ukraine and the war with Russia. Use our API to fetch and display this data in real-time, so you can stay ahead of the curve.

To get started, visit our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run the above code in under 10 minutes, bringing your sentiment analysis capabilities up to speed. Don't let your pipeline fall behind!

Top comments (0)