What are Model outputs in transformers?

This recipe explains what are Model outputs in transformers.

Recipe Objective - What are Model outputs in transformers?

All model outputs are subclass instances of ModelOutput. These are data structures that contain all the information returned by the model, but they can also be used as tuples or dictionaries.

Learn to Implement Deep Learning Techniques for Medical Image Segmentation

Some types:

1. BaseModelOutput
2. BaseModelOutputWithPooling
3. BaseModelOutputWithCrossAttentions
4. BaseModelOutputWithPoolingAndCrossAttentions
5. BaseModelOutputWithPast
6. BaseModelOutputWithPastAndCrossAttentions
7. Seq2SeqModelOutput
8. CausalLMOutput

For more related projects -

https://www.projectpro.io/projects/data-science-projects/deep-learning-projects
https://www.projectpro.io/projects/data-science-projects/keras-deep-learning-projects

Example -

# Importing libraries
from transformers import BertTokenizer, BertForSequenceClassification
import torch

# Creating tokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

# Creating sequence classification model
model = BertForSequenceClassification.from_pretrained('bert-base-uncased')

# Passing input to tokenizer
inputs = tokenizer("Welcome to transformers tutorial", return_tensors="pt")

# Creating labels with batch size 1
labels = torch.tensor([1]).unsqueeze(0)

# Model output
outputs = model(**inputs, labels=labels)
outputs

Output -
SequenceClassifierOutput([('loss', tensor(1.4172, grad_fn=)),
                          ('logits',
                           tensor([[ 0.6969, -0.4427]], grad_fn=))])

The outputs object is a SequenceClassifierOutput.

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

NLP Project for Multi Class Text Classification using BERT Model
In this NLP Project, you will learn how to build a multi-class text classification model using using the pre-trained BERT model.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Build a Text Classification Model with Attention Mechanism NLP
In this NLP Project, you will learn to build a multi class text classification model with attention mechanism.

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.