Skip to content

Commit

Permalink
Add docs for Sentiment Analysis Node
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegIvaniv committed Jul 25, 2024
1 parent 9dcd77b commit d05693a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/advanced-ai/langchain/langchain-n8n.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Available nodes:
* [Basic LLM Chain](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainllm/)
* [Retrieval Q&A Chain](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa/)
* [Summarization Chain](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainsummarization/)
* [Sentiment Analysis](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.sentimentanalysis/)
* [Text Classifier](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-classifier/)

Learn more about [Chains in LangChain](https://js.langchain.com/docs/modules/chains/){:target=_blank .external-link}.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
#https://www.notion.so/n8n/Frontmatter-432c2b8dff1f43d4b1c8d20075510fe4
title: Sentiment Analysis
description: Documentation for the Sentiment Analysis node in n8n, a workflow automation platform. Includes details of operations and configuration, and links to examples and credentials information.
contentType: integration
---

# Sentiment Analysis

Use the Sentiment Analysis node to analyze the sentiment of incoming text data. Using the
categories provided in the parameters (see below), each item is passed to the
language model to determine its sentiment.

## Node parameters

**Text to Analyze** defines the input text for sentiment analysis. This is usually 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 a `text` 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 as "Very Positive, Positive, Neutral, Negative, Very Negative"
for more granular analysis.

* **Include Detailed Results**: When enabled, this option includes sentiment strength and
confidence scores in the output. Note that these scores are estimates generated by the
language model and should be interpreted as rough indicators rather than precise measurements.

* **System Prompt Template**: This option allows you 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, this option allows the node to automatically fix model outputs to ensure they match the expected format. This is done by sending the schema parsing error to the LLM and asking it to fix it.

## Usage Notes

1. **Model Temperature Setting**: It is strongly advised to set the temperature of the connected language model to 0 or a value very close to 0. This helps ensure that the results are as deterministic as possible, providing more consistent and reliable sentiment analysis across multiple runs.

2. **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.

3. **Processing Large Volumes**: When analyzing large amounts of text, consider splitting the input into smaller chunks to optimize processing time and resource usage.

4. **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
1. Connect a data source (e.g., RSS Feed, HTTP Request) to the Sentiment Analysis node.
2. Set the "Text to Analyze" field to the relevant item property (e.g., `{{ $json.content }}` for blog post content).
3. Keep the default sentiment categories.
4. Connect the node's outputs to separate paths for processing positive, neutral, and negative sentiments differently.

### Custom Category Analysis
1. Modify the "Sentiment Categories" to "Excited, Happy, Neutral, Disappointed, Angry".
2. Adjust your workflow to handle these five output categories.
3. Use this setup to analyze customer feedback with more nuanced emotional categories.

## Related resources

--8<-- "_snippets/integrations/builtin/cluster-nodes/langchain-overview-link.md"
--8<-- "_glossary/ai-glossary.md"
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ nav:
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa.md
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainsummarization.md
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-classifier.md
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.sentimentanalysis.md
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.code.md
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoreinmemory.md
- integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstorepinecone.md
Expand Down

0 comments on commit d05693a

Please sign in to comment.