DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 20.1h Behind: Catching Climate Sentiment Leads with Pulsebit

Your Pipeline Is 20.1h Behind: Catching Climate Sentiment Leads with Pulsebit

We recently observed a notable anomaly: a 24h momentum spike of +0.394 related to climate sentiment. This spike isn’t just a number; it signals a significant shift in public discourse, specifically tied to rising water bills and climate change. With two articles highlighting this phenomenon, the narrative is gaining traction, and it’s essential to understand how to capture these emerging trends effectively using our API.

Your model missed this by 20.1 hours. If your sentiment pipeline isn’t equipped to handle multilingual origins or recognize the dominance of specific entities, you could be lagging behind critical insights. In this case, the leading language was English, but the themes surrounding water bills are universal. If you’re not accounting for this dynamic, you’re potentially missing out on significant sentiment shifts that could inform your decisions.

English coverage led by 20.1 hours. Sl at T+20.1h. Confidenc
English coverage led by 20.1 hours. Sl at T+20.1h. Confidence scores: English 0.90, Spanish 0.90, Af 0.90 Source: Pulsebit /sentiment_by_lang.

Here’s how we can catch this sentiment spike with Python. We’ll start by fetching relevant articles using our API to filter by language and country.

Geographic detection output for climate. Hong Kong leads wit
Geographic detection output for climate. Hong Kong leads with 1 articles and sentiment -0.70. Source: Pulsebit /news_recent geographic fields.

import requests

# Define parameters for API call
topic = 'climate'
lang = 'en'
momentum = +0.394
confidence = 0.90
score = -0.087

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


# Fetch articles related to the topic in English
response = requests.get(f"https://api.pulsebit.com/articles?topic={topic}&lang={lang}")

# Print the response for debugging
print(response.json())
Enter fullscreen mode Exit fullscreen mode

Next, we need to score the narrative framing of the identified cluster reason string. This will help us understand the sentiment around the emerging themes more deeply.

# Meta-sentiment moment: analyzing the cluster reason
cluster_reason = "Clustered by shared themes: change, fueling, georgia's, brutal, summer."
sentiment_response = requests.post("https://api.pulsebit.com/sentiment", json={"text": cluster_reason})

# Print the sentiment score for the cluster
print(sentiment_response.json())
Enter fullscreen mode Exit fullscreen mode

These two API calls allow us to capture and analyze sentiment trends effectively. The first fetches articles relevant to climate change from English sources, while the second evaluates the sentiment surrounding the narratives derived from the articles. This dual approach is crucial for developing a nuanced understanding of public sentiment.

Now, let’s explore three specific builds we can implement based on this momentum spike:

  1. Geo-Filtered Sentiment Analysis: Use the geographic origin filter to track sentiment shifts in areas most affected by climate change. Set a threshold for momentum spikes above +0.3 to prioritize emerging narratives.
   # Example of threshold setting
   if momentum > 0.3:
       # Trigger further analysis
       print("Significant sentiment spike detected.")
Enter fullscreen mode Exit fullscreen mode
  1. Meta-Sentiment Loop: Create a loop that runs the meta-sentiment analysis whenever articles are clustered by shared themes. Use a confidence threshold of 0.85 to confirm strong sentiment before alerting your team.
   if confidence > 0.85:
       # Execute further actions based on sentiment
       print("Strong sentiment detected for cluster.")
Enter fullscreen mode Exit fullscreen mode
  1. Dynamic Theme Monitoring: Build a monitoring tool that checks for forming themes, such as climate, google, and change. Set alerts for any significant sentiment shifts in these areas, especially when compared to mainstream narratives.
   # Monitor for emerging themes
   emerging_themes = ["climate", "google", "change"]
   if any(theme in cluster_reason for theme in emerging_themes):
       print("Emerging themes detected in sentiment.")
Enter fullscreen mode Exit fullscreen mode

These builds leverage the real-time insights we can extract from our API and help us stay ahead of critical sentiment shifts that could impact decision-making.

For those eager to dive in, visit pulsebit.lojenterprise.com/docs. You can copy-paste and run these examples in under 10 minutes. Let’s leverage the power of sentiment data to stay proactive in our strategies.

Top comments (0)