DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

Your pipeline just missed a significant 24h momentum spike of -0.604 related to the topic of defence. This anomaly suggests that a considerable shift in sentiment is happening right now, particularly around discussions of military support in the context of the ongoing war in Ukraine, as voiced by Zelenskyy. The urgency of this spike cannot be overstated; it reflects an evolving narrative that you need to catch before it impacts your models and decisions.

If your data pipeline doesn't accommodate multilingual origins or entity dominance, you might find yourself 17.6 hours behind the curve. This lag is particularly troubling when it comes to understanding how Western press coverage is framing the ongoing conflict in Ukraine, with English as the leading language but a significant cluster of articles emphasizing themes of war, support, and patriotism. Your model might have missed this timely insight while focusing on other narratives, potentially compromising your understanding of the geopolitical landscape.

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

To capture this momentum spike effectively, we can leverage our API. Here’s how we can query the relevant data, focusing specifically on the defence topic with a negative sentiment score.

import requests

# Define the API endpoint and parameters
url = "https://api.pulsebit.com/v1/insights"
params = {
    "topic": "defence",
    "score": -0.125,
    "confidence": 0.85,
    "momentum": -0.604,
    "lang": "en"  # Geographic origin filter
}

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


# Make the API call
response = requests.get(url, params=params)
data = response.json()

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


# Print the results
print(data)
Enter fullscreen mode Exit fullscreen mode

Now that we have our data, we need to run a meta-sentiment analysis on the cluster reason string to gauge the narrative framing itself. Here’s how you can do that:

# Define the meta-sentiment input
meta_sentiment_input = "Clustered by shared themes: ukraine, russia’s, war, support, patriot."

# API endpoint for sentiment analysis
sentiment_url = "https://api.pulsebit.com/v1/sentiment"

# Make the POST request for meta-sentiment analysis
sentiment_response = requests.post(sentiment_url, json={"text": meta_sentiment_input})
sentiment_data = sentiment_response.json()

# Print the sentiment analysis results
print(sentiment_data)
Enter fullscreen mode Exit fullscreen mode

With these two calls, you're not just capturing the spike in defence sentiment; you're also evaluating the surrounding narrative that shapes public perception.

Now, let’s consider three specific builds you can implement with this pattern:

  1. Geo-filtered Sentiment Analysis for Defence: Build an endpoint that continuously polls for defence-related articles in English, using a score threshold of -0.125. This will allow you to monitor shifts in sentiment and react promptly.

  2. Meta-Sentiment Loop Trigger: Create a trigger that runs the meta-sentiment analysis whenever a negative score is detected in the defence topic. This way, you can swiftly understand the context of the articles leading to the sentiment change.

  3. Alert System for Forming Themes: Set up an alert system that monitors forming themes such as defence (+0.00), Trump (+0.00), and budget (+0.00) against mainstream narratives like Ukraine and Russia's war. This can give you an early warning of narrative shifts.

By combining these insights and actions, you can ensure that your models remain agile and responsive to the rapidly changing geopolitical landscape.

If you want to get started, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run these snippets in under 10 minutes. Get ahead of the curve!

Top comments (0)