Evaluate the model

Getting all together

In summary, there are several steps for the machine learning project

  • load model from the library

  • specify device configuration that the model will be using

  • initialize the model with all components

    • data suitable for machine learning model

    • dataloader, optimizer, scheduler

    • performance evaluation metrics, logging

  • train the model

  • evaluate the model performance

model = BertForSequenceClassification.from_pretrained("bert-base-uncased",
                                                      num_labels=len(label_dict),
                                                      output_attentions=False,
                                                      output_hidden_states=False)

model.to(device)
pass

model.load_state_dict(
    torch.load('Models/finetuned_bert_epoch_1_gpu_trained.model',
               map_location = torch.device('cpu')
              )
)

_, predictions, true_vals = evaluate(dataloader_val)

accuracy_per_class(predictions, true_vals)

Last updated