DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 28.6h Behind: Catching Sustainability Sentiment Leads with Pulsebit

Your Pipeline Is 28.6h Behind: Catching Sustainability Sentiment Leads with Pulsebit

We just discovered that our sentiment analysis is showing a spike: sentiment is at +0.033 and momentum is flat at +0.000. What’s particularly notable here is that the leading language is English, with a 28.6-hour delay in recognizing this trend compared to the original sentiment from Evanston Township High School’s sustainability initiatives. This indicates that our pipeline isn't adjusting quickly enough to emerging themes in sustainability, which could be a significant oversight.

The Problem

Your model missed this by 28.6 hours. If you're not handling multilingual origin or entity dominance, you risk falling behind. The leading language here is English, which means that any sentiment analysis that doesn’t incorporate this data promptly will lag in delivering accurate insights. This gap not only affects your analytics but could lead to missed opportunities in understanding and reacting to public sentiment on critical issues like sustainability.

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

The Code

To catch this sentiment spike, we’ll leverage our API to query the relevant data. Below is a succinct Python script that demonstrates how to filter by language and process the sentiment of the cluster narrative.

import requests

# Parameters for the API call
topic = 'sustainability'
score = +0.033
confidence = 0.85
momentum = +0.000

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


# Step 1: Geographic origin filter
url = "https://api.pulsebit.com/v1/sentiment"
params = {
    "topic": topic,
    "lang": "en"  # Filter for English language
}
response = requests.get(url, params=params)
results = response.json()

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


# Extracted data for further processing
sentiment_score = results['sentiment_score']
print(f"Sentiment Score: {sentiment_score}")

# Step 2: Meta-sentiment moment
meta_narrative = "Clustered by shared themes: evanston, township, high, school, sustainability."
meta_response = requests.post(url, json={"text": meta_narrative})
meta_results = meta_response.json()

# Processed meta sentiment score
meta_sentiment_score = meta_results['sentiment_score']
print(f"Meta Sentiment Score: {meta_sentiment_score}")
Enter fullscreen mode Exit fullscreen mode

In the code above, we first filter the sentiment data by language using the lang parameter set to "en", which ensures we’re only working with English-language sources. Then we run the cluster narrative through the sentiment endpoint again, allowing us to score how effectively this narrative is framing the discussion around sustainability.

Three Builds Tonight

Here are three specific things you can build using this pattern:

  1. Geographic Sentiment Dashboard: Use the geographic origin filter to create a sentiment dashboard that tracks sustainability sentiment across different regions. Set a signal threshold of +0.030 to trigger alerts when sentiment rises significantly.

  2. Meta-Sentiment Analysis Tool: Build a tool that uses the meta-sentiment loop to assess how narratives are evolving. For instance, you could input narratives like "Clustered by shared themes: sustainability, innovation, community" and analyze shifts in sentiment over time.

  3. Forming Theme Tracker: Set up a tracker for forming themes such as sustainability(+0.00), Google(+0.00), and Africa(+0.00) vs. mainstream topics like Evanston, Township, High. Use the sentiment scores to identify when these topics start gaining traction and adjust your content strategy accordingly.

Get Started

You can dive right in and start building. Check out our API documentation at pulsebit.lojenterprise.com/docs. You should be able to copy-paste the code above and run it in under 10 minutes. Let's catch up on that 28.6-hour delay in sentiment!

Top comments (0)