DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

Your 24-hour momentum spike of -0.660 surrounding climate sentiment caught our attention today. This anomaly suggests a significant shift in public sentiment, especially concerning gray whale deaths in the Bay Area and broader climate change concerns. With only one article processed, the implications are vast, especially given the leading language being English. We’re at a point where the conversation about climate is rapidly shifting, and our insights can help you catch these changes before they become mainstream.

The underlying gap here is evident. If your pipeline doesn't account for multilingual origin or entity dominance, you're missing critical signals. Right now, your model is lagging by 22 hours, which means you're at risk of being out of touch. This specific spike in sentiment—fueled by an English-language article discussing the plight of gray whales—could lead to missed opportunities if you’re only processing data from one angle or language.

English coverage led by 22.0 hours. Sl at T+22.0h. Confidenc
English coverage led by 22.0 hours. Sl at T+22.0h. Confidence scores: English 0.85, Spanish 0.85, French 0.85 Source: Pulsebit /sentiment_by_lang.

To catch this spike, we can write a simple Python script using our API. Below is the code that captures the current sentiment around climate:

import requests

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


# Step 1: Using geographic origin filter to capture the climate topic
response = requests.get("https://api.pulsebit.lojenterprise.com/sentiment", 
                        params={"topic": "climate", "lang": "en"})
data = response.json()

![Geographic detection output for climate. India leads with 1 ](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1778409083251.png)
*Geographic detection output for climate. India leads with 1 articles and sentiment +0.85. Source: Pulsebit /news_recent geographic fields.*


# Check if the response contains valid data
if data['momentum_24h'] < -0.5:  # This threshold indicates a significant spike
    print("Anomaly detected: 24h momentum spike:", data['momentum_24h'])

# Step 2: Run the cluster reason string through the sentiment endpoint
cluster_reason = "Clustered by shared themes: grow, over, more, gray, whale."
sentiment_response = requests.post("https://api.pulsebit.lojenterprise.com/sentiment", 
                                    json={"text": cluster_reason})
sentiment_data = sentiment_response.json()

print("Meta Sentiment Score:", sentiment_data['sentiment_score'])
Enter fullscreen mode Exit fullscreen mode

In this code, we first filter the sentiment data by the English language to isolate the climate topic. We then check for significant momentum spikes (here, we defined it as lower than -0.5). After identifying the spike, we run the cluster reason string through our sentiment endpoint to gauge the narrative's framing. This step is crucial as it allows us to understand how the sentiment around the topic is being shaped by various themes.

Now, let’s discuss three builds you could implement based on this data pattern:

  1. Geographic Sentiment Analysis: Build a real-time alert system that monitors sentiment spikes in specific geographies. Use the geo filter to focus on regions with high environmental concerns, such as coastal areas. Set a threshold at -0.5 for momentum to trigger notifications.

  2. Meta-Sentiment Loop: Create a dashboard that visualizes how narratives evolve over time. This should utilize the meta-sentiment loop to analyze and display how themes like "grow, over, more" shape public opinion surrounding climate issues. Update the dashboard dynamically as new data comes in.

  3. Forming Gap Analysis: Develop a predictive model that assesses the forming gaps between mainstream and emerging themes. Use the forming themes like climate, change, and Google to gauge potential future spikes in sentiment. By analyzing how new topics emerge against established narratives, you can forecast shifts in public opinion.

If you want to dive deeper, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste the provided code and run it in under 10 minutes to start catching these crucial sentiment shifts right now.

Top comments (0)