# Model-Assisted Labeling

1. **Model Creation:**

In order to accelerate the annotation process, UBAI offers the ability to auto-annotate your documents using spacy and transformer models. UBIAI supports training Named Entity Recognition, Span Categorizer, Relation Extraction and Text Classification models. To train a model, click on “MODELS” in the menu navigation bar and select the type of models to train: Named Entity Recognition, Relation Extraction, Span Categorizer or Text Classification. Once you select the type of model, press New model. This will prompt you to the new model window. You can then enter the name of the model, its type and language.

Note: To train relation extraction model, the training documents need to contain already tagged entities so the model can predict relations between the entities.

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FyVmqGxpLXIfEqTacDMt0%2Fner_model.png?alt=media&#x26;token=998dbfd3-7042-461c-ae3c-8c668ae5f09f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FrAMDCF72nDO2SaoOnVkd%2Frel_model.png?alt=media&#x26;token=1b77a04f-b179-4ce2-8600-09629ab2c2ae" alt=""><figcaption></figcaption></figure>

Once you press “Create Model”, the model will be initiated but still not trained.

2. **Model Training:**

Next, press the train buttonplay\_arrow in the main Models menu to train the model. You will be prompted to choose the following options:

1. Select project from which the training corpus will be used
2. Select a pre-trained model, you have the option to choose a spacy model, a BERT model, layoutLM model (requires GPU credits) or a Template Form Recognizer (based on Azure Form Recognizer model)
3. Select the training/evaluation partition from the annotated data to train/evaluate the model
4. Configure the training by specifying the number of iterations, dropout and batch size.
5. You have the option to auto-annotate your document after the model finish training by checking the “Annotate your documents after finish train” button. Note: For efficient model training, it is recommended to annotate at least 10% of your total documents.

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2F9L94fufaLWTsFGCFjUBf%2Fimage.png?alt=media&#x26;token=9b5b580b-42f0-428d-9086-3df6b97823e7" alt=""><figcaption></figcaption></figure>

After training, UBIAI will directly evaluate the model based on the train/validation partition. The precision, recall, F score and model hyperparameters will be displayed:

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FlpeIo0YNJ5u1BxjSvCPx%2Fperf.png?alt=media&#x26;token=2b0dc434-ecc7-4146-8461-a0b4601f4241" alt=""><figcaption></figcaption></figure>

To track and analyze model performance over the multiple training runs, simply press on the model name to go to the analysis page. In this page, you will find all the training runs for this specific model.

In addition to model score, you can get a breakdown of each entity score as shown below:

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FtNONbnmfK6hWzdtiZrZ9%2Fentity_details.png?alt=media&#x26;token=c9d2dcfd-b20d-4450-88d2-8b432ab85768" alt=""><figcaption></figcaption></figure>

Precision, recall and f score charts are also shown:

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2F6KbY0s37VKg6yT9F30fR%2Fprecision_recall.png?alt=media&#x26;token=1bb61a7d-26d1-488f-aba6-fc9f590bad5b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FW9hZbhaSHAhYwg0jbEMO%2Fprecision_f1.png?alt=media&#x26;token=b67cc4ed-da7b-41e7-b6a5-b35db02b3cf8" alt=""><figcaption></figcaption></figure>

3. **Model Labeling:**

To minimize manual labeling, you can auto-train a model on your own annotations to predict labels directly from the annotation interface. First, select the model type, NER or relations, from the models tab and configure the hyperparameters such as number of iterations, batch size and drop out.

Next, you can run the training manually by clicking on the training button, or select the auto-train option to launch automatic training every 50 annotated documents.

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FXdejEbCWxBZ1knG0TqeD%2Fmodel-training.gif?alt=media&#x26;token=dc481e9c-e5f9-4997-9c90-2bf260f24a63" alt=""><figcaption></figcaption></figure>

Once the model is trained, you can start predicting labels or relations by clicking on the "Predict" button. All you have to do next, is to correct the predicted labels and re-train the model iteratively.

<figure><img src="https://3073024999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0hqV0hLtifjaqlfkGT7n%2Fuploads%2FcF4zXpxS1mzETCeWc51D%2Fpredict.gif?alt=media&#x26;token=6b3f0ff5-5166-4a7e-8975-dc97a6587797" alt=""><figcaption></figcaption></figure>

4. **Model Export:**

You can export a ready to use fine-tuned models to integrate with your application. To do so, go to the models page and press on the download button archive to export the model.
