DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

We just uncovered a compelling anomaly in our data: a 24h momentum spike of -1.193 around human rights sentiment. This drop indicates a significant shift in discourse, especially when we consider that the leading language for this sentiment analysis is English, with a lag of 26.2 hours. This highlights just how far behind your pipeline might be if it isn't equipped to handle multilingual sources or dominant entities effectively.

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

Imagine your sentiment model, built to react swiftly to emerging trends, missing a critical shift in human rights discussions by over 26 hours. The dominant entity here is Stephen Lewis, a recognized advocate in this space. If your pipeline is only processing data in a single language or failing to recognize significant figures, you risk missing crucial narratives that could inform your strategies or decisions.

To catch this anomaly, we need to implement a Python script that leverages our API effectively. Below is the code that retrieves relevant articles filtered by language, scores the sentiment, and gives us insights into the prevailing narrative:

import requests

# Set the parameters for the API call
topic = 'human rights'
score = -0.700
confidence = 0.85
momentum = -1.193
lang = 'en'

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


# Step 1: Geographic origin filter
url = f"https://api.pulsebit.com/v1/articles?topic={topic}&lang={lang}"
response = requests.get(url)
articles = response.json()

# Display the returned articles
print(articles)

# Step 2: Meta-sentiment moment
cluster_reason = "Clustered by shared themes: rights, advocate, stephen, lewis, fought."
sentiment_url = "https://api.pulsebit.com/v1/sentiment"
sentiment_response = requests.post(sentiment_url, json={"text": cluster_reason})
sentiment_analysis = sentiment_response.json()

# Display the sentiment analysis result
print(sentiment_analysis)
Enter fullscreen mode Exit fullscreen mode

The first step queries our articles based on the topic of "human rights" while filtering for English-language content. This is crucial to ensure we're capturing the right discussions that are relevant to the sentiment shift. The second part of the code sends the cluster reason string back through the sentiment endpoint to assess how the narrative is framed. This step is essential because it helps us understand not just the sentiment score but the context around it, which can significantly inform our approach to the issue at hand.

Now that we have the foundational code, let's discuss three concrete builds we can implement based on this pattern:

  1. Sentiment Signal Monitoring: Create a real-time monitoring system that triggers alerts when momentum drops below a certain threshold, say -1.5 for topics like human rights. Use the geographic filter to ensure you're only capturing relevant discussions in English.

Geographic detection output for human rights. India leads wi
Geographic detection output for human rights. India leads with 5 articles and sentiment -0.59. Source: Pulsebit /news_recent geographic fields.

  1. Meta-Sentiment Analysis Dashboard: Build a dashboard that visualizes the meta-sentiment analysis results for clustered themes. For instance, track the evolving narratives around "rights," "human," and "google" versus mainstream discussions. This can help identify emerging stories before they become mainstream.

  2. Entity Influence Tracking: Develop a feature that tracks the influence of key figures like Stephen Lewis over time. By analyzing the sentiment around articles featuring him, we can gauge how his advocacy impacts public perception and sentiment in the human rights space.

If you want to dive deeper into building these features, check out our documentation: pulsebit.lojenterprise.com/docs. You can copy this code and run it in under 10 minutes to start catching these critical insights in your workflows.

Top comments (0)