Method GetTopCategoriesAsync
- Namespace
- LMKit.TextAnalysis
- Assembly
- LM-Kit.NET.dll
GetTopCategoriesAsync(IList<string>, string, int, bool, CancellationToken)
Asynchronously classifies the specified plain text into up to a specified maximum number of categories.
public Task<List<int>> GetTopCategoriesAsync(IList<string> categories, string content, int maxCategories, bool normalize = true, CancellationToken cancellationToken = default)
Parameters
categoriesIList<string>A list of predefined category names.
contentstringThe plain text to be classified.
maxCategoriesintThe maximum number of top categories to return.
normalizeboolSpecifies whether input parameters should be normalized. The default is
true.cancellationTokenCancellationTokenA CancellationToken for canceling the operation.
Returns
- Task<List<int>>
A task representing the asynchronous operation. The task result is a list of indices representing the top categories.
Examples
// Asynchronous usage:
var categories = new List<string> { "finance", "travel", "entertainment", "politics", "technology" };
string text = "The government unveiled a new technology policy impacting the finance sector.";
IList<int> topCategories = await categorization.GetTopCategoriesAsync(categories, text, 3);
Console.WriteLine("Top categories:");
foreach (var index in topCategories)
{
Console.WriteLine(categories[index]);
}
GetTopCategoriesAsync(IList<string>, IList<string>, string, int, bool, CancellationToken)
Asynchronously classifies the specified plain text into up to a specified maximum number of categories.
public Task<List<int>> GetTopCategoriesAsync(IList<string> categories, IList<string> categoryDescriptions, string content, int maxCategories, bool normalize = true, CancellationToken cancellationToken = default)
Parameters
categoriesIList<string>A list of predefined category names.
categoryDescriptionsIList<string>Optional descriptions for each category.
contentstringThe plain text to be classified.
maxCategoriesintThe maximum number of top categories to return.
normalizeboolSpecifies whether input parameters should be normalized. The default is
true.cancellationTokenCancellationTokenA CancellationToken for canceling the operation.
Returns
- Task<List<int>>
A task representing the asynchronous operation. The task result is a list of indices representing the top categories.
GetTopCategoriesAsync(IList<string>, ImageBuffer, int, bool, CancellationToken)
Asynchronously classifies the given image into up to a specified maximum number of categories. The underlying language model must support vision input.
public Task<List<int>> GetTopCategoriesAsync(IList<string> categories, ImageBuffer image, int maxCategories, bool normalize = true, CancellationToken cancellationToken = default)
Parameters
categoriesIList<string>A list of predefined category names.
imageImageBufferThe image to classify.
maxCategoriesintThe maximum number of top categories to return.
normalizeboolSpecifies whether input parameters should be normalized. The default is
true.cancellationTokenCancellationTokenA CancellationToken used to cancel the operation.
Returns
- Task<List<int>>
A task representing the asynchronous operation. The task result is a list of indices representing the top categories for the given image.
Exceptions
- InvalidModelException
Thrown if the underlying model does not support vision when an image is provided.
GetTopCategoriesAsync(IList<string>, Attachment, int, bool, CancellationToken)
Asynchronously classifies the content provided as an attachment into up to a specified maximum number of categories.
public Task<List<int>> GetTopCategoriesAsync(IList<string> categories, Attachment content, int maxCategories, bool normalize = true, CancellationToken cancellationToken = default)
Parameters
categoriesIList<string>A list of predefined category names.
contentAttachmentThe attachment to be classified. Supports various file formats including images, PDF documents, HTML files, and Microsoft Office formats. See Attachment for the complete list of supported formats.
maxCategoriesintThe maximum number of top categories to return.
normalizeboolSpecifies whether input parameters should be normalized. The default is
true.cancellationTokenCancellationTokenA CancellationToken for canceling the operation.
Returns
- Task<List<int>>
A task representing the asynchronous operation. The task result is a list of indices representing the top categories for the given attachment.
Exceptions
- InvalidModelException
Thrown when the attachment contains visual content requiring vision input but the underlying language model does not support vision.
GetTopCategoriesAsync(IList<string>, IList<string>, Attachment, int, bool, CancellationToken)
Asynchronously classifies the content provided as an attachment into up to a specified maximum number of categories.
public Task<List<int>> GetTopCategoriesAsync(IList<string> categories, IList<string> categoryDescriptions, Attachment content, int maxCategories, bool normalize = true, CancellationToken cancellationToken = default)
Parameters
categoriesIList<string>A list of predefined category names.
categoryDescriptionsIList<string>Optional descriptions for each category.
contentAttachmentThe attachment to be classified. Supports various file formats including images, PDF documents, HTML files, and Microsoft Office formats.
maxCategoriesintThe maximum number of top categories to return.
normalizeboolSpecifies whether input parameters should be normalized. The default is
true.cancellationTokenCancellationTokenA CancellationToken for canceling the operation.
Returns
- Task<List<int>>
A task representing the asynchronous operation. The task result is a list of indices representing the top categories for the given attachment.
Exceptions
- InvalidModelException
Thrown when the attachment contains visual content requiring vision input but the underlying language model does not support vision.