DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently uncovered an intriguing anomaly: a 24-hour momentum spike of +0.518 surrounding the topic of defence. This data point revealed a significant shift in sentiment, particularly in the context of recent events, like France's ban on Israeli weapons at a defence show. With two articles clustering around this event, it’s clear that the narrative is evolving rapidly. If your sentiment analysis pipeline isn't tuned to detect these changes in real-time, you could be missing out on critical insights.

The Problem

Your model missed this by 18.2 hours. This structural gap highlights the importance of handling multilingual origins and entity dominance effectively. In this case, English-language press articles led the charge, but if your pipeline only processes data in one language or fails to recognize emerging entities, you risk operating in the dark. For instance, the sentiment surrounding "defence" is significantly underrepresented compared to other mainstream narratives like "sexual," "violence," and "landmark." This disconnect can leave your analyses stale and less actionable.

English coverage led by 18.2 hours. No at T+18.2h. Confidenc
English coverage led by 18.2 hours. No at T+18.2h. Confidence scores: English 0.90, French 0.90, Spanish 0.90 Source: Pulsebit /sentiment_by_lang.

The Code

To catch this momentum spike, we can use our API effectively. Here's how to set up your Python code:

import requests

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


# Step 1: Geographic origin filter
url = "https://api.pulsebit.lojenterprise.com/v1/sentiment"

![Geographic detection output for defence. India leads with 7 ](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1780380049481.png)
*Geographic detection output for defence. India leads with 7 articles and sentiment +0.11. Source: Pulsebit /news_recent geographic fields.*


params = {
    "topic": "defence",
    "lang": "en",
    "score": -0.100,
    "confidence": 0.90,
    "momentum": +0.518
}

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

print(data)
Enter fullscreen mode Exit fullscreen mode

Now, let’s leverage the cluster reason string through our POST /sentiment endpoint to score the narrative framing itself. This is the unique part that allows us to analyze the context around the spike:

# Step 2: Meta-sentiment moment
meta_url = "https://api.pulsebit.lojenterprise.com/v1/sentiment"

meta_payload = {
    "input": "Clustered by shared themes: sexual, violence, landmark, military, inquiry."
}

meta_response = requests.post(meta_url, json=meta_payload)
meta_data = meta_response.json()

print(meta_data)
Enter fullscreen mode Exit fullscreen mode

This code allows us to filter by language and assess the sentiment around clustered themes, giving us a more comprehensive understanding of the emerging narratives.

Three Builds Tonight

Here are three specific things we can build with this pattern:

  1. Geo-filtered Sentiment Trends: Set a signal threshold at +0.500 for detecting topics like "defence." Use the geo filter to catch spikes specifically in regions where conflicts or military actions are occurring. This can help identify early indicators of regional unrest.

  2. Meta-Sentiment Analysis: Create a dashboard that continuously analyzes clusters of narratives. Use the meta-sentiment loop on themes like "military" and "inquiry" to track sentiment shifts in real-time. This can serve as an early warning system for potential geopolitical shifts.

  3. Gap Analysis Engine: Build an automated reporting tool that compares sentiment from emerging topics (like "defence") against mainstream themes (like "sexual" or "violence"). This could help you identify when an important topic is being overshadowed and allow you to shift your focus accordingly.

Get Started

Ready to put this into practice? Check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run this in under 10 minutes to start catching those crucial sentiment leads.

Top comments (0)