Skip to main content
Do you like Artifex? Give it a ⭐ star on GitHub!

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 the load() 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
    str
    optional

    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
    int
    optional
    default: 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
    str
    optional
    default: 3

    An integer which specifies the number of epochs to train the model for.
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.",
]
)
None