> For the complete documentation index, see [llms.txt](https://michael-mao.gitbook.io/sentiment-analysis-bert/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://michael-mao.gitbook.io/sentiment-analysis-bert/pytorch-bert/evaluate-the-model.md).

# 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&#x20;
* 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

```python
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)
```
