Table of Contents

Method CreateTrainingObject

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

CreateTrainingObject(TrainingDataset, int, bool, int?, bool)

Creates a training object for fine-tuning a sentiment analysis model using a specified dataset.

public LoraFinetuning CreateTrainingObject(SentimentAnalysis.TrainingDataset dataset, int maxSamples = 1000, bool shuffle = true, int? seed = null, bool neutralSupport = true)

Parameters

dataset SentimentAnalysis.TrainingDataset

The dataset to be used for training.

maxSamples int

The maximum number of samples to use from the dataset. Default is 1000.

shuffle bool

Indicates whether to shuffle the dataset before selecting samples. Default is true.

seed int?

An optional seed for the random number generator used when shuffling. If null, the shuffle operation will not be seeded.

neutralSupport bool

Specifies whether support for neutral samples should be included. The default is true.

Returns

LoraFinetuning

A LoraFinetuning object configured with the training data.

Examples

// Create training object using a predefined dataset
LoraFinetuning finetuning = sentimentAnalyzer.CreateTrainingObject(
    SentimentAnalysis.TrainingDataset.KotziasKDD2015,
    maxSamples: 500,
    shuffle: true,
    seed: 42,
    neutralSupport: false);

// Proceed with fine-tuning...

Remarks

This method simplifies the process of creating a training object by directly using one of the predefined datasets.

Exceptions

ArgumentException

Thrown if the dataset is not recognized.

InvalidModelException

Thrown if fine-tuning is not supported when using the embedding classifier.

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

Creates a LoraFinetuning object for fine-tuning a sentiment analysis model using the provided training data.

public LoraFinetuning CreateTrainingObject(IList<(string, SentimentAnalysis.SentimentCategory)> trainingData, int maxSamples = 1000)

Parameters

trainingData IList<(string, SentimentAnalysis.SentimentCategory)>

A list of tuples where each tuple contains a text (string) and its corresponding sentiment category (SentimentAnalysis.SentimentCategory).

maxSamples int

The maximum number of training samples to use. The default value is 1000. If the number of samples in trainingData exceeds this value, only the first maxSamples samples will be used.

Returns

LoraFinetuning

A LoraFinetuning object configured for fine-tuning the sentiment analysis model with the provided training data.

Examples

// Prepare training data
var trainingData = new List<(string, SentimentCategory)>
{
    ("I hate this product.", SentimentCategory.Negative),
    ("This is fantastic!", SentimentCategory.Positive),
    ("It's okay, nothing special.", SentimentCategory.Neutral),
    // Add more samples...
};

// Create training object
LoraFinetuning finetuning = sentimentAnalyzer.CreateTrainingObject(trainingData);

// Proceed with fine-tuning...

Remarks

This method allows you to fine-tune the model with custom data to improve sentiment analysis accuracy.

Exceptions

ArgumentNullException

Thrown if the trainingData argument is null.

ArgumentException

Thrown if the trainingData list is empty or contains invalid entries.

InvalidModelException

Thrown if fine-tuning is not supported when using the embedding classifier.