DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently discovered a significant anomaly: a 24h momentum spike of -0.912. This sudden drop in sentiment is tied to the narrative around Disney's new CEO and a massive €2.18 billion overhaul of their theme park. This story is clustered around themes like "new," "ceo," and "caps," revealing a troubling gap in how sentiment is being processed in your pipeline.

If your sentiment analysis model isn't equipped to handle multilingual origins or recognizes entity dominance effectively, it’s likely going to miss crucial trends like this one. For instance, you could be trailing behind by 20.7 hours, as indicated by the leading English press coverage emerging right when the momentum shift occurred.

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

Let’s dig into how to catch these momentum shifts programmatically. Here's a Python snippet that utilizes our API to analyze this specific situation:

import requests

# Define the parameters for the API call
topic = 'world'
score = +0.015
confidence = 0.85
momentum = -0.912

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


# Geographic origin filter: querying for English language articles
url = f'https://api.pulsebit.com/topics/{topic}/sentiment'
params = {
    "lang": "en",
    "momentum": momentum,
    "confidence": confidence
}

![Geographic detection output for world. Hong Kong leads with ](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1774832269811.png)
*Geographic detection output for world. Hong Kong leads with 15 articles and sentiment +0.16. Source: Pulsebit /news_recent geographic fields.*


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

# Print the response for debugging
print(data)

# Now, let's analyze the narrative framing itself
narrative = "Clustered by shared themes: new, ceo, caps, billion, euro."
sentiment_url = 'https://api.pulsebit.com/sentiment'
sentiment_response = requests.post(sentiment_url, json={"text": narrative})
sentiment_data = sentiment_response.json()

# Output the sentiment analysis of the narrative
print(sentiment_data)
Enter fullscreen mode Exit fullscreen mode

In the code above, we first query by the topic "world," specifying the language as English. This ensures that we're focusing on the most relevant articles that could influence sentiment. Next, we utilize the POST /sentiment endpoint to get a sentiment score for the narrative framing itself, which adds depth to our analysis.

Now that we’ve established how to catch these signals, let’s discuss three builds that can be generated from this momentum shift:

  1. Cluster Alert System: Set up a signal that triggers when sentiment momentum drops below -0.5 for topics like "world." This would allow you to proactively catch falling sentiment before it becomes widespread.

  2. Geo-Filtered Insights: Utilize the geographic origin filter to aggregate sentiment data from specific regions. For example, alert when sentiment in the EU regarding "new," "ceo," and "caps" falls significantly below a score of 0.0.

  3. Meta-Sentiment Dashboard: Build a dashboard that visualizes the sentiment of the narratives surrounding major corporate shifts. Use the output from the sentiment analysis of the cluster reason to track how these narratives evolve over time, focusing on themes like "world" and "new."

To get started with these builds, check out our documentation at pulsebit.lojenterprise.com/docs. You’ll be able to copy-paste and run this code in under 10 minutes, unlocking valuable insights into sentiment dynamics that can help you stay ahead of the curve.

Top comments (0)