DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 9.1h Behind: Catching World Sentiment Leads with Pulsebit

Your Pipeline Is 9.1h Behind: Catching World Sentiment Leads with Pulsebit

We recently discovered a striking anomaly: a 24-hour momentum spike of +0.115 in world sentiment, which is quite significant. This spike indicates heightened interest and engagement around global events, specifically with clustered articles discussing "World Cup Viewing Challenges for India and China." As developers, we know how important it is to catch these shifts early, and this particular spike highlights how our models can miss crucial updates when they don't account for multilingual origins or entity dominance.

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

The Problem

Your model missed this by 9.1 hours—an unacceptable lag that can have serious implications for timely decision-making. With the leading language being English and the dominant entities being India and China, it’s clear that a lack of multilingual support can leave your insights stale. This is a critical oversight in any pipeline that relies solely on one language or entity view. In a world driven by real-time information, missing out on these nuances can lead to missed opportunities and misguided strategies.

The Code

To catch this momentum spike, we can create a simple Python script using our API. The first step is to filter for geographic origin, specifically focusing on English-language articles. We will use the following API call:

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

import requests

# Parameters for the API call
url = "https://api.pulsebit.com/sentiment"
params = {
    "topic": "world",
    "lang": "en",
    "score": +0.109,
    "confidence": 0.85,
    "momentum": +0.115
}

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

Next, we need to run a meta-sentiment analysis on the narrative framing itself. The reason for clustering can provide additional context to our findings. We’ll loop back the cluster reason string through our sentiment endpoint:

# Meta-sentiment analysis
meta_sentiment_url = "https://api.pulsebit.com/sentiment"
meta_input = "Clustered by shared themes: china, machine, targets, top, spot."
meta_response = requests.post(meta_sentiment_url, json={"text": meta_input})
meta_data = meta_response.json()
print(meta_data)
Enter fullscreen mode Exit fullscreen mode

This code snippet allows us to score the narrative and better understand how the themes are resonating in the context of world events.

Three Builds Tonight

Here are three specific builds leveraging this pattern that you can start implementing right away:

  1. Geo-Filtered Insights: Use the geographic origin filter to track sentiment for the topic "world" specifically from India and China. Set a threshold for momentum spikes above +0.1 to alert for emerging stories.
   # Threshold check for momentum
   if data['momentum_24h'] > 0.1:
       print("Significant spike in sentiment detected!")
Enter fullscreen mode Exit fullscreen mode
  1. Meta-Sentiment Loop: Implement a feedback loop using the meta-sentiment analysis. Track phrases like "world", "china", and "india" that are forming against mainstream narratives like "machine" and "targets". This can enhance your understanding of evolving sentiments.
   # Example of tracking forming themes
   if "world" in meta_input or "china" in meta_input or "india" in meta_input:
       print("Forming themes detected!")
Enter fullscreen mode Exit fullscreen mode
  1. Sentiment Clustering: Combine sentiment scores with cluster analysis to identify which topics are gaining traction. Use a sentiment score threshold of +0.1 for articles related to the clusters identified.
   # Sentiment clustering check
   if meta_data['sentiment_score'] > 0.1:
       print("Positive sentiment in clustered themes!")
Enter fullscreen mode Exit fullscreen mode

Get Started

Ready to dive in? You can find everything you need at pulsebit.lojenterprise.com/docs. Copy-paste the above snippets, and you can have this running in under 10 minutes. Let’s make sure we never miss another momentum spike again.

Top comments (0)