DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 12.7h Behind: Catching Defence Sentiment Leads with Pulsebit

Your Pipeline Is 12.7h Behind: Catching Defence Sentiment Leads with Pulsebit

We recently observed a significant anomaly: a 24-hour momentum spike of +0.425 in sentiment related to the topic of defence. This spike was notably led by English press coverage, which showed a 12.7-hour lead time. This finding indicates that there’s a substantial shift in sentiment that your current models might be missing if they aren't designed to handle multilingual origins or entity dominance effectively.

English coverage led by 12.7 hours. Et at T+12.7h. Confidenc
English coverage led by 12.7 hours. Et at T+12.7h. Confidence scores: English 0.95, French 0.95, No 0.95 Source: Pulsebit /sentiment_by_lang.

When you think about it, your sentiment analysis pipeline potentially missed this key insight by 12.7 hours due to its inability to process and prioritize information from various languages or dominant entities. The leading article, "Taiwanese lawmakers spar over 12-fold budget rise for US joint defence programme," aligns closely with the observed spike. If your model is not tuned to address these nuances, you're likely lagging behind crucial developments in sentiment shifts, especially in high-stakes areas like defence.

To catch this momentum spike, we can use our API to create a targeted query. Here's how you can capture the relevant sentiment data in Python:

import requests

# Define parameters for the API call
topic = 'defence'
score = -0.009
confidence = 0.95
momentum = +0.425

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


# Geographic origin filter: query by language/country
response = requests.get(
    "https://api.pulsebit.com/sentiment",
    params={
        "topic": topic,
        "lang": "en",
        "score": score,
        "confidence": confidence
    }
)

![Geographic detection output for defence. Hong Kong leads wit](https://pub-c3309ec893c24fb9ae292f229e1688a6.r2.dev/figures/g3_geo_output_1781002788413.png)
*Geographic detection output for defence. Hong Kong leads with 7 articles and sentiment -0.37. Source: Pulsebit /news_recent geographic fields.*


# Check the response
data = response.json()
print(data)
Enter fullscreen mode Exit fullscreen mode

Next, we need to evaluate the narrative framing of the sentiment with the meta-sentiment moment. By sending the cluster reason string back through our sentiment endpoint, we can gauge how the themes are being perceived. This is the crux of our analysis:

# Define the cluster reason string
cluster_reason = "Clustered by shared themes: defence, programme, its, over, budget."

# Call the sentiment API to score the narrative framing
meta_response = requests.post(
    "https://api.pulsebit.com/sentiment",
    json={
        "text": cluster_reason
    }
)

# Check the response
meta_data = meta_response.json()
print(meta_data)
Enter fullscreen mode Exit fullscreen mode

By employing this approach, you're not just reacting to sentiment; you're actively shaping your narrative understanding based on real-time data.

We can build three specific applications using this pattern:

  1. Geographic Origin Filter: Set a threshold to capture sentiment spikes specifically in English language articles. For instance, if the sentiment score exceeds a threshold of -0.005, trigger an alert for further investigation.

  2. Meta-Sentiment Loop: After scoring the cluster reason, if the resulting sentiment score is above 0.01, consider it a signal to deepen your analysis of defence-related articles. This helps you gauge public sentiment and media framing effectively.

  3. Forming Themes Analysis: Establish a monitoring signal for topics like "defence(+0.00)," "google(+0.00)," and "plan(+0.00)" compared to mainstream narratives. If these form a significant positive deviation, it could suggest emerging opportunities or risks.

If you’re ready to take your sentiment analysis to the next level, you can find all the necessary information at pulsebit.lojenterprise.com/docs. With this setup, you can copy, paste, and run these examples in under 10 minutes, ensuring that you’re always ahead of the curve in understanding the nuances of sentiment data.

Top comments (0)