DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently discovered a significant anomaly in our analytics: a 24h momentum spike of +0.610 related to defence sentiment. This spike isn't just a number; it reflects a growing narrative surrounding Canada-India defence collaboration, clustered under themes that resonate strongly with current geopolitical climates. The leading language in this spike is English, with a remarkably precise timing of 11.1 hours ahead of other signals. This kind of data isn’t just interesting—it’s critical for staying ahead in a rapidly evolving landscape.

The Problem

If your pipeline isn't designed to handle multilingual origins or account for entity dominance, you might have missed this spike by over 11 hours. The leading sentiment in English is a clear indicator of emerging narratives that could inform your strategies. By ignoring these nuances, you risk operating in a reactive mode while your competitors leverage timely insights. Imagine the implications: your model could be lagging, missing critical shifts in sentiment that could drive decision-making.

English coverage led by 11.1 hours. Nl at T+11.1h. Confidenc
English coverage led by 11.1 hours. Nl at T+11.1h. Confidence scores: English 0.85, Spanish 0.85, Ca 0.85 Source: Pulsebit /sentiment_by_lang.

The Code

Here’s how we can catch this momentum spike in our analysis using our API. First, we’ll filter the data by language and country to hone in on the relevant signals. The following Python code demonstrates how to query for this specific topic:

Geographic detection output for defence. Hong Kong leads wit
Geographic detection output for defence. Hong Kong leads with 10 articles and sentiment +0.32. Source: Pulsebit /news_recent geographic fields.

import requests

# Parameters for our API call
topic = 'defence'
lang = 'en'
momentum = +0.610

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


# API endpoint for fetching sentiment data
url = f"https://api.pulsebit.com/v1/sentiment?topic={topic}&lang={lang}"

# Make the API call
response = requests.get(url)
data = response.json()
print(data)
Enter fullscreen mode Exit fullscreen mode

Next, we’ll run the cluster reason string through our sentiment scoring endpoint to analyze the narrative framing itself. This step is crucial as it encapsulates the themes driving the current sentiment.

# Cluster reason string
cluster_reason = "Clustered by shared themes: defence, canada-india, collaboration, secure, future"

# API endpoint for scoring the narrative framing
url_sentiment = "https://api.pulsebit.com/v1/sentiment"

# Make the POST request
payload = {
    "text": cluster_reason
}
response = requests.post(url_sentiment, json=payload)
meta_sentiment = response.json()
print(meta_sentiment)
Enter fullscreen mode Exit fullscreen mode

Three Builds Tonight

With the momentum spike and the meta-sentiment insights, here are three specific builds you can create:

  1. Geographic Origin Filter: Use the lang parameter to filter incoming data. This ensures that your analysis focuses on English-language content, capturing the leading narrative without the noise of other languages. Set a threshold of momentum greater than +0.500.

  2. Meta-Sentiment Loop: Continuously run the cluster reason strings through the sentiment scoring endpoint. If a narrative scores above a confidence level of 0.80, consider it a strong signal for further analysis. Utilize this for themes like "defence" and "collaboration," which are forming without mainstream overlap.

  3. Threshold Alerts: Set alerts for forming themes around "military" and its associations. If momentum shows a spike of more than +0.300 alongside a positive sentiment score, trigger a notification for deeper analysis. This will help you stay proactive in identifying shifts before they become mainstream.

Get Started

To start building with these insights, check out our documentation at pulsebit.lojenterprise.com/docs. We encourage you to copy-paste and run this code within ten minutes to see the power of real-time sentiment analysis in action.

Top comments (0)