DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We recently discovered a striking anomaly in our sentiment analysis: a 24-hour momentum spike of +0.310 related to climate topics. This spike emerged not only as a numerical outlier but also as a signal that demands immediate attention. The leading language of this spike was English, with a notable press lead of 17.7 hours, indicating that any existing pipeline you have may be missing critical insights by nearly a full day.

If your pipeline doesn’t account for multilingual origin or entity dominance, you're at risk of missing this crucial information. Your model missed this by 17.7 hours, leaving you behind the curve. With English as the leading language, the sentiment surrounding climate issues is evolving rapidly, and without integration of this data, your decisions may be based on outdated or incomplete information. Ignoring entities clustered around themes like climate emissions from immigration flights could leave significant gaps in your analysis and forecasting.

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

Here's the Python code you can use to catch this momentum spike and ensure your pipeline stays relevant. First, let's filter our query by the English language:

import requests

# Define parameters for the API call
params = {
    "topic": "climate",
    "score": -0.163,
    "confidence": 0.85,
    "momentum": +0.310,
    "lang": "en"
}

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


# Make the API call to get the relevant sentiment data
response = requests.get("https://api.pulsebit.com/sentiment_analysis", params=params)
data = response.json()
print(data)
Enter fullscreen mode Exit fullscreen mode

After filtering for the right language, it’s crucial to analyze the narrative framing around this momentum spike. We can run the cluster reason string through our API to score its meta-sentiment. Here’s how to do that:

# Meta-sentiment moment: scoring the narrative framing
meta_sentiment_input = "Clustered by shared themes: sound, (climate), silence, politico"
meta_response = requests.post("https://api.pulsebit.com/sentiment", json={"text": meta_sentiment_input})
meta_data = meta_response.json()
print(meta_data)
Enter fullscreen mode Exit fullscreen mode

This two-step process ensures that we not only identify the spike but also understand the context driving this sentiment, keeping us ahead in our analysis.

Now, let’s build three specific things using this pattern. First, we can set up an alerting mechanism that triggers when the momentum score exceeds a threshold of +0.300 for climate-related topics, using the geo filter to refine our search:

  1. Alert When Momentum Exceeds +0.300: Monitor sentiment spikes specifically for climate-related topics by setting a threshold of momentum greater than +0.300. Use the geo filter to ensure you’re only capturing English-language sentiments.

  2. Narrative Scoring Loop: Implement a function that runs the meta-sentiment scoring for every new cluster reason string you encounter. This will help you continuously reevaluate the framing of narratives as new data emerges.

  3. Compare with Historical Baseline: Create a scheduled task that compares current sentiment scores against historical baselines. This allows you to spot anomalies and shifts in public sentiment before they become mainstream, focusing on forming themes like climate vs. silence.

To get started, dive into our documentation at pulsebit.lojenterprise.com/docs. With the provided code examples, you can copy-paste and run this in under 10 minutes, ensuring your pipeline is equipped to catch crucial insights as they develop.

Geographic detection output for climate. India leads with 3
Geographic detection output for climate. India leads with 3 articles and sentiment -0.20. Source: Pulsebit /news_recent geographic fields.

Top comments (0)