DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 21.1h Behind: Catching Health Sentiment Leads with Pulsebit

Your Pipeline Is 21.1h Behind: Catching Health Sentiment Leads with Pulsebit

We recently stumbled upon an intriguing anomaly: a 24h momentum spike of -0.750 in health sentiment. The leading language was English, with a pressing focus from the media 21.1 hours ago. The surprising aspect is that while mainstream narratives revolve around health, aging, and expertise, there was an emerging cluster centered on the article titled "A Healthy Aging Expert’s No. 1 Favorite Social Activity to Boost Longevity and O." This indicates a significant shift in sentiment that many pipelines might miss if they don't account for multilingual origins or entity dominance.

English coverage led by 21.1 hours. Nl at T+21.1h. Confidenc
English coverage led by 21.1 hours. Nl at T+21.1h. Confidence scores: English 0.90, Spanish 0.90, Sv 0.90 Source: Pulsebit /sentiment_by_lang.

Your model likely missed this critical insight by 21.1 hours, which can be a huge disadvantage in the fast-paced world of sentiment analysis. If your pipeline isn't set up to handle multiple languages or recognize dominant entities, you're potentially ignoring valuable signals. In this case, while the mainstream conversation was rooted in well-established themes, the nuance of the English narrative was overshadowed.

Let's dive into how we can capture this important data. We can utilize our API to filter sentiment analysis by geographic origin, specifically focusing on the English language for this health topic. Here’s the Python code to perform that operation:

Geographic detection output for health. India leads with 12
Geographic detection output for health. India leads with 12 articles and sentiment +0.26. Source: Pulsebit /news_recent geographic fields.

import requests

# Set parameters for the API call
topic = 'health'
score = -0.141
confidence = 0.90
momentum = -0.750

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


# Geographic origin filter
url = "https://api.pulsebit.com/sentiment"
params = {
    "topic": topic,
    "lang": "en",
    "score": score,
    "confidence": confidence,
    "momentum": momentum
}

response = requests.get(url, params=params)
data = response.json()

print(data)
Enter fullscreen mode Exit fullscreen mode

Next, we analyze the narrative framing itself. Let’s run the cluster reason string back through our sentiment scoring endpoint to assess how the themes resonate:

# Meta-sentiment moment
cluster_reason = "Clustered by shared themes: healthy, aging, expert’s, favorite, social."
meta_sentiment_url = "https://api.pulsebit.com/sentiment"
meta_params = {
    "text": cluster_reason
}

meta_response = requests.post(meta_sentiment_url, json=meta_params)
meta_data = meta_response.json()

print(meta_data)
Enter fullscreen mode Exit fullscreen mode

Now that we have the necessary tools, let’s explore three specific builds we can create with this pattern.

  1. Geo Filter Alert: Set a threshold for health sentiment below -0.5 in English articles. This way, whenever there’s a significant downturn, you can immediately investigate the context.
   if data['momentum'] < -0.5:
       alert("Health sentiment is falling sharply in English articles.")
Enter fullscreen mode Exit fullscreen mode
  1. Meta-Sentiment Insight: Create a service that analyzes narratives around health and aging every time a new article appears. Use the meta-sentiment loop to refine your understanding of emerging themes.
   if meta_data['sentiment_score'] < -0.1:
       log("Negative sentiment detected in narrative framing.")
Enter fullscreen mode Exit fullscreen mode
  1. Forming Themes Tracker: Implement an endpoint that watches for forming themes, such as “happiest” and “google,” and how they correlate with mainstream sentiments. This can help identify shifts in public interest before they become mainstream.
   forming_themes = ['health', 'happiest', 'google']
   if any(theme in data['semantic_clusters'] for theme in forming_themes):
       track("New forming theme detected.")
Enter fullscreen mode Exit fullscreen mode

You can start building these alerts and insights right away by visiting pulsebit.lojenterprise.com/docs. We believe you can copy-paste and run these snippets in under 10 minutes, enabling you to stay ahead of the curve in health sentiment analysis.

Top comments (0)