Sentiment Analysis API

by Stanford NLP 161

This sentiment analysis API extracts sentiment in a given string of text. Sentiment analysis, also called 'opinion mining', uses natural language processing, text analysis and computational linguistics to identify and detect subjective information from the input text. This algorithm classifies each sentence in the input as very negative, negative, neutral, positive, or very positive.

url upload file upload


API Docs
QUICK START API REQUEST
curl \
    -F 'text=YOUR_TEXT_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/sentiment-analysis 

Sentiment Analysis

automated at scale

Extract sentiment from massive datasets of text quickly.

Opinion Mining

with deep learning

Use this sentiment analysis model to extract sentiment from every sentence.

Text Mining

with sentiment analysis

With a sentiment analysis API, you can mine bodies of text to extract sentiment with ease.

Algorithmic Trading using Sentiment Analysis on News Articles

Using sentiment analysis, you can weight the overall positivity or negativity of a news article based on sentiment extracted sentence-by-sentence. With this subjective information extracted from either the article headline or news article text, you can weight news sentiment into you algorithmic trading strategy to better optimize buying and selling decisions.


Extract Sentiment from Customer Reviews

Analyze the sentiment of customer reviews or survey responses at scale with automatic sentiment analysis. You can weight the overall sentiment of the text by averaging the predicted sentiment of each sentence in a user's review, or by analyzing the review headline.


Sentiment Analysis API Documentation

Sentiment Analysis cURL Examples

# Example posting a text URL:

curl \
    -F 'text=YOUR_TEXT_URL' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/sentiment-analysis 


# Example posting a local text file:

curl \
    -F 'text=@/path/to/your/file.txt' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/sentiment-analysis 


# Example directly sending a text string:

curl \
    -F 'text=YOUR_TEXT_HERE' \
    -H 'api-key:YOUR_API_KEY' \
    https://api.deepai.org/api/sentiment-analysis 

Sentiment Analysis Javascript Examples

// Get the 'deepai' package here (Compatible with browser & nodejs):
//     https://www.npmjs.com/package/deepai
// All examples use JS async-await syntax, be sure to call the API inside an async function.
//     Learn more about async-await here: https://javascript.info/async-await

// Example posting a text URL:

const deepai = require('deepai'); // OR include deepai.min.js as a script tag in your HTML

deepai.setApiKey('YOUR_API_KEY');

(async function() {
    var resp = await deepai.callStandardApi("sentiment-analysis", {
            text: "YOUR_TEXT_URL",
    });
    console.log(resp);
})()


// Example posting file picker input text (Browser only):

const deepai = require('deepai'); // OR include deepai.min.js as a script tag in your HTML

deepai.setApiKey('YOUR_API_KEY');

(async function() {
    var resp = await deepai.callStandardApi("sentiment-analysis", {
            text: document.getElementById('yourFileInputId'),
    });
    console.log(resp);
})()


// Example posting a local text file (Node.js only):
const fs = require('fs');

const deepai = require('deepai'); // OR include deepai.min.js as a script tag in your HTML

deepai.setApiKey('YOUR_API_KEY');

(async function() {
    var resp = await deepai.callStandardApi("sentiment-analysis", {
            text: fs.createReadStream("/path/to/your/file.txt"),
    });
    console.log(resp);
})()


// Example directly sending a text string:

const deepai = require('deepai'); // OR include deepai.min.js as a script tag in your HTML

deepai.setApiKey('YOUR_API_KEY');

(async function() {
    var resp = await deepai.callStandardApi("sentiment-analysis", {
            text: "YOUR_TEXT_HERE",
    });
    console.log(resp);
})()

Sentiment Analysis Python Examples

# Ensure your pyOpenSSL pip package is up to date
# Example posting a text URL:

import requests
r = requests.post(
    "https://api.deepai.org/api/sentiment-analysis",
    data={
        'text': 'YOUR_TEXT_URL',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example posting a local text file:

import requests
r = requests.post(
    "https://api.deepai.org/api/sentiment-analysis",
    files={
        'text': open('/path/to/your/file.txt', 'rb'),
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())


# Example directly sending a text string:

import requests
r = requests.post(
    "https://api.deepai.org/api/sentiment-analysis",
    data={
        'text': 'YOUR_TEXT_HERE',
    },
    headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())

Sentiment Analysis Ruby Examples

# Example posting a text URL:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/sentiment-analysis', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_URL',
    }
)
puts r


# Example posting a local text file:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/sentiment-analysis', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => File.new('/path/to/your/file.txt'),
    }
)
puts r


# Example directly sending a text string:

require 'rest_client'
r = RestClient::Request.execute(method: :post, url: 'https://api.deepai.org/api/sentiment-analysis', timeout: 600,
    headers: {'api-key' => 'YOUR_API_KEY'},
    payload: {
        'text' => 'YOUR_TEXT_HERE',
    }
)
puts r

Sentiment Analysis Csharp Examples

// Ensure your DeepAI.Client NuGet package is up to date: https://www.nuget.org/packages/DeepAI.Client
// Example posting a text URL:

using DeepAI; // Add this line to the top of your file

DeepAI_API api = new DeepAI_API(apiKey: "YOUR_API_KEY");

StandardApiResponse resp = api.callStandardApi("sentiment-analysis", new {
        text = "YOUR_TEXT_URL",
});
Console.Write(api.objectAsJsonString(resp));


// Example posting a local text file:

using DeepAI; // Add this line to the top of your file

DeepAI_API api = new DeepAI_API(apiKey: "YOUR_API_KEY");

StandardApiResponse resp = api.callStandardApi("sentiment-analysis", new {
        text = File.OpenRead("C:\\path\\to\\your\\file.txt"),
});
Console.Write(api.objectAsJsonString(resp));


// Example directly sending a text string:

using DeepAI; // Add this line to the top of your file

DeepAI_API api = new DeepAI_API(apiKey: "YOUR_API_KEY");

StandardApiResponse resp = api.callStandardApi("sentiment-analysis", new {
        text = "YOUR_TEXT_HERE",
});
Console.Write(api.objectAsJsonString(resp));