DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We just uncovered a striking anomaly in sentiment analysis: a 24h momentum spike of +1.026 around the topic of food. This spike is not just a random blip; it reflects a significant surge in positive sentiment towards food-related narratives, specifically led by English press articles. With a leading language lag of just 0.0h against the dominant entity, Hong Kong, it’s clear this is a signal you cannot afford to ignore.

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

But here’s the catch: if your pipeline isn’t set up to handle multilingual sources or understand entity dominance, you might have missed this critical insight by a staggering 25.4 hours. Your model likely failed to account for the rising sentiment in Hong Kong, which currently holds a 3% share of voice and a neutral sentiment score of +0.012. If you're relying solely on mainstream data sources, you're likely missing these nuanced shifts that can dictate market behavior in real-time.

To bridge this gap, let’s dive into the code that can help us capture and analyze these insights effectively. We’ll use our API to fetch sentiment data with specific parameters.

import requests

# Define parameters for our API call
topic = 'food'
score = +0.127
confidence = 0.85
momentum = +1.026

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


# Geographic origin filter: Fetching data related to food in English
url = "https://api.pulsebit.com/v1/sentiment"
params = {
    "topic": topic,
    "score": score,
    "confidence": confidence,
    "momentum": momentum,
    "lang": "en",
}

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


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

print(data)
Enter fullscreen mode Exit fullscreen mode

Now, let’s enhance our analysis by scoring the narrative framing itself. We’ll run the cluster reason string through our sentiment endpoint:

# Meta-sentiment moment: Analyze the narrative framing
cluster_reason = "Clustered by shared themes: open, menu, food, prices."
sentiment_url = "https://api.pulsebit.com/v1/sentiment"
sentiment_params = {
    "text": cluster_reason,
}

sentiment_response = requests.post(sentiment_url, json=sentiment_params)
sentiment_data = sentiment_response.json()

print(sentiment_data)
Enter fullscreen mode Exit fullscreen mode

By using these API calls, we can get a clearer view of how food sentiment is evolving and how it might influence consumer behavior.

Here are three specific builds we can implement with this pattern:

  1. Real-Time Alert System: Set a threshold for momentum spikes of +0.5 or greater within a 24-hour window using the geo filter. This can help you identify and respond to emerging trends in specific regions, such as Hong Kong, before your competitors do.

  2. Cluster Analysis Dashboard: Use the meta-sentiment loop to score narratives around clustered themes. For instance, track themes like "food" (+0.00) versus mainstream themes like "open" or "menu" to visualize shifts in consumer sentiment over time.

  3. Anomaly Detection: Build a function that flags any topic with a momentum spike greater than +1.0 and a sentiment score above +0.1. This can be particularly useful for tracking the emergence of trends in real time, ensuring you’re always ahead of the curve.

If you want to get started with this, head over to pulsebit.lojenterprise.com/docs. You can copy and paste the code snippets above and run them in under 10 minutes. Don’t let your pipeline fall behind—leverage the power of sentiment analysis to stay informed and agile in a fast-moving landscape.

Top comments (0)