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.TrainingDatasetThe dataset to be used for training.
maxSamples
intThe maximum number of samples to use from the dataset. Default is
1000
.shuffle
boolIndicates 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
boolSpecifies 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
intThe maximum number of training samples to use. The default value is
1000
. If the number of samples intrainingData
exceeds this value, only the firstmaxSamples
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 isnull
.- 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.