DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

How to Detect Cloud Sentiment Anomalies with the Pulsebit API (Python)

How to Detect Cloud Sentiment Anomalies with the Pulsebit API (Python)

We recently stumbled upon a striking anomaly: a 24h momentum spike of +0.375 in the sentiment surrounding the cloud sector. This spike isn't just a number; it reflects a significant shift in public sentiment that could impact decision-making. The momentum increase suggests that something noteworthy is brewing in the cloud space, and we need to dive deeper to understand it.

Without a robust pipeline that accounts for multilingual origins or dominant entities, you risk missing critical insights like this one. Imagine your model missing this anomaly by a mere few hours. The leading language in discussions around cloud technology might skew your results if you don't account for it properly, ultimately leading to a misinterpretation of public sentiment. In this case, that could mean missing out on crucial insights from emerging markets or non-English speaking regions.

Arabic coverage led by 4.2 hours. English at T+4.2h. Confide
Arabic coverage led by 4.2 hours. English at T+4.2h. Confidence scores: Arabic 0.82, Mandarin 0.68, English 0.41 Source: Pulsebit /sentiment_by_lang.

To capture such anomalies, we need to implement a solution that leverages our API effectively. Here’s how to catch that spike.

import requests

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


# Define the parameters for the API request
topic = 'cloud'
score = +0.000
confidence = 0.87
momentum = +0.375

# Geographic origin filter - Note: No geo filter data returned
geo_filter = {
    "language": "en",  # Replace with actual language or country if available
    "topic": topic
}

![[DATA UNAVAILABLE: countries  verify /news_recent is return](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1773076432782.png)
*[DATA UNAVAILABLE: countries  verify /news_recent is returning country/region values for topic: cloud]*


# This is where you would apply the geo filter if data was available
response = requests.get(f"https://api.pulsebit.com/data?topic={topic}&geo={geo_filter}")
data = response.json()

# Check if the expected data is present
if response.status_code == 200 and data:
    print("Geo-filtered data retrieved successfully.")
else:
    print("No geo filter data returned — verify /dataset/daily_dataset and /news_recent.")
Enter fullscreen mode Exit fullscreen mode

Next, we want to analyze the sentiment narrative itself. For this, we’ll run a meta-sentiment moment using our API to score the cluster narrative.

# Input for meta-sentiment analysis
narrative_input = "Cloud narrative sentiment cluster analysis"

# POST request to analyze the sentiment of the narrative
response = requests.post("https://api.pulsebit.com/sentiment", json={"text": narrative_input})
meta_sentiment_data = response.json()

# Check the response
if response.status_code == 200:
    print("Meta-sentiment analysis successful:", meta_sentiment_data)
else:
    print("Failed to analyze meta-sentiment.")
Enter fullscreen mode Exit fullscreen mode

With these two components, we can build some useful tools around this anomaly. Here are three specific builds we can create:

  1. Geo-filtered Anomaly Detection: Set a threshold for momentum spikes, e.g., momentum > +0.300, and filter results based on geographic language. This could help you identify trends emerging in specific regions faster.

  2. Meta-Sentiment Monitoring: Use the narrative sentiment analysis build to track how sentiment shifts over time. A threshold like confidence > 0.80 can be set to trigger alerts when narratives shift significantly, allowing for quick responses.

  3. Composite Signals: Combine the geo-filtered data and the meta-sentiment analysis into a composite signal. For instance, if momentum exceeds +0.375 and the sentiment score is below 0.1, you could trigger a deeper investigation into the underlying reasons.

If you’re ready to start leveraging these insights, head over to our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste this code and have it running in under 10 minutes. Let’s catch those anomalies together!

Top comments (0)