Table of Contents

Method Recognize

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

Recognize(Attachment, CancellationToken)

Synchronously recognizes named entities in the given image attachment.

public List<NamedEntityRecognition.ExtractedEntity> Recognize(Attachment content, CancellationToken cancellationToken = default)

Parameters

content Attachment

The attachment representing the image to analyze.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

List<NamedEntityRecognition.ExtractedEntity>

A list of detected NamedEntityRecognition.ExtractedEntity instances.

Examples

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

// Load a vision-capable model
LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
NamedEntityRecognition ner = new NamedEntityRecognition(model);

// Extract entities from a document image
var documentImage = new Attachment("business_card.jpg");
var entities = ner.Recognize(documentImage);

foreach (var entity in entities)
{
    Console.WriteLine($"[{entity.Type}] {entity.Value}");
}

Exceptions

ArgumentNullException

Thrown when the attachment is null.

InvalidModelException

Thrown when the underlying language model does not support vision input, which is required to analyze images for entity recognition.

Recognize(string, CancellationToken)

Synchronously recognizes named entities in the given content.

public List<NamedEntityRecognition.ExtractedEntity> Recognize(string content, CancellationToken cancellationToken = default)

Parameters

content string

The non-null, non-empty input text to analyze.

cancellationToken CancellationToken

Returns

List<NamedEntityRecognition.ExtractedEntity>

A list of NamedEntityRecognition.ExtractedEntity objects representing each detected entity.

Examples

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

LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
NamedEntityRecognition ner = new NamedEntityRecognition(model);

string news = "Amazon reported $143 billion in revenue. Jeff Bezos founded the company in Seattle in 1994.";
var entities = ner.Recognize(news);

foreach (var entity in entities)
{
    Console.WriteLine($"[{entity.Type}] {entity.Value}");
}
Console.WriteLine($"Confidence: {ner.Confidence:P1}");

Exceptions

ArgumentException

Thrown if content is null or whitespace.