DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

In the last 24 hours, we've seen a notable momentum spike of -0.450 in the sentiment surrounding the software sector. This drop is particularly intriguing given the context of a cluster story titled "Software as a Service (SaaS) Market Expected to Reach US$908.2" — a headline that should ideally generate optimism, not concern. With no related articles to support this sentiment shift, we find ourselves facing an anomaly that cannot be ignored.

When you rely on sentiment data from multiple sources, it’s easy to miss critical insights if your pipeline doesn’t account for multilingual origins or dominant entities within the data. Your model missed this spike by a full 24 hours, potentially glossing over the fact that the leading language in this domain is English, which may have masked emerging sentiments from non-English sources. The lack of geo-filtering means you might be overlooking crucial sentiments from global narratives that could significantly impact your analysis.

en coverage led by 18.5 hours. id at T+18.5h. Confidence sco
en coverage led by 18.5 hours. id at T+18.5h. Confidence scores: en 0.87, es 0.85, fr 0.85 Source: Pulsebit /sentiment_by_lang.

Here’s a quick Python script to catch anomalies like this one:

import requests

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


# Define our parameters
topic = 'software'
momentum = -0.450
score = +0.000
confidence = 0.00

# Geographic origin filter (assuming we had geo data)
# geo_filter = 'en-US'  # Uncomment if geo data is available

# Fetching sentiment data
response = requests.get(
    f'https://api.pulsebit.com/sentiment?topic={topic}&momentum={momentum}&score={score}&confidence={confidence}'
)

# Display response
print(response.json())

# Meta-sentiment moment
cluster_reason = "Clustered by shared themes: service, (saas), market, expected, reach."
meta_response = requests.post(
    'https://api.pulsebit.com/sentiment', 
    json={'text': cluster_reason}
)

# Display meta sentiment response
print(meta_response.json())
Enter fullscreen mode Exit fullscreen mode

In this code, we’re querying for the sentiment of the topic "software" with the specific anomaly metrics. The geo_filter is commented out, as we currently don’t have geographic data for this example. If we did, filtering by language or country would enhance the precision of our anomaly detection significantly.

Geographic detection output for software. au leads with 1 ar
Geographic detection output for software. au leads with 1 articles and sentiment +0.00. Source: Pulsebit /news_recent geographic fields.

Next, we run the cluster reason string back through our API to analyze how the narrative frames itself. This is crucial for understanding why sentiments are shifting. The meta sentiment response allows us to assess the framing of the narrative itself, offering insights into potential biases or gaps.

Now, let’s outline three specific builds we can implement using this anomaly detection pattern:

  1. Sentiment Alert System: Set up a threshold alert for any sentiment spike below -0.300 on the topic "software." Use the endpoint that fetches daily sentiment data to trigger notifications when anomalies occur.

  2. Geo-Filtered Sentiment Analysis: Implement a query that filters sentiment data by specific countries, such as 'en-GB' or 'de-DE'. This allows you to capture localized sentiments that may not be reflected in global data.

  3. Meta-Sentiment Reporting: Create a report that pulls the narrative framing for any topic that has a momentum spike. Use the POST endpoint to analyze sentiment around the narrative every time a significant shift occurs. By doing this, you gain deeper insights into how media narratives influence perception.

To dive into building these solutions, check out our documentation. You can copy and paste the provided Python code and run it in under 10 minutes to start detecting anomalies in sentiment data. This is a powerful way to keep your insights relevant and actionable.

Top comments (0)