Table of Contents

Method GetEmotionCategory

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

GetEmotionCategory(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 EmotionDetection.EmotionCategory GetEmotionCategory(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

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
LLM languageModel = new LLM("https://huggingface.co/lm-kit/phi-3.5-mini-3.8b-instruct-gguf/resolve/main/Phi-3.5-mini-Instruct-Q4_K_M.gguf?download=true");

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

// Analyze text emotion
EmotionCategory emotion = emotionDetector.GetEmotionCategory("I am feeling very sad today.");
Console.WriteLine($"Emotion: {emotion}");
// Output: "Emotion: Sadness"

Exceptions

OperationCanceledException

Thrown when the operation is cancelled based on the CancellationToken.