Class SentimentAnalysis
- Namespace
- LMKit.TextAnalysis
- Assembly
- LM-Kit.NET.dll
Provides functionality for performing sentiment analysis on plain text, designed to assess and categorize emotional tone.
public sealed class SentimentAnalysis
- Inheritance
-
SentimentAnalysis
- Inherited Members
Examples
using LMKit.TextAnalysis;
using LMKit.Model;
using System;
// Initialize the language model (LLM) using the specified model path
LLM languageModel = new LLM("https://huggingface.co/lm-kit/lm-kit-sentiment-analysis-2.0-1b-gguf/resolve/main/lm-kit-sentiment-analysis-2.0-1b-q4.gguf?download=true");
// Create an instance of SentimentAnalysis
SentimentAnalysis sentimentAnalyzer = new SentimentAnalysis(languageModel);
// Analyze text sentiment
string text = "I absolutely love this product! It exceeded my expectations.";
SentimentCategory sentiment = sentimentAnalyzer.GetSentimentCategory(text);
Console.WriteLine($"Sentiment: {sentiment}");
// Output: "Sentiment: Positive"
Remarks
The SentimentAnalysis class uses a language model to analyze textual content and determine its sentiment category. It supports both synchronous and asynchronous operations and allows for fine-tuning with custom training data.
Constructors
- SentimentAnalysis(LLM)
Initializes a new instance of the SentimentAnalysis class.
Properties
- Confidence
Gets the confidence score of the last sentiment analysis process, ranging from 0 to 1. A score closer to 1 indicates higher confidence in the categorization accuracy.
- Model
Gets the LLM instance associated with this SentimentAnalysis object.
- NeutralSupport
Gets or sets a value indicating whether the neutral category support is enabled.
- UseEmbeddingClassifier
Gets or sets a value indicating whether the classifier should utilize the embeddings strategy instead of completion.
Methods
- CreateTrainingObject(TrainingDataset, int, bool, int?, bool)
Creates a training object for fine-tuning a sentiment analysis model using a specified dataset.
- CreateTrainingObject(IList<(string, SentimentCategory)>, int)
Creates a LoraFinetuning object for fine-tuning a sentiment analysis model using the provided training data.
- GetSentimentCategory(string, CancellationToken)
Analyzes the sentiment of the specified text and classifies it into a category defined in the SentimentAnalysis.SentimentCategory enumeration.
- GetSentimentCategoryAsync(string, CancellationToken)
Asynchronously analyzes the sentiment of the specified text and classifies it into a category defined in the SentimentAnalysis.SentimentCategory enumeration.
- GetTrainingData(TrainingDataset, int, bool, int?, bool)
Retrieves training data for fine-tuning a sentiment analysis model from the specified dataset.