Table of Contents

Method GetEmotionCategoryAsync

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

GetEmotionCategoryAsync(string, CancellationToken)

Analyzes the emotional tone of a given text and classifies it into a specific category as defined by the EmotionDetection.EmotionCategory enumeration.

public Task<EmotionDetection.EmotionCategory> GetEmotionCategoryAsync(string text, CancellationToken cancellationToken = default)

Parameters

text string

The text to analyze for emotional content. This should be a non-empty string representing the textual content whose emotion is to be classified.

cancellationToken CancellationToken

Optional. A CancellationToken for handling cancellation requests.

Returns

Task<EmotionDetection.EmotionCategory>

A member of the EmotionDetection.EmotionCategory enumeration that matches the category associated with the plain text.

Examples

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

// Initialize the language model using the specified model path
LM languageModel = LM.LoadFromModelID("phi3.5");

// Create an instance of EmotionDetection
EmotionDetection emotionDetector = new EmotionDetection(languageModel);

// Asynchronously analyze text emotion
EmotionCategory emotion = await emotionDetector.GetEmotionCategoryAsync("I am scared and anxious.");
Console.WriteLine($"Emotion: {emotion}");
// Output: "Emotion: Fear"

Exceptions

OperationCanceledException

Thrown when the operation is cancelled based on the CancellationToken.