Sentiment Analysis node#
Use the Sentiment Analysis node to analyze the sentiment of incoming text data.
The language model uses the Sentiment Categories in the node options to determine each item's sentiment.
Node parameters#
- Text to Analyze defines the input text for sentiment analysis. This is an expression that references a field from the input items. For example, this could be
{{ $json.chatInput }}
if the input is from a chat or message source. By default, it expects atext
field.
Node options#
- Sentiment Categories: Define the categories that you want to classify your input as.
- By default, these are
Positive, Neutral, Negative
. You can customize these categories to fit your specific use case, such asVery Positive, Positive, Neutral, Negative, Very Negative
for more granular analysis.
- By default, these are
- Include Detailed Results: When turned on, this option includes sentiment strength and confidence scores in the output. Note that these scores are estimates generated by the language model and are rough indicators rather than precise measurements.
- System Prompt Template: Use this option to change the system prompt that's used for the sentiment analysis. It uses the
{categories}
placeholder for the categories. - Enable Auto-Fixing: When enabled, the node automatically fixes model outputs to ensure they match the expected format. Do this by sending the schema parsing error to the LLM and asking it to fix it.
Usage Notes#
Model Temperature Setting#
It's strongly advised to set the temperature of the connected language model to 0 or a value close to 0. This helps ensure that the results are as deterministic as possible, providing more consistent and reliable sentiment analysis across multiple runs.
Language Considerations#
The node's performance may vary depending on the language of the input text.
For best results, ensure your chosen language model supports the input language.
Processing Large Volumes#
When analyzing large amounts of text, consider splitting the input into smaller chunks to optimize processing time and resource usage.
Iterative Refinement#
For complex sentiment analysis tasks, you may need to iteratively refine the system prompt and categories to achieve the desired results.
Example Usage#
Basic Sentiment Analysis#
- Connect a data source (for example, RSS Feed, HTTP Request) to the Sentiment Analysis node.
- Set the "Text to Analyze" field to the relevant item property (for example,
{{ $json.content }}
for blog post content). - Keep the default sentiment categories.
- Connect the node's outputs to separate paths for processing positive, neutral, and negative sentiments differently.
Custom Category Analysis#
- Change the Sentiment Categories to
Excited, Happy, Neutral, Disappointed, Angry
. - Adjust your workflow to handle these five output categories.
- Use this setup to analyze customer feedback with more nuanced emotional categories.
Related resources#
View n8n's Advanced AI documentation.
AI glossary#
- completion: Completions are the responses generated by a model like GPT.
- hallucinations: Hallucination in AI is when an LLM (large language model) mistakenly perceives patterns or objects that don't exist.
- vector database: A vector database stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.
- vector store: A vector store, or vector database, stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.