DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 26.9h Behind: Catching Human Rights Sentiment Leads with Pulsebit

Your Pipeline Is 26.9h Behind: Catching Human Rights Sentiment Leads with Pulsebit

A 24-hour momentum spike of +0.440 in sentiment around the topic of human rights has emerged, primarily driven by discussions surrounding a Human Rights Ordinance in East Lansing. This spike, led by English press with a near-zero lag, indicates a noteworthy shift in public sentiment that your current pipeline may not be capturing effectively. The anomaly reveals how quickly sentiment can evolve, and in this case, it’s crucial for responding to emerging trends.

If your model isn’t equipped to handle multilingual inputs or recognize dominant entities, you might have missed this crucial spike by a staggering 26.9 hours. The leading language here is English, showcasing that while your system may be robust, it’s lagging significantly in recognizing timely sentiment shifts. As developers, we know that missing out on such key insights can lead to missed opportunities for engagement or action.

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

Here’s how we can catch that sentiment spike in our analysis. We can leverage our API to filter for the geographic origin and run a sentiment analysis on the cluster of articles discussing the human rights topic.

Geographic detection output for human rights. Hong Kong lead
Geographic detection output for human rights. Hong Kong leads with 1 articles and sentiment -0.70. Source: Pulsebit /news_recent geographic fields.

import requests

# Set up parameters for the API call
topic = 'human rights'
score = +0.250
confidence = 0.85
momentum = +0.440

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


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

# Check if the request was successful
if response.status_code == 200:
    data = response.json()
    print("Data fetched successfully:", data)
else:
    print("Failed to fetch data:", response.status_code)

# Run meta-sentiment analysis using the cluster reason
cluster_reason = "Clustered by shared themes: lansing, residents, invited, discuss, human."
meta_response = requests.post("https://api.pulsebit.com/v1/sentiment",
                               json={"text": cluster_reason})

# Check if the meta-sentiment request was successful
if meta_response.status_code == 200:
    meta_data = meta_response.json()
    print("Meta-sentiment data:", meta_data)
else:
    print("Failed to fetch meta-sentiment data:", meta_response.status_code)
Enter fullscreen mode Exit fullscreen mode

In this code, we first filter the sentiment data by the English language to focus on the relevant articles. Then, we perform a meta-sentiment analysis on the cluster reason string to derive insights about how the narrative around human rights is framed. This two-step approach allows us to align our findings closely with the emerging sentiment.

Now that we have a process to capture this sentiment, we can build specific features that’ll keep us ahead of the curve. Here are three builds to consider:

  1. Sentiment Alert System: Create an alert that triggers when sentiment momentum exceeds a threshold of +0.400, specifically for the topic of "human rights." This can help you react quickly to rising discussions.

  2. Geo-Filtered Reporting: Implement a reporting system that uses the geographic origin filter with a focus on English-speaking regions, allowing you to generate reports that highlight emerging trends in specific demographics.

  3. Meta-Sentiment Dashboard: Build a dashboard that visualizes meta-sentiment metrics using the cluster reason strings, such as "Clustered by shared themes: lansing, residents, invited, discuss, human." This can provide deeper insights into how narratives are shaped in different contexts.

To get started with building these features, check out our documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run the provided code snippets in under 10 minutes to start capturing valuable sentiment insights today.

Top comments (0)