# Sentiment Analyzer: positive, negative and neutral scores (`examsens.ai/sentiment-analyzer`) Actor

Scores the sentiment of texts you supply or of a dataset in your account: positive, negative and neutral probabilities for each text, with optional sentence and aspect detail. The models run inside the actor; no outside service is called.

- **URL**: https://apify.com/examsens.ai/sentiment-analyzer.md
- **Developed by:** [Ed Rayyis](https://apify.com/examsens.ai) (community)
- **Categories:** AI, Marketing
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.60 / 1,000 text analyzeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Sentiment Analyzer: positive, negative and neutral scores

Give it texts, or pick a dataset in your account such as the output of a review scraper, and it returns the sentiment of each text: a label, the positive, neutral and negative probabilities, and a compound score from minus one to one.

The models run inside the actor. No outside service is called and no API key is needed.

- English: `cardiffnlp/twitter-roberta-base-sentiment-latest`, trained on social media posts, released under CC BY 4.0
- Multilingual: `lxyuan/distilbert-base-multilingual-cased-sentiments-student`, released under the Apache 2.0 license

### Detail levels

- Document: one result per text. A text with several sentences is scored sentence by sentence, and the document score is the mean of its sentences, weighted by length.
- Sentences: the document result plus every sentence with its own label and scores.
- Aspects: the sentence detail plus a result for every aspect term you list, such as price, delivery or staff. Each term gets the scores of the sentences that mention it, and `mentions: 0` when no sentence does.

### Input

- Texts: one result per text
- Datasets to analyze: datasets in your account. The run gets read access to the datasets you pick and nothing else.
- Text field (default `text`) and an optional ID field copied to each result as `itemId`
- Maximum items per dataset (default 1,000)
- Model: English (default) or Multilingual
- Detail level and aspect terms

### Output

Dataset: one item per text with `index`, `source` (`input` or the dataset ID), `ok`, `model`, `text`, `label` (`positive`, `neutral` or `negative`), `scores`, `compound` (positive minus negative), `sentenceCount`, and with more detail, `sentences` and `aspects`. Dataset items also carry `itemNumber` and `itemId`. A text that cannot be scored gets `ok: false` and an `error`, and the run carries on. Texts longer than 20,000 characters are scored on their first 20,000 characters, with a `note`.

### Tested

- Short English reviews: positive, negative and neutral sentences each got the expected label from the English model
- A review that praises the food and criticizes the service: food scored positive, service negative, prices neutral, and an unmentioned term returned `mentions: 0`
- Spanish, French and German sentences with the Multilingual model
- A dataset from an earlier run, read through the dataset picker, including an item without the text field
- A 24,000 character text, an empty text
- The maximum charge: texts it does not cover are left unprocessed

The Multilingual model is the weaker of the two. In testing it scored a neutral English sentence and the one word text "Awful." as positive, where the English model returned neutral and negative. Use the English model for English text.

### Speed

With 1 GB of memory, a run that scored two typed texts and three dataset items took 10 seconds.

### Pricing

Pay per event: one event per text scored, at any detail level. Texts that fail are not charged. The run stops scoring when it reaches the maximum charge you set, and the texts left get an error saying so.

### Scope and conduct

Only the texts and datasets you supply are read. Nothing is collected from websites.

### Support

Questions and problems: the Issues tab on this page. Replies are written by an AI assistant on behalf of the developer and reviewed by the developer.

# Actor input Schema

## `texts` (type: `array`):

Reviews, comments, survey answers or any other text you supply. One result per text.

## `datasets` (type: `array`):

Datasets in your account, for example the output of a review scraper. The run gets read access to these datasets only.

## `textField` (type: `string`):

Name of the field that holds the text in each dataset item.

## `idField` (type: `string`):

Optional. A field copied to each result as itemId, so you can join results back to the source.

## `maxDatasetItems` (type: `integer`):

Read at most this many items from each dataset.

## `model` (type: `string`):

Use English for English text. Use Multilingual for text in other languages.

## `level` (type: `string`):

Sentence and aspect detail cost the same as document level.

## `aspects` (type: `array`):

For the Aspects level: words such as price, delivery or staff. Each gets the score of the sentences that mention it.

## Actor input object example

```json
{
  "texts": [
    "I love this phone, the battery lasts all day.",
    "The delivery was late and the box was damaged.",
    "The store opens at nine."
  ],
  "textField": "text",
  "maxDatasetItems": 1000,
  "model": "english",
  "level": "document",
  "aspects": [
    "price",
    "delivery",
    "battery"
  ]
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "texts": [
        "I love this phone, the battery lasts all day.",
        "The delivery was late and the box was damaged.",
        "The store opens at nine."
    ],
    "aspects": [
        "price",
        "delivery",
        "battery"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("examsens.ai/sentiment-analyzer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "texts": [
        "I love this phone, the battery lasts all day.",
        "The delivery was late and the box was damaged.",
        "The store opens at nine.",
    ],
    "aspects": [
        "price",
        "delivery",
        "battery",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("examsens.ai/sentiment-analyzer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "texts": [
    "I love this phone, the battery lasts all day.",
    "The delivery was late and the box was damaged.",
    "The store opens at nine."
  ],
  "aspects": [
    "price",
    "delivery",
    "battery"
  ]
}' |
apify call examsens.ai/sentiment-analyzer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,examsens.ai/sentiment-analyzer"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/f2pDJKVpxnQBGxXsg/builds/GVNviXADr2GTjtbti/openapi.json
