DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 22.4h Behind: Catching World Sentiment Leads with Pulsebit

Your model missed a significant anomaly: a 24h momentum spike of +0.210. This spike is particularly intriguing as it reveals a burgeoning sentiment around mental health, encapsulated in the cluster story "World Brain Day: Mental health is as important as physical health, says Ballari." With only one article contributing to this spike, the narrow focus highlights a specific sentiment shift that may have flown under your radar. If you’re not filtering for multilingual data or dominant entities, your pipeline is missing critical trends.

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

This situation exposes a structural gap in any pipeline that does not adequately handle multilingual origins or entity dominance. If your model isn't tracking sentiment accurately across languages, you might find yourself 22.4 hours behind the curve in recognizing emerging trends. In this case, English press coverage led the sentiment spike, while your system could be lagging if it primarily focuses on a single language or a limited set of entities.

Let’s dive into the code that can help you catch these insights in real-time. First, we’ll filter by the geographic origin using our API to ensure we’re only pulling English-language articles. Here’s how to set that up:

Geographic detection output for world. India leads with 31 a
Geographic detection output for world. India leads with 31 articles and sentiment +0.45. Source: Pulsebit /news_recent geographic fields.

import requests

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


# Define our parameters
params = {
    "topic": "world",
    "score": +0.156,
    "confidence": 0.90,
    "momentum": +0.210,
    "lang": "en"  # Filter by English
}

# Call the endpoint to get relevant articles
response = requests.get("https://api.pulsebit.com/articles", params=params)
articles = response.json()

print(f"Retrieved {len(articles)} articles related to the world topic.")
Enter fullscreen mode Exit fullscreen mode

Next, we want to score the narrative framing using our sentiment analysis endpoint. This will allow us to understand the underlying sentiments that contribute to the spike. Here’s how you can do that:

# Define the narrative string
narrative_string = "Clustered by shared themes: brain, health, world, day:, mental."

# Call the sentiment analysis endpoint
sentiment_response = requests.post("https://api.pulsebit.com/sentiment", json={"text": narrative_string})
sentiment_score = sentiment_response.json()

print(f"Sentiment Score for the narrative: {sentiment_score['score']}")
Enter fullscreen mode Exit fullscreen mode

Now that we've set up the core logic, let’s explore three specific things to build with this pattern. First, you could set a signal threshold for momentum spikes greater than +0.200 to catch similar sentiments early. Use the geo filter we established to capture only English articles.

Second, implement a meta-sentiment loop that identifies cluster stories with high sentiment scores, particularly around themes like mental health. This could leverage the narrative from our previous POST request, helping to frame the content more effectively.

Lastly, consider forming a composite index that takes into account related themes like "world," "cup," and "after," while monitoring their sentiment against mainstream topics such as "brain" and "health." This can help you identify when emerging narratives might be gaining traction or diverging from expected sentiments.

For more details on how to implement these features, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run this code in under 10 minutes, giving you the ability to catch sentiment leads as they emerge.

Top comments (0)