Table of Contents

Method GetSentimentCategoryAsync

Namespace
LMKit.TextAnalysis
Assembly
LM-Kit.NET.dll

GetSentimentCategoryAsync(string, CancellationToken)

Asynchronously analyzes the sentiment of the specified text and classifies it into a category defined in the SentimentAnalysis.SentimentCategory enumeration.

public Task<SentimentAnalysis.SentimentCategory> GetSentimentCategoryAsync(string text, CancellationToken cancellationToken = default)

Parameters

text string

The text to be analyzed and classified.

cancellationToken CancellationToken

Optional. A CancellationToken for handling cancellation requests.

Returns

Task<SentimentAnalysis.SentimentCategory>

A task representing the asynchronous operation. The task result contains a member of the SentimentAnalysis.SentimentCategory enumeration that matches the sentiment category of the text.

Examples

using LMKit.TextAnalysis;
using LMKit.Model;
using System;

// Initialize the language model using the specified model path
LM languageModel = LM.LoadFromModelID("lmkit-tasks:4b-preview");

// Create an instance of SentimentAnalysis
SentimentAnalysis sentimentAnalyzer = new SentimentAnalysis(languageModel);

// Asynchronously analyze text sentiment
SentimentCategory sentiment = await sentimentAnalyzer.GetSentimentCategoryAsync("I'm not sure how I feel about this.");
Console.WriteLine($"Sentiment: {sentiment}");
// Output: "Sentiment: Neutral"

Remarks

This method is suitable for use in asynchronous programming models and can help prevent blocking the calling thread.

Exceptions

ArgumentNullException

Thrown if the input text is null or whitespace.

Share