DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 24.5h Behind: Catching Science Sentiment Leads with Pulsebit

Your pipeline is 24.5 hours behind: catching science sentiment leads with Pulsebit

We recently discovered a compelling anomaly in our data: a 24-hour momentum spike of +0.905 related to a scientific breakthrough. This spike is tied specifically to the Spanish press, which has been leading the conversation about the "golden orb" found two miles deep in the ocean. This surge in sentiment clearly indicates a significant moment in the scientific community that demands our attention.

However, if your model isn't equipped to handle multilingual origins or is dominated by specific entities, you would have completely missed this opportunity. Your pipeline, operating without multilingual filters, missed this spike by a staggering 24.5 hours. The leading language in this case is Spanish, and the dominant narrative was picked up only in certain regions. Without the proper setup, you risk losing critical insights that can shape your understanding of current events.

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

Let’s dive into the code that can help you capture this momentum in real-time. We’ll use our API to query for sentiment data specifically from the Spanish-language articles.

import requests

# Define the parameters for the API call
params = {
    "topic": "science",
    "lang": "sp",  # Spanish language filter
    "score": +0.347,
    "confidence": 0.85,
    "momentum": +0.905
}

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


# Make the API call to fetch relevant articles
response = requests.get('https://api.pulsebit.com/sentiment', params=params)
data = response.json()

# Output the articles processed
print(data['articles_processed'])
Enter fullscreen mode Exit fullscreen mode

Next, we need to analyze the narrative framing around our spike. The cluster reason string reveals key themes that can provide deeper insights. We’ll run this string back through our sentiment analysis to score its framing.

# Define the cluster reason string
cluster_reason = "Clustered by shared themes: finally, found, what, mystery, solve."

# Make the POST request to analyze the narrative
sentiment_response = requests.post('https://api.pulsebit.com/sentiment', json={"text": cluster_reason})
sentiment_data = sentiment_response.json()

# Output the sentiment score for the narrative
print(sentiment_data['sentiment_score'])
Enter fullscreen mode Exit fullscreen mode

This approach gives you a comprehensive view of not just the spike itself but also the themes driving it. Now that we have captured this lead, here are three specific builds you can implement tonight:

  1. Multilingual Article Fetcher: Create a function that queries articles in Spanish where the sentiment score is greater than +0.3. Use the geo filter to ensure you're only pulling relevant content from the Spanish-speaking regions.

  2. Dynamic Theme Tracker: Implement a meta-sentiment loop that takes your clustered themes and scores them daily. Use the cluster reason to pull in new narratives that are resonating within the science community, particularly focusing on narratives like "niti" and "aayog" that are forming.

  3. GAP Analysis Dashboard: Develop a dashboard that visualizes the forming gaps between science and data sentiment versus mainstream narratives. Set thresholds to alert you when sentiment shifts significantly, focusing on the topics of "science," "data," and "Google."

By implementing these builds, you’ll stay ahead of the curve and ensure your insights are timely.

Get started by checking out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run the provided code in under 10 minutes, allowing you to leverage our API effectively and catch those important sentiment spikes as they happen.

Geographic detection output for science. India leads with 4
Geographic detection output for science. India leads with 4 articles and sentiment +0.43. Source: Pulsebit /news_recent geographic fields.

Top comments (0)