Training a Model
Training Models
In this section, we will further discuss how a Model Runtime is used to train a model that we have deployed. To allow a model to be trained, we need to add a few things to our model.yml file.
The important change here is trainable: true
. The model assistant allows the user to define a training store, can capture training options. If we want to allow our model to be trained, we also need to provide a train
function.
📘 Training Options
It is important to note that in the inference we pass the training options as a parameters, however in the training we pass the training options as a dictionary.
The train
function is called by the model runtime when the model is trained. The training_store
is the store is the document store that the user has selected to use for training. The training_options
are the options that the user has selected for training. The model_data
is a directory that the model can use to store “trained model”. A model can store anything in the model_data
directory. This contains the model_data
directory will be stored in the model store as a Model Training.
We place the responsibility of iterating over the documents in the training store and training model on the model. This provides flexibility in how the model wants to process all the training documents. Once completed, the model can save any “trained materials” in model_data
.
Supporting Model Testing in the UI
One of the powerful features in Kodexa is support for the Model Assistant, allowing a user to label a document, and then test the model against that document. This allows the user to see how the model is performing against a document that they have labeled.
To support this, we need to include an extra parameter in the train
function. This parameter is additional_training_document
. This will be an instance of a KodexaDocument.
Adding this allows you to determine in the model how you wish to handle this additional training document.
📘 Additional Training Document
The additional training document should always be a KodexaDocument. However, it is important to note that you need to confirm (using the path of the Kodexa Document) that you don’t pick up the same document from the training store.
We can see below an example of how you might write the logic to allow you to train:
Using files you deployed with the Model
When you deploy a model, you can include files that will be deployed with the model. These files can be used by the model at runtime. To access these files, you can add the parameter model_base
, this will be the folder where the model code has been deployed.