# Predictions for sequenceclassification task

**URL:** <https://discuss.huggingface.co/t/predictions-for-sequenceclassification-task/1453>\
**Category:** Beginners\
**Created:** [October 9, 2020, 3:09pm UTC](https://discuss.huggingface.co/t/predictions-for-sequenceclassification-task/1453 "2020-10-09T15:09:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shainaraza](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/shainaraza/32/2854_2.png) [@shainaraza](https://discuss.huggingface.co/u/shainaraza)\
**Post date:** [October 9, 2020, 3:09pm UTC](https://discuss.huggingface.co/t/predictions-for-sequenceclassification-task/1453/1 "2020-10-09T15:09:51Z")

</div>

I am working on SequenceClassification task and dont know how to see the predictions  
here is my code

> from transformers import DistilBertTokenizer, TFDistilBertForMaskedLM
> 
> import tensorflow as tf
> 
> import torch
> 
> loaded\_model = DistilBertForSequenceClassification.from\_pretrained(“/content/results/distillbert/model1”,return\_dict=True)
> 
> tokenizer = DistilBertTokenizer.from\_pretrained(‘distilbert-base-cased’)
> 
> inputs = tokenizer(“Hello, this news is Not good for learning”, return\_tensors=“pt”)
> 
> labels = torch.tensor([1]).unsqueeze(0) # Batch size 1
> 
> outputs = loaded\_model(\*\*inputs, labels=labels)
> 
> loss = outputs.loss
> 
> logits = outputs.logits

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](https://discuss.huggingface.co/u/valhalla)\
**Post date:** [October 9, 2020, 3:56pm UTC](https://discuss.huggingface.co/t/predictions-for-sequenceclassification-task/1453/2 "2020-10-09T15:56:30Z")

</div>

Checkout this [docs](https://huggingface.co/transformers/task_summary.html#sequence-classification).

First, you won’t need to pass `labels` for predictions and for prediction put the code under `torch.no_grad()` to avoid calculating gradients.

The returned `logits` have shape `[batch_size, num_classes]`, you can then apply `argmax` to get the index highest scored class.

```python
classes = ["NEGATIVE", "POSITIVE"]
enc = tokenizer("positive text", return_tensors="pt")
with torch.no_grad():
  logits = model(**enc, return_dict=True).logits

pred_class_idx = torch.argmax(logits).item()
classes[pred_class_idx]

```

you can also apply `softmax` on `logits` to get the probabilities.

and better yet, just use `pipeline` as shown in the docs above, which does all of this for you.

---

<div class="post-metadata">

**Author:** ![shainaraza](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/shainaraza/32/2854_2.png) [@shainaraza](https://discuss.huggingface.co/u/shainaraza)\
**Post date:** [October 9, 2020, 4:14pm UTC](https://discuss.huggingface.co/t/predictions-for-sequenceclassification-task/1453/3 "2020-10-09T16:14:35Z")

</div>

solved, very useful  
thanks
