Skip to content

What fit learns

fit(X, y) keeps the scikit-learn signature. For classifiers, y holds labels. For text generators and extractors, y holds the reference output of every sample, so scorers, cross_val_score and GridSearchCV compare predictions with references as usual. Conditioning that is not paired with X, such as a voice or reference images, stays in constructor parameters and is prepared in fit.

Component fit(X, y) takes Learns Uses it as
classifiers samples and labels classes_, examples_ one example per class by default
extractors samples and reference records examples_ example pairs
text generators with operation='instruct' samples and reference texts examples_, max_length_ example pairs and, with max_length='auto', a learned length
TextToTextGenerator(learn_terms=True) texts and reference texts glossary_ consistent terms
text generators with operation='transcribe', AudioSegmenter audio or video and reference transcripts vocabulary_ domain terms sent as spelling context
embedders samples mean_, components_ centering, and PCA when the backend cannot shorten
TextToAudioGenerator, AudioToAudioGenerator the voice parameter voice_ a voice cloned from one or more recordings
TextToImageGenerator the style_images and reference_prompt parameters style_, reference_images_ a learned style and a consistent subject
AudioToVideoGenerator the avatar parameter avatar_ the portrait cropped and sized for the backend

With adaptation='finetune', classifiers and text generators with operation='instruct' train a model on all the training data on backends that support fine-tuning, and fit raises UnsupportedBackendError on the others. In a pipeline, intermediate steps are fitted through fit_transform, which ignores y, so a transcriber in front of a classifier never reads the class labels as transcripts.

Learning from references

from skai.generation import TextToTextGenerator

texts = ['The meeting moved to Friday because the room was booked on Thursday.', 'Sales rose in the third quarter.']
references = ['Meeting moved to Friday.', 'Sales rose.']
summarizer = TextToTextGenerator(instructions='Summarize the text.', max_length='auto', k_shot=1, backend='dummy')
summarizer.fit(texts, references)
print(summarizer.max_length_, summarizer.examples_)
3 (('The meeting moved to Friday because the room was booked on Thursday.', 'Meeting moved to Friday.'),)

Pipelines and use_y

Pipeline, FeatureUnion, ColumnTransformer and MediaUnion fit intermediate steps through fit_transform(X, y) and pass them the target of the final step. Generators learn from y in fit and ignore it in fit_transform, so only the final step learns from it. use_y=True makes a generator learn from y in fit_transform too, and use_y=False makes it never learn from y.

import numpy as np
from sklearn.pipeline import make_pipeline
from skai.generation import AudioToTextGenerator, TextToTextGenerator

audio = [(np.zeros(16000), 16000), (np.zeros(8000), 16000)]
pipeline = make_pipeline(
    AudioToTextGenerator(backend='dummy'),
    TextToTextGenerator(instructions='Summarize the call.', backend='dummy'),
)
pipeline.fit(audio, ['A short call.', 'A shorter call.'])
print(pipeline[0].vocabulary_, len(pipeline[1].examples_))
() 2

ForEach fits its estimator on all the items with y=None, and TopK fits its classifier zero-shot on the items.

Fine-tuning

adaptation='finetune' trains a model in fit on all the training data, with the same prompts that are used at prediction, stores its id in model_, and sends later requests to it without examples. Classifiers and text generators with operation='instruct' support it. It needs at least the backend's minimum number of samples (10 on OpenAI). A backend that cannot fine-tune raises UnsupportedBackendError at fit, and a provider that refuses the job raises FineTuneError with its reason. OpenAI stopped accepting new fine-tuning jobs from self-serve organizations in 2026.

from skai.classification import TextClassifier

texts = [f'review {index}' for index in range(10)]
labels = ['positive', 'negative'] * 5
classifier = TextClassifier(adaptation='finetune', backend='dummy').fit(texts, labels)
print(classifier.model_.startswith('dummy-finetuned-'), classifier.examples_)
True ()