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)

We recently encountered a fascinating anomaly: a 24-hour momentum spike of -0.450 in the sentiment surrounding the software sector. This significant drop in momentum suggests a sudden shift in sentiment, which could be indicative of larger trends or emerging narratives that warrant our attention. Notably, there were 0 articles associated with this anomaly, yet it was clustered around themes like "service", "(saas)", and "market", prompting us to dig deeper.

The absence of articles in conjunction with a negative momentum spike reveals a crucial gap in many sentiment analysis pipelines. If you’re not accounting for multilingual origins or the dominance of specific entities, your model may have missed this anomaly by several hours. In this case, English articles might be overshadowing other languages, which can significantly alter sentiment perception. We’re seeing a moment where sentiment is shifting, but the data doesn’t back it up with a substantial volume of articles, leaving a potential blind spot in your analysis.

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

Let’s get hands-on with some Python code to identify this anomaly effectively. Below is a snippet that captures the essence of this spike:

import requests

# Define the parameters for the API call
topic = 'software'
score = +0.000
confidence = 0.00
momentum = -0.450

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


# Geographic origin filter (This is a placeholder; actual data is unavailable)
geo_filter = {
    'region': 'global',  # Specify the region if available
    'language': 'en'    # Example: filter for English articles
}

# Check sentiment from our API
response = requests.post('https://api.pulsebit.com/sentiment', json={
    "input": "Clustered by shared themes: service, (saas), market, expected, reach."
})

# Check if the API returned a score
if response.status_code == 200:
    sentiment_data = response.json()
    print(sentiment_data)
else:
    print("Error fetching sentiment data:", response.status_code)
Enter fullscreen mode Exit fullscreen mode

Here, we have a straightforward implementation that allows us to query sentiment based on our identified cluster reason string. It’s worth noting that geographic filtering can enhance our results significantly when language and country data are available. Unfortunately, in our current dataset, we couldn’t retrieve geo-filtered data, but it's a powerful feature when implemented correctly.

![DATA UNAVAILABLE: countries — verify /news_recent is return
[DATA UNAVAILABLE: countries — verify /news_recent is returning country/region values for topic: software]

Next, we want to explore the sentiment surrounding the narrative itself. We’ll run the cluster reason string back through our API to get a score for the narrative framing. This is how we can quantify the sentiment around the concepts being discussed:

# Running the cluster reason string through our API
narrative_response = requests.post('https://api.pulsebit.com/sentiment', json={
    "input": "Clustered by shared themes: service, (saas), market, expected, reach."
})

# Output the sentiment score for the narrative
if narrative_response.status_code == 200:
    narrative_sentiment_data = narrative_response.json()
    print("Narrative Sentiment Score:", narrative_sentiment_data)
else:
    print("Error fetching narrative sentiment data:", narrative_response.status_code)
Enter fullscreen mode Exit fullscreen mode

With the code above, you can assess the sentiment of the narrative directly, allowing you to gauge not just the data but the underlying narratives shaping it.

Now, let's discuss three builds we can implement with this pattern:

  1. Geo-Filtered Alerts: Set up an alert system that triggers when sentiment momentum drops below -0.5 for the software sector in a specific country. This would help us catch regional shifts early.

  2. Narrative Score Dashboard: Create a dashboard that visualizes sentiment scores of specific narratives, like "service" and "saas", derived from cluster reason strings. This can highlight potentially dangerous shifts in sentiment over time.

  3. Anomaly Detection Bot: Develop a bot that runs automated checks on sentiment data every hour, flagging anomalies where momentum drops sharply and correlates with a rise in certain thematic clusters. This could aid in proactive decision-making.

We encourage you to get started with our API at pulsebit.lojenterprise.com/docs. You can easily copy-paste the provided code and have it running in under 10 minutes. Start leveraging sentiment data more effectively today!

Top comments (0)