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

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

Build Portfolio Optimization Machine Learning Models in R
Machine Learning Project for Financial Risk Modelling and Portfolio Optimization with R- Build a machine learning model in R to develop a strategy for building a portfolio for maximized returns.

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

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.