DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

Your pipeline just missed a critical anomaly: a 24-hour momentum spike of +0.703. This means that sentiment around the topic of "world" surged significantly in a short period, highlighted by a leading article, "AI wins have Alphabet poised to become world’s biggest company" from Fortune. This spike indicates a noteworthy shift in sentiment, and if your system isn't tuned to catch these swift changes, you're lagging behind by over six hours, according to the leading language data.

The Problem

Your model missed this by 6.9 hours, and it’s a glaring issue if you’re dealing with multilingual data or a dominant entity like Alphabet. When sentiment around such influential topics shifts rapidly, you need to be on top of it. If your pipeline isn’t structured to leverage language filters or entity recognition, you might be left analyzing stale data while pivotal conversations unfold without you.

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

The Code

Here’s how you can catch this momentum spike and avoid being left behind. We’ll use our API to query sentiment data filtered by the English language, specifically looking at the topic "world".

First, let’s set up our API call to filter based on the language:

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

# API endpoint and parameters
url = "https://api.pulsebit.com/v1/sentiment"
params = {
    "topic": "world",
    "lang": "en"
}

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

# Extract relevant information
momentum = data['momentum_24h']  # +0.703
print(f"24h momentum for 'world': {momentum}")
Enter fullscreen mode Exit fullscreen mode

Next, we need to analyze the narrative framing of our clustered articles. We’ll feed the cluster reason string back through our sentiment endpoint to score it:

# Meta-sentiment moment
meta_sentiment_text = "Clustered by shared themes: wins, have, alphabet, poised, become."
meta_response = requests.post(url, json={"text": meta_sentiment_text})
meta_data = meta_response.json()

# Extract and print the sentiment score
sentiment_score = meta_data['sentiment_score']  # +0.060
confidence = meta_data['confidence']  # 0.85
print(f"Meta sentiment score: {sentiment_score} with confidence: {confidence}")
Enter fullscreen mode Exit fullscreen mode

This two-step process allows us to catch emerging sentiment trends effectively.

Three Builds Tonight

Now that we have the data, what can we build with this momentum spike? Here are three specific implementations:

  1. Geographic Origin Filter: Create a real-time alert system that triggers when sentiment around "world" exceeds a threshold, say +0.7, specifically in English-language articles. Use the geo filter to ensure you’re only capturing relevant sentiment shifts.

Geographic detection output for world. India leads with 40 a
Geographic detection output for world. India leads with 40 articles and sentiment +0.10. Source: Pulsebit /news_recent geographic fields.

   if momentum > 0.7:
       # Trigger your alert system
       print("Alert: Significant sentiment spike detected!")
Enter fullscreen mode Exit fullscreen mode
  1. Meta-Sentiment Loop: Build a dashboard that visualizes sentiment scores over time for clustered narratives. Incorporate the meta-sentiment analysis to show how narratives are being framed in the media about "wins, have, alphabet".

  2. Forming Themes Analysis: Develop a report generator that aggregates forming themes like "world", "google", and "cup" against mainstream narratives. By scoring these against a baseline sentiment, you can identify potential market movements or shifts in public opinion.

Get Started

To dive deeper and implement these strategies, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste the above code and get this running in under 10 minutes to start catching the sentiment shifts that matter.

Top comments (0)