Method AddSample
- Namespace
- LMKit.TextAnalysis.Training
- Assembly
- LM-Kit.NET.dll
AddSample(string, IList<string>, IList<string>, int)
Adds a training sample from raw text using the engine’s preferred modality.
public void AddSample(string content, IList<string> categories, IList<string> categoryDescriptions, int resultIndex)
Parameters
contentstringThe textual content to classify.
categoriesIList<string>The list of category labels. The item at
resultIndexis treated as the correct label for this sample.categoryDescriptionsIList<string>Optional human-readable descriptions aligned 1:1 with
categories.resultIndexintThe zero-based index into
categoriesindicating the expected class.
Examples
dataset.AddSample(
"The battery lasts two days on a single charge.",
new[] { "Positive", "Neutral", "Negative" },
new[] { "Favorable tone", "Objective tone", "Unfavorable tone" },
resultIndex: 0);
Remarks
The content is wrapped as a text Attachment and
forwarded to
AddSample(InferenceModality, Attachment, IList<string>, IList<string>, int).
AddSample(Attachment, IList<string>, IList<string>, int)
Adds a training sample from an Attachment using the engine’s preferred modality.
public void AddSample(Attachment content, IList<string> categories, IList<string> categoryDescriptions, int resultIndex)
Parameters
contentAttachmentThe input attachment (e.g., text, image, or multimodal source) to classify.
categoriesIList<string>The list of category labels. The item at
resultIndexis treated as the correct label for this sample.categoryDescriptionsIList<string>Optional human-readable descriptions aligned 1:1 with
categories.resultIndexintThe zero-based index into
categoriesindicating the expected class.
Remarks
For text inputs, prefer CreateFromText(string, string). This overload delegates to the modality-explicit overload.
AddSample(InferenceModality, Attachment, IList<string>, IList<string>, int)
Adds a training sample with an explicit InferenceModality.
public void AddSample(InferenceModality modality, Attachment content, IList<string> categories, IList<string> categoryDescriptions, int resultIndex)
Parameters
modalityInferenceModalityThe inference modality to use for prompt generation.
contentAttachmentThe content attachment to classify.
categoriesIList<string>The list of category labels. The item at
resultIndexis the expected label for this sample.categoryDescriptionsIList<string>Optional human-readable descriptions aligned 1:1 with
categories.resultIndexintThe zero-based index of the correct label within
categories.
Examples
var attachment = Attachment.CreateFromText(reviewText, "text");
var labels = new[] { "Positive", "Neutral", "Negative" };
var desc = new[] { "Favorable tone", "Objective tone", "Unfavorable tone" };
dataset.AddSample(
InferenceModality.Text,
attachment,
labels,
desc,
resultIndex: 2);
Remarks
This method calls Categorization.CreateSamplingClassificationTrainingSample
to synthesize a chat-based training example using
Classification.CategorizationEngine.NormalizationLevel.All. The resulting
sample is wrapped in ChatTrainingSample with the resolved
inferenceModality.
If EnableModalityAugmentation is true and the resolved
inferenceModality is Multimodal, two additional
samples are automatically added using Text and
Vision.
The lengths of categories and categoryDescriptions
should match (when descriptions are provided), and resultIndex must be
a valid index into categories.