What is Text Generation in transformers?

This recipe explains what is Text Generation in transformers.

Recipe Objective - What is Text Generation in transformers?

In text generation (also known as open text generation), the goal is to create a coherent part of the text that is a continuation of a given context. The following example shows how to use GPT2 in a pipeline to generate text. By default, all models apply TopK sampling when used in pipeline, as configured in their respective configuration (for example, see gpt2 configuration).

Get Access to Plant Species Identification Project using Machine Learning

For more related projects -

/projects/data-science-projects/deep-learning-projects
/projects/data-science-projects/keras-deep-learning-projects

Example of text generation using pipeline:

# Importing libraries
from transformers import pipeline

# Creating pipeline for text-generation
model_text_generator = pipeline("text-generation")

# Passing sequence to model
print(model_text_generator("I have never watched anything like this and", max_length=20, do_sample=False))

Output -
[{'generated_text': "I have never watched anything like this and I'm not sure if I'll ever watch it again."}]

In this way, we can perform text generation in transformers.

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

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

NLP Project on LDA Topic Modelling Python using RACE Dataset
Use the RACE dataset to extract a dominant topic from each document and perform LDA topic modeling in python.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

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

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

Build Deep Autoencoders Model for Anomaly Detection in Python
In this deep learning project , you will build and deploy a deep autoencoders model using Flask.

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.