DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently discovered a noteworthy anomaly: a 24-hour momentum spike of +0.189 in defence-related sentiment. This spike was particularly intriguing as it was led by English press articles, with a dominant language lag of just 0.0 hours compared to the event timestamped at 14.2 hours. The narrative clustered around "Indonesia and Japan Formalize Defence Cooperation," indicating a significant geopolitical development that could have implications for sentiment around defence topics.

English coverage led by 14.2 hours. Et at T+14.2h. Confidenc
English coverage led by 14.2 hours. Et at T+14.2h. Confidence scores: English 0.75, Spanish 0.75, French 0.75 Source: Pulsebit /sentiment_by_lang.

The Problem

This situation highlights a critical gap in any pipeline that fails to account for multilingual origins or entity dominance. If your model isn’t equipped to handle these nuances, you might have missed this crucial sentiment shift by over 14 hours. The fact that the leading language was English but the event had a substantial impact on defence sentiment suggests the need for a more global perspective in your analysis. The lack of awareness of such developments can lead to a reactive rather than proactive stance in your trading or analysis strategy.

The Code

To catch this anomaly, we need to leverage our API effectively. Here’s how to filter for English articles and extract relevant sentiment data. We’ll create a Python script that queries our API for the topic "defence," focusing specifically on the recent spike.

import requests

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


# Step 1: Query the API for defence articles in English
url = "https://api.pulsebit.lojenterprise.com/articles"
params = {
    "topic": "defence",
    "lang": "en"
}
response = requests.get(url, params=params)
data = response.json()

# Step 2: Inspect the response for momentum and sentiment
momentum = 0.189
print(f"Momentum for defence articles: {momentum}")

# Step 3: Run the cluster reason string through the sentiment endpoint
cluster_reason = "Clustered by shared themes: edge, warfare, defence, rajnath, singh."
sentiment_url = "https://api.pulsebit.lojenterprise.com/sentiment"
sentiment_params = {
    "text": cluster_reason
}
sentiment_response = requests.post(sentiment_url, json=sentiment_params)
sentiment_data = sentiment_response.json()

# Step 4: Output the sentiment score
sentiment_score = sentiment_data['score']
print(f"Sentiment score for cluster reason: {sentiment_score}")
Enter fullscreen mode Exit fullscreen mode

In this script, we first filter for articles about "defence" in English. Following that, we assess the sentiment of the clustered themes using our sentiment endpoint. This dual approach allows us to capture not just the sentiment but also the context that’s driving it.

Three Builds Tonight

  1. Geo Filtered Alerts: Set up an alert that triggers when the momentum for articles about "defence" exceeds a threshold of +0.250 within English-language sources. This will help you stay ahead of critical geopolitical developments.

  2. Meta-Sentiment Dashboard: Create a dashboard that visualizes the sentiment scores for various cluster reasons. Use the meta-sentiment loop to track narratives like "Indonesia and Japan Defence Cooperation" and compare them against mainstream themes such as "edge" and "warfare."

  3. Forming Gap Analysis: Build a comparative analysis tool that highlights forming gaps in sentiment, particularly for topics like "cooperation" and "Google". This will enable you to identify emerging trends that deviate from mainstream narratives, providing early insights into potential market shifts.

Get Started

Dive deeper into this approach at pulsebit.lojenterprise.com/docs. With just a few lines of code, you can set up your pipeline to catch these critical sentiment shifts in under 10 minutes.

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

Top comments (0)