Creating a Model
This page walks through creating a model with MTP, from an empty protocol to a file you can submit to Databiomes for training.
Installation
pip install model-train-protocol
Steps
1. Create the Protocol
The protocol holds everything your model will learn.
import model_train_protocol as mtp
# inputs: number of input lines in each Instruction sample (minimum 1)
# encrypt: whether to encrypt tokens with hashed keys (default: True)
protocol = mtp.Protocol(name="my_model", inputs=1, encrypt=True)
Set state_machine=True if you are building a state machine. See Model Types to decide which type of model you need.
2. Add Context
Context gives the model the background information and domain knowledge it needs.
protocol.add_context("The Cheshire Cat is a fictional character from Lewis Carroll's 'Alice's Adventures in Wonderland'.")
protocol.add_context("The Cat appears and vanishes at will, and speaks in riddles.")
A minimum of 10 context lines are required in total across the protocol and its instructions. See Context for details.
3. Create Tokens and TokenSets
Tokens are the building blocks of your model. TokenSets group them into input patterns.
tree = mtp.Token("Tree")
cat = mtp.Token("Cat")
talk = mtp.Token("Talk")
cat_talking = mtp.TokenSet(tokens=(tree, cat, talk))
See Tokens and TokenSets for the available token types.
4. Create an Instruction
The instruction class you choose determines the type of model you train:
Instructionfor a generative model. See Instructions.StateMachineInstructionfor a state machine. See State Machines.MultiClassifierInstructionfor a multi-classification model. See Multi-Classification.
instruction_input = mtp.InstructionInput(
tokensets=[cat_talking]
)
instruction_output = mtp.InstructionOutput(
tokenset=cat_talking,
final=mtp.FinalToken("Continue")
)
instruction = mtp.Instruction(
name="cat_talking_instruction",
input=instruction_input,
output=instruction_output
)
5. Add Samples
Samples are the training examples that teach the instruction how to respond.
instruction.add_sample(
input_snippets=["Why do I keep vanishing and reappearing so suddenly?"],
output_snippet="Because it amuses me, and it keeps everyone wondering whether I'm truly here at all."
)
A minimum of 3 samples are required per instruction. StateMachineInstruction requires a minimum of 10.
6. Add the Instruction to the Protocol
protocol.add_instruction(instruction)
7. Save the Protocol
protocol.save()
protocol.template()
save()writes<name>_model.json, the file you submit for trainingtemplate()writes<name>_template.json, which describes how to format prompts for the trained model
Both methods validate the protocol first and raise a ProtocolError if anything is missing or invalid.
Training the Model
Upload the generated <name>_model.json to Databiomes to start training. You can monitor training progress there, and your model appears in the interface once training is complete.
Once trained, use <name>_template.json to build prompts that match the instructions the model was trained on. See Template for the fields in the template and how to use them.
Next Steps
- Examples - A complete example protocol for each model type
- Model Types - The kinds of models you can train
- API Reference - Complete API documentation
- Template - Build prompts for your trained model
Databiomes