Table of Contents

Method CreateTrainingObject

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

CreateTrainingObject(IList<string>, IList<(string, string)>, int)

Creates a training object for fine-tuning the categorization model using the provided training data.

public LoraFinetuning CreateTrainingObject(IList<string> categories, IList<(string, string)> trainingData, int maxSamples = 1000)

Parameters

categories IList<string>

A list of predefined categories. Each category must be a unique, non-null string.

trainingData IList<(string, string)>

A list of tuples where each tuple contains a sample text and its corresponding category.

maxSamples int

The maximum number of training samples to include. The default is 1000.

Returns

LoraFinetuning

A LoraFinetuning object initialized with the training data and ready for further fine-tuning steps.

Examples

using LMKit.Model;
using LMKit.TextAnalysis;
using LMKit.Finetuning;
using System;
using System.Collections.Generic;

class Example
{
    static void Main()
    {
        LM model = LM.LoadFromModelID("llama-3.1");

        Categorization categorization = new Categorization(model);

        var categories = new List<string> { "food", "technology", "travel" };
        var trainingData = new List<(string, string)>
        {
            ("Pizza is delicious.", "food"),
            ("Quantum computing can change the world.", "technology"),
            ("Visiting Tokyo next year!", "travel")
        };

        try
        {
            LoraFinetuning fineTuner = categorization.CreateTrainingObject(categories, trainingData);
            Console.WriteLine("Training object created successfully. Ready for fine-tuning steps.");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }
}

Remarks

This method validates and normalizes category names and training entries before generating a training chat history. The resulting LoraFinetuning instance is preloaded with the training data.

Exceptions

ArgumentNullException

Thrown if the categories or trainingData arguments are null.

ArgumentException

Thrown if trainingData is empty or if an entry references a category not present in categories.

InvalidModelException

Thrown if fine-tuning is not supported when using the embedding-based classification mode.