# Precision vs recall when using transformer models?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprecision-vs-recall-when-using-transformer-models%2F13448%3E%5C
**Category:** 🤗Transformers\
**Created:** [January 6, 2022, 3:37pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprecision-vs-recall-when-using-transformer-models%2F13448 "2022-01-06T15:37:35Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![BramVanroy](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bramvanroy/32/47360_2.png) [@BramVanroy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FBramVanroy)%5C
**Post date:** [January 10, 2022, 8:46am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprecision-vs-recall-when-using-transformer-models%2F13448%2F6 "2022-01-10T08:46:52Z")

</div>

Here is an example: [How can I use class\_weights when training? - #7 by nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-can-i-use-class-weights-when-training%2F1067%2F7) (Or if you look for “class weight” on the forums you’ll find related examples.) This is the important part:

```auto
loss_fct = nn.CrossEntropyLoss(weight=torch.tensor([0.2, 0.3]))

```

where the tensor contains the class weights. Refer to the PyTorch documentation for more information about the [class weights](https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html).

For hyperparameters to tune, as you say they are less distinct than more traditional algorithms. Typically you’d do a search for the optimal learning rate at least, potentially also including other arguments of the optimizer.

---

_[View the full topic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprecision-vs-recall-when-using-transformer-models%2F13448)._
