Tasks

Text Generation

Generating text is the task of producing new text. These models can, for example, fill in incomplete text or paraphrase.

Inputs
Input

Once upon a time,

Text Generation Model
Output
Output

Once upon a time, we knew that our ancestors were on the verge of extinction. The great explorers and poets of the Old World, from Alexander the Great to Chaucer, are dead and gone. A good many of our ancient explorers and poets have

About Text Generation

This task covers guides on both text-generation and text-to-text generation models. Popular large language models that are used for chats or following instructions are also covered in this task. You can find the list of selected open-source large language models here, ranked by their performance scores.

Use Cases

Instruction Models

A model trained for text generation can be later adapted to follow instructions. One of the most used open-source models for instruction is OpenAssistant, which you can try at Hugging Chat.

Code Generation

A Text Generation model, also known as a causal language model, can be trained on code from scratch to help the programmers in their repetitive coding tasks. One of the most popular open-source models for code generation is StarCoder, which can generate code in 80+ languages. You can try it here.

Stories Generation

A story generation model can receive an input like "Once upon a time" and proceed to create a story-like text based on those first words. You can try this application which contains a model trained on story generation, by MosaicML.

If your generative model training data is different than your use case, you can train a causal language model from scratch. Learn how to do it in the free transformers course!

Task Variants

Completion Generation Models

A popular variant of Text Generation models predicts the next word given a bunch of words. Word by word a longer text is formed that results in for example:

  • Given an incomplete sentence, complete it.
  • Continue a story given the first sentences.
  • Provided a code description, generate the code.

The most popular models for this task are GPT-based models or Llama series. These models are trained on data that has no labels, so you just need plain text to train your own model. You can train text generation models to generate a wide variety of documents, from code to stories.

Text-to-Text Generation Models

These models are trained to learn the mapping between a pair of texts (e.g. translation from one language to another). The most popular variants of these models are FLAN-T5, and BART. Text-to-Text models are trained with multi-tasking capabilities, they can accomplish a wide range of tasks, including summarization, translation, and text classification.

Inference

You can use the πŸ€— Transformers library text-generation pipeline to do inference with Text Generation models. It takes an incomplete text and returns multiple outputs with which the text can be completed.

from transformers import pipeline
generator = pipeline('text-generation', model = 'gpt2')
generator("Hello, I'm a language model", max_length = 30, num_return_sequences=3)
## [{'generated_text': "Hello, I'm a language modeler. So while writing this, when I went out to meet my wife or come home she told me that my"},
##  {'generated_text': "Hello, I'm a language modeler. I write and maintain software in Python. I love to code, and that includes coding things that require writing"}, ...

Text-to-Text generation models have a separate pipeline called text2text-generation. This pipeline takes an input containing the sentence including the task and returns the output of the accomplished task.

from transformers import pipeline

text2text_generator = pipeline("text2text-generation")
text2text_generator("question: What is 42 ? context: 42 is the answer to life, the universe and everything")
[{'generated_text': 'the answer to life, the universe and everything'}]

text2text_generator("translate from English to French: I'm very happy")
[{'generated_text': 'Je suis très heureux'}]

You can use Model Database.js to infer text classification models on Model Database Hub.

import { HfInference } from "@Model Database/inference";

const inference = new HfInference(HF_ACCESS_TOKEN);
await inference.conversational({
  model: 'distilbert-base-uncased-finetuned-sst-2-english',
  inputs: "I love this movie!"
})

Text Generation Inference

Text Generation Inference (TGI) is an open-source toolkit for serving LLMs tackling challenges such as response time. TGI powers inference solutions like Inference Endpoints and Hugging Chat, as well as multiple community projects. You can use it to deploy any supported open-source large language model of your choice.

ChatUI Spaces

Model Database Spaces includes templates to easily deploy your own instance of a specific application. ChatUI is an open-source interface that enables serving conversational interface for large language models and can be deployed with few clicks at Spaces. TGI powers these Spaces under the hood for faster inference. Thanks to the template, you can deploy your own instance based on a large language model with only a few clicks and customize it. Learn more about it here and create your large language model instance here.

ChatUI

Useful Resources

Would you like to learn more about the topic? Awesome! Here you can find some curated resources that you may find helpful!

Tools within Model Database Ecosystem

  • You can use PEFT to adapt large language models in efficient way.
  • ChatUI is the open-source interface to conversate with Large Language Models.
  • text-generation-inferface
  • HuggingChat is a chat interface powered by Model Database to chat with powerful models like Llama 2 70B.

Documentation

Course and Blogs

Notebooks

Scripts for training

Compatible libraries

Text Generation demo
This model can be loaded on the Inference API on-demand.
Models for Text Generation
Browse Models (23,732)

Note A large code generation model that can generate code in 80+ languages.

Note A model trained to follow instructions, uses Pythia-12b as base model.

Note A model trained to follow instructions curated by community, uses Pythia-12b as base model.

Note A model trained to follow instructions, based on mosaicml/mpt-7b.

Note A large language model trained to generate text in English.

Note A large text-to-text model trained to follow instructions.

Datasets for Text Generation
Browse Datasets (1,395)

Note A large multilingual dataset of text crawled from the web.

Note A crowd-sourced instruction dataset to develop an AI assistant.

Note A crowd-sourced instruction dataset created by Databricks employees.

Spaces using Text Generation

Note A robust text generation model that can perform various tasks through natural language prompting.

Note An text generation based application that can write code for 80+ languages.

Note An text generation based application for conversations.

Note An text generation application that combines OpenAI and Model Database models.

Note An text generation application that uses StableLM-tuned-alpha-7b.

Note An UI that uses StableLM-tuned-alpha-7b.

Metrics for Text Generation
Cross Entropy
Cross Entropy is a metric that calculates the difference between two probability distributions. Each probability distribution is the distribution of predicted words
Perplexity
The Perplexity metric is the exponential of the cross-entropy loss. It evaluates the probabilities assigned to the next word by the model. Lower perplexity indicates better performance