DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently observed a striking anomaly: a 24-hour momentum spike of +0.379 in human rights sentiment. This spike hints at a growing discussion around "FIFA and AFC's Human Rights Obligations," despite there being no articles currently available on this topic. The API tagged this cluster based on shared themes such as "fifa," "iranian," "football," and "afc." This is a clear signal that something significant is brewing beneath the surface.

But what does this mean for you as a developer? It reveals a critical structural gap in any sentiment analysis pipeline that neglects multilingual origins or entity dominance. If your model doesn’t account for these factors, it could have missed this spike by several hours, particularly if the dominant discussions are in languages other than English. The lack of sensitivity to geographical context can leave you in the dark about emerging narratives.

en coverage led by 21.7 hours. it at T+21.7h. Confidence sco
en coverage led by 21.7 hours. it at T+21.7h. Confidence scores: en 0.86, es 0.86, fr 0.85 Source: Pulsebit /sentiment_by_lang.

Here’s how you can catch such spikes using our API in Python:

import requests

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


# Define parameters for your query
topic = 'human rights'
score = +0.000
confidence = 0.00
momentum = +0.379

# Geographic origin filter (assuming data available)
geo_filter = {"country": "iran", "language": "fa"}  # Persian for Iran
response = requests.get('https://api.pulsebit.lojenterprise.com/v1/news_recent', params=geo_filter)

![Geographic detection output for human rights. au leads with ](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1773366466498.png)
*Geographic detection output for human rights. au leads with 1 articles and sentiment -0.70. Source: Pulsebit /news_recent geographic fields.*


# Assuming response is valid and we can process it
if response.status_code == 200:
    data = response.json()
    print(f"Filtered Data: {data}")

# Meta-sentiment moment
cluster_reason = "Clustered by shared themes: fifa, their, iranian, football, afc."
sentiment_response = requests.post('https://api.pulsebit.lojenterprise.com/v1/sentiment', json={"text": cluster_reason})

if sentiment_response.status_code == 200:
    sentiment_data = sentiment_response.json()
    print(f"Meta Sentiment Score: {sentiment_data['score']}, Confidence: {sentiment_data['confidence']}")
Enter fullscreen mode Exit fullscreen mode

In this code, we start by defining our topic and sentiment scores. We then attempt to filter data by geographic origin; ideally, you’d query by country and language to capture local discussions. However, this data is currently unavailable, which underscores the importance of having geo-filtering capabilities.

Next, we take the cluster reason string and run it through our sentiment endpoint to evaluate the narrative framing itself. This unique aspect allows you to understand not just the sentiment of individual articles but the collective narrative that is forming around a specific topic.

Now that we've seen how to catch the anomaly, what can you build with this newfound insight?

  1. Geo-Filtered Sentiment Analysis: Use the geographic origin filter to track sentiment specifically in regions where discussions on human rights are emerging. For example, monitor trends in Iran by changing the geo filter to include country="iran" and language="fa".

  2. Meta-Sentiment Tracking: Build a system that continually runs cluster reason strings through the sentiment endpoint. This will allow you to score the narrative framing in real-time, enabling you to identify potential sentiment shifts before they become mainstream.

  3. Threshold Alerts: Implement a notification system that alerts you to any sentiment spikes above a certain threshold (say, +0.3). This way, you can proactively monitor discussions around critical themes like "human rights," especially when they are forming in clusters with low article counts.

To get started, check out our documentation at pulsebit.lojenterprise.com/docs. With these patterns and code snippets, you can easily copy-paste and run your analysis in under 10 minutes. Don’t miss out on critical conversations just because your model lacks the necessary sensitivity to emerging narratives.

Top comments (0)