DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently stumbled upon a striking anomaly: a 24-hour momentum spike of -0.303 in mobile sentiment. This drop is particularly curious in light of the news surrounding the launch of a new 5G handset by Siyata PTT and T-Mobile. Despite no articles reporting on this event, our API clustering identified shared themes like "ptt," "announces," and "t-mobile." This discrepancy highlights a critical insight into sentiment analysis and how it can sometimes miss key developments.

In any sentiment analysis pipeline that doesn't handle multilingual origins or entity dominance effectively, gaps can manifest. Imagine your model missed this by 12 hours while the leading news was in English but the sentiment was largely driven by other languages. The absence of a comprehensive geographical and linguistic filter can lead to significant oversight, especially with major events like a 5G launch.

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

Let's dive into the Python code that captures this anomaly. We'll begin with a basic analysis of the mobile topic:

import requests

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


# Setting the parameters
topic = 'mobile'
score = +0.000
confidence = 0.00
momentum = -0.303

# Geographic origin filter
# Note: Data is currently unavailable for geo filter, but here's how you would structure it
geographic_filter = {
    "topic": topic,
    "country": "US",  # Example for filtering by country
    "language": "en"  # Example for filtering by language
}

![Geographic detection output for mobile. in leads with 2 arti](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1773326307671.png)
*Geographic detection output for mobile. in leads with 2 articles and sentiment +0.38. Source: Pulsebit /news_recent geographic fields.*


# Making the API request (hypothetically, if geo data were available)
response = requests.post('https://api.pulsebit.com/data', json=geographic_filter)
data = response.json()

# Meta-sentiment moment: scoring the cluster reason
cluster_reason = "Clustered by shared themes: ptt, announces, t-mobile, first, wireless."
sentiment_response = requests.post('https://api.pulsebit.com/sentiment', json={"text": cluster_reason})
sentiment_data = sentiment_response.json()

print("Sentiment Score:", sentiment_data['score'])
print("Confidence:", sentiment_data['confidence'])
Enter fullscreen mode Exit fullscreen mode

In this code, we demonstrate how to implement a geographic origin filter. Note that, currently, we lack specific geo filter data returned from our endpoints, but the structure remains essential for future analysis. If geo data becomes available, you can easily tailor your queries and refine your insights.

Next, we run the cluster reason string through our sentiment endpoint to score the narrative framing itself. Using the cluster reason "Clustered by shared themes: ptt, announces, t-mobile, first, wireless" allows us to understand how the cluster’s sentiment aligns with the detected spike.

Now, let’s explore three builds you can implement based on this anomaly:

  1. Geo Filtered Sentiment Analysis: Set a threshold for sentiment score changes. For instance, trigger alerts when the sentiment score drops below 0.05 in the US for 'mobile' during product launches. This can help you catch anomalies early.

  2. Cluster Reason Sentiment Loop: Use the meta-sentiment loop to score recent narratives around T-Mobile. Whenever a new article surfaces, automatically analyze the sentiment of the cluster reason. If the score falls below a certain threshold (e.g., -0.1), it could indicate a shift in public perception that deserves further investigation.

  3. Comparative Analysis with Historical Baselines: Monitor the momentum changes over time for the 'mobile' topic and set up a signal for significant deviations from historical norms. For example, if the momentum swings more than ±0.25 in a 24-hour window, initiate a deeper review of news coverage and sentiment shifts.

To get started, refer to our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste the provided code and run it in under 10 minutes. This real-time analysis can greatly enhance your insights into mobile sentiment and equip you to respond more proactively to emerging trends.

Top comments (0)