# Sentiment Analyzer (`junipr/sentiment-analyzer`) Actor

Analyze text sentiment — positive, negative, neutral, or mixed. Detect emotions (joy, anger, sadness), extract key phrases, detect language. Batch up to 100K texts. Offline NLP, no external AI API.

- **URL**: https://apify.com/junipr/sentiment-analyzer.md
- **Developed by:** [junipr](https://apify.com/junipr) (community)
- **Categories:** AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

$2.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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Sentiment Analyzer

Batch text sentiment analysis with emotion detection, key phrase extraction, and language detection. Processes up to 100,000 texts using offline NLP — no external AI API needed, fast, deterministic, and private.

### Why Use This Actor?

| Feature | This Actor | Google NLP | AWS Comprehend | GPT-based actors |
|---------|-----------|------------|----------------|------------------|
| Price per 1K texts | $2.60 | $1.00-2.00 | $1.00 | $5.00-20.00 |
| External API needed | No | Yes | Yes | Yes |
| Deterministic results | Yes | Yes | Yes | No |
| Speed per text | < 5ms | ~100ms | ~100ms | ~1s |
| Emotion detection | Yes | Partial | No | Yes |
| Zero-config | Yes | Needs key | Needs key | Needs key |
| Data privacy | Full | External API | External API | External API |

At $2.60/1K texts, this actor is 3-13x cheaper than LLM-based alternatives while being 200x faster and fully deterministic. Your text data never leaves Apify infrastructure.

### How to Use

**Zero-config (just provide texts):**
```json
{
  "texts": [
    "This product is amazing! Best purchase ever.",
    "Terrible service, waited 2 hours.",
    "The package arrived on Tuesday."
  ]
}
````

**With ID and metadata:**

```json
{
  "texts": [
    { "id": "review-123", "text": "Love this product!", "metadata": { "source": "amazon" } }
  ]
}
```

**Review analysis pipeline (filter negative reviews):**

```json
{
  "texts": ["... your review texts ..."],
  "onlySentiment": "negative",
  "extractKeyPhrases": true
}
```

### Input Configuration

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `texts` | array | sample texts | Texts to analyze. Plain strings or `{id, text, metadata}` objects. Max 100K. |
| `sentimentModel` | string | `"combined"` | `afinn`, `vader`, or `combined` (most accurate) |
| `detectEmotions` | boolean | `true` | Detect joy, anger, sadness, fear, surprise, disgust |
| `extractKeyPhrases` | boolean | `true` | Extract key phrases contributing to sentiment |
| `detectLanguage` | boolean | `true` | Detect language of each text |
| `neutralThreshold` | number | `0.05` | Compound score range for neutral classification |
| `onlySentiment` | string | null | Filter: `positive`, `negative`, `neutral`, `mixed` |
| `includeWordScores` | boolean | `false` | Per-word sentiment scores |
| `minimumConfidence` | number | `0` | Minimum confidence threshold |

### Output Format

```json
{
  "id": "review-123",
  "text": "This product is amazing!",
  "textLength": 25,
  "language": { "detected": "en", "name": "English", "confidence": 0.9 },
  "sentiment": {
    "label": "positive",
    "compound": 0.8721,
    "positive": 0.8721,
    "negative": 0.0,
    "neutral": 0.1279,
    "confidence": 0.9721
  },
  "emotions": {
    "joy": 0.8, "anger": 0.0, "sadness": 0.0,
    "fear": 0.0, "surprise": 0.1, "disgust": 0.0,
    "dominant": "joy"
  },
  "keyPhrases": [
    { "phrase": "amazing", "sentiment": 1.0, "importance": 0.9 }
  ],
  "analyzedAt": "2026-03-11T12:00:00.000Z"
}
```

#### Sentiment Score Interpretation

| Compound Score | Label | Description |
|----------------|-------|-------------|
| 0.05 to 1.0 | positive | Positive sentiment |
| -0.05 to 0.05 | neutral | No strong sentiment |
| -1.0 to -0.05 | negative | Negative sentiment |
| Both pos & neg > 0.3 | mixed | Contains both positive and negative |

### Tips and Advanced Usage

**Choosing the right model:**

- `combined` (default) — Best accuracy, uses AFINN + VADER ensemble
- `vader` — Better for social media with emojis, slang, caps, punctuation
- `afinn` — Fastest, purely lexicon-based

**Adjusting neutral threshold:**

- Default `0.05` works well for most use cases
- Increase to `0.15-0.20` for stricter positive/negative classification

**Handling sarcasm:** Lexicon-based analysis cannot reliably detect sarcasm ("Oh great, another delay"). For sarcasm, consider LLM-based tools.

**Multi-language:** Works best with English. 20+ languages supported via translated lexicons with lower accuracy.

### Pricing

**Pay-Per-Event:** $0.0026 per text analyzed ($2.60 per 1,000 texts)

Pricing includes all platform compute costs — no hidden fees.

| Scenario | Texts | Cost |
|----------|-------|------|
| Product reviews batch (500) | 500 | $1.30 |
| Twitter mentions (5,000) | 5,000 | $13.00 |
| Customer feedback (20,000) | 20,000 | $52.00 |
| Monthly monitoring (100,000) | 100,000 | $260.00 |

### Related Actors

- [Finance News Scraper](https://apify.com/junipr/finance-news-scraper) — Pair with sentiment for financial signal detection
- [Google News Scraper](https://apify.com/junipr/google-news-scraper) — News to analyze with sentiment

### FAQ

#### How accurate is the sentiment analysis?

For standard review and social media text, lexicon-based approaches achieve 75-85% accuracy vs LLM methods (80-90%). For most business use cases, this difference is negligible at a 10x cost saving.

#### Does it detect sarcasm?

No. Sarcasm detection requires contextual understanding that lexicon-based NLP cannot reliably provide. Document this limitation for your users.

#### What languages are supported?

English is the primary language with highest accuracy. 20+ other languages are supported via translated lexicons with moderate accuracy.

#### Can I analyze social media posts with emojis?

Yes — emoji sentiment mapping is built in. Common emojis are mapped to sentiment values.

#### What's the difference between AFINN and VADER models?

AFINN: lexicon-based word scoring, fast and simple. VADER: rule-based with negation handling, emphasis (CAPS, !!!), and emoji support — better for social media.

#### How does emotion detection work?

Emotion detection uses a word-emotion association lexicon. Each word is mapped to one of 6 emotions. The dominant emotion is the one most frequently detected in the text.

# Actor input Schema

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

List of texts to analyze. Each can be a plain string or an object with 'text' and optional 'id' fields. Max 100,000 texts.

## `detectEmotions` (type: `boolean`):

Detect specific emotions (joy, anger, sadness, fear, surprise, disgust) in addition to sentiment polarity.

## `extractKeyPhrases` (type: `boolean`):

Extract key phrases/words that contribute most to the sentiment score.

## `detectLanguage` (type: `boolean`):

Detect language of each text. Analysis quality is best for English.

## `sentimentModel` (type: `string`):

Sentiment analysis approach: afinn (AFINN-165 lexicon), vader (rules-based), combined (ensemble — most accurate).

## `neutralThreshold` (type: `number`):

Compound score between -threshold and +threshold is classified as neutral. Min: 0.01, Max: 0.30.

## `includeWordScores` (type: `boolean`):

Include per-word sentiment scores in output (detailed breakdown).

## `onlySentiment` (type: `string`):

Filter output to only texts matching this sentiment: positive, negative, neutral, mixed. Leave empty for all.

## `minimumConfidence` (type: `number`):

Only output results with confidence >= this threshold. Min: 0, Max: 1.

## Actor input object example

```json
{
  "texts": [
    "This product is amazing! Best purchase I've ever made.",
    "Terrible service, waited 2 hours and nobody helped.",
    "The package arrived on Tuesday as expected."
  ],
  "detectEmotions": true,
  "extractKeyPhrases": true,
  "detectLanguage": true,
  "sentimentModel": "combined",
  "neutralThreshold": 0.05,
  "includeWordScores": false,
  "minimumConfidence": 0
}
```

# Actor output Schema

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

One sentiment analysis result per input text.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("junipr/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 = {}

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

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

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

```

## CLI example

```bash
echo '{}' |
apify call junipr/sentiment-analyzer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=junipr/sentiment-analyzer",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Sentiment Analyzer",
        "description": "Analyze text sentiment — positive, negative, neutral, or mixed. Detect emotions (joy, anger, sadness), extract key phrases, detect language. Batch up to 100K texts. Offline NLP, no external AI API.",
        "version": "1.0",
        "x-build-id": "l17GI9Gd2UARiYICr"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/junipr~sentiment-analyzer/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-junipr-sentiment-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/junipr~sentiment-analyzer/runs": {
            "post": {
                "operationId": "runs-sync-junipr-sentiment-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/junipr~sentiment-analyzer/run-sync": {
            "post": {
                "operationId": "run-sync-junipr-sentiment-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "texts": {
                        "title": "Texts to Analyze",
                        "type": "array",
                        "description": "List of texts to analyze. Each can be a plain string or an object with 'text' and optional 'id' fields. Max 100,000 texts.",
                        "items": {
                            "type": "string"
                        },
                        "default": [
                            "This product is amazing! Best purchase I've ever made.",
                            "Terrible service, waited 2 hours and nobody helped.",
                            "The package arrived on Tuesday as expected."
                        ]
                    },
                    "detectEmotions": {
                        "title": "Detect Emotions",
                        "type": "boolean",
                        "description": "Detect specific emotions (joy, anger, sadness, fear, surprise, disgust) in addition to sentiment polarity.",
                        "default": true
                    },
                    "extractKeyPhrases": {
                        "title": "Extract Key Phrases",
                        "type": "boolean",
                        "description": "Extract key phrases/words that contribute most to the sentiment score.",
                        "default": true
                    },
                    "detectLanguage": {
                        "title": "Detect Language",
                        "type": "boolean",
                        "description": "Detect language of each text. Analysis quality is best for English.",
                        "default": true
                    },
                    "sentimentModel": {
                        "title": "Sentiment Model",
                        "enum": [
                            "afinn",
                            "vader",
                            "combined"
                        ],
                        "type": "string",
                        "description": "Sentiment analysis approach: afinn (AFINN-165 lexicon), vader (rules-based), combined (ensemble — most accurate).",
                        "default": "combined"
                    },
                    "neutralThreshold": {
                        "title": "Neutral Threshold",
                        "minimum": 0.01,
                        "maximum": 0.3,
                        "type": "number",
                        "description": "Compound score between -threshold and +threshold is classified as neutral. Min: 0.01, Max: 0.30.",
                        "default": 0.05
                    },
                    "includeWordScores": {
                        "title": "Include Word Scores",
                        "type": "boolean",
                        "description": "Include per-word sentiment scores in output (detailed breakdown).",
                        "default": false
                    },
                    "onlySentiment": {
                        "title": "Filter by Sentiment",
                        "enum": [
                            "positive",
                            "negative",
                            "neutral",
                            "mixed"
                        ],
                        "type": "string",
                        "description": "Filter output to only texts matching this sentiment: positive, negative, neutral, mixed. Leave empty for all."
                    },
                    "minimumConfidence": {
                        "title": "Minimum Confidence",
                        "minimum": 0,
                        "maximum": 1,
                        "type": "number",
                        "description": "Only output results with confidence >= this threshold. Min: 0, Max: 1.",
                        "default": 0
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
