DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 20.4h Behind: Catching Food Sentiment Leads with Pulsebit

Your Pipeline Is 20.4h Behind: Catching Food Sentiment Leads with Pulsebit

We recently encountered a striking anomaly: a 24h momentum spike of -0.850 related to food sentiment. This finding, which emerged from our analysis of news coverage, points to a significant shift in public interest, specifically regarding the story "Hyderabad Police arrest 64 persons, seize 15 tonnes of adulterated food products." This spike is not just a number; it's a signal that there's a developing narrative around food that needs our attention.

When your pipeline fails to account for multilingual origins or dominant entities, crucial insights slip through the cracks. In this case, our model missed the action by 20.4 hours. The leading language in this scenario was English, but the dominant entity — Hyderabad and its police — should have raised red flags long before this story broke. If you're relying solely on English metrics, you might be lagging behind in a fast-moving sentiment landscape.

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

To catch this spike, we can leverage our API effectively. Below is the Python code that demonstrates how to filter for English-language content and analyze the sentiment around the identified cluster.

import requests

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


# Step 1: Geographic origin filter
topic = 'food'
lang = 'en'
url = f"https://api.pulsebit.com/v1/sentiment?topic={topic}&lang={lang}"

![Geographic detection output for food. India leads with 5 art](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1774913968878.png)
*Geographic detection output for food. India leads with 5 articles and sentiment +0.49. Source: Pulsebit /news_recent geographic fields.*


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

# Extracting the relevant score
momentum = -0.850
sentiment_score = +0.388
confidence = 0.90

# Step 2: Meta-sentiment moment
cluster_reason = "Clustered by shared themes: hyderabad, police, tonnes, adulterated, food."
meta_sentiment_url = "https://api.pulsebit.com/v1/sentiment"
meta_response = requests.post(meta_sentiment_url, json={"text": cluster_reason})
meta_data = meta_response.json()

print(f"Sentiment Score: {sentiment_score}, Confidence: {confidence}, Meta Sentiment: {meta_data}")
Enter fullscreen mode Exit fullscreen mode

This script performs two crucial operations: it first queries for sentiment data filtered by English-language articles and then scores the narrative framing itself using the cluster reason. This dual approach allows us to not only identify a spike but also understand the context that surrounds it, which is essential for making informed decisions.

With this spike in mind, here are three specific builds you might consider implementing:

  1. Geo-filtered signal detection: Regularly monitor sentiment on food-related topics specifically in English-speaking regions, using a threshold momentum score of -0.850 to trigger alerts for potential newsworthy events.

  2. Meta-sentiment narrative scoring: Create a function that sends the cluster reason through our sentiment endpoint to gauge potential narrative shifts. This could help you identify emerging themes, especially when they cluster around critical events like food safety.

  3. Forming theme analysis: Develop a dashboard that visualizes forming themes like food, Google, and fast in relation to dominant narratives like Hyderabad, police, and tonnes. This can help you track evolving sentiments and prepare for possible market shifts.

If you want to dive deeper into this data and start building your own insights, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy, paste, and run the code above in under 10 minutes, setting you on the path to catching sentiment leads before they become mainstream.

Top comments (0)