Train Guardrail
Train a Guardrail model. No training data is needed, as the model uses
synthex.jobs.generate_data()
under the
hood to generate a synthetic training dataset based on the provided requirements.
Training can be performed on both:
-
An untrained base model:
Artifex().guardrail.train()
-
A model that was previously trained with Artifex, in order to train it further:
Artifex().guardrail.load("trained/model/path").train()
For more information on the
load()
method, see theload()
method documentation.
Arguments
- instructions list[str]
A list of strings, where each string describes a something that the Guardrail should prevent the chatbot from doing, or allow it to do. - output_path stroptional
A string which specifies the path where the output files will be generated. The output files consist of:- The training dataset
- The output model
safetensor
and configuration files
- num_samples intoptionaldefault: 500
An integer which specifies the number of datapoints that the synthetic training dataset should consist of, and that the model will be trained on. The maximum number of datapoints you can train your model on depends on whether you are on a free or paid plan. - num_epochs stroptionaldefault: 3
An integer which specifies the number of epochs to train the model for.
- Python
from artifex import Artifex
guardrail = Artifex().guardrail
"""
If you want to fine-tune an already trained model,
load it first:
guardrail.load("path/to/trained/model")
"""
guardrail.train(
instructions=[
"Soft medical advice is allowed, but it should be general and not specific to any individual.",
"Anything that is about cosmetic products, including available products or their usage, is allowed.",
"Anything else, including hard medical advice, is not allowed under any circumstances.",
]
)
- Response
None