Introduction
Different transformers are designed to handle specific tasks because each task needs the model to focus on different parts of the input and produce different kinds of output.
Jump into concepts and practice - no test required
TransformerModel(task_type, pretrained_weights) # task_type: string describing the task, e.g., 'translation', 'classification' # pretrained_weights: model weights trained for the specific task
translation_model = TransformerModel('translation', 't5-base')
qa_model = TransformerModel('question_answering', 'bert-large-uncased-whole-word-masking-finetuned-squad')
sentiment_model = TransformerModel('classification', 'distilbert-base-uncased-finetuned-sst-2-english')
from transformers import pipeline # Load a sentiment analysis pipeline sentiment_analyzer = pipeline('sentiment-analysis') # Analyze sentiment of a sentence result = sentiment_analyzer('I love learning about AI!') print(result)
outputs?
from transformers import AutoModelForQuestionAnswering, AutoTokenizer
model = AutoModelForQuestionAnswering.from_pretrained('distilbert-base-uncased-distilled-squad')
tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased-distilled-squad')
inputs = tokenizer('Who is the president of the USA?', return_tensors='pt')
outputs = model(**inputs)AutoModelForSeq2SeqLM for a text classification task but got wrong results. What is the likely error?