SuperAPIAI Directory

text-to-text-transfer-transformer

github.com · AI developer platforms

T5 (Text-To-Text Transfer Transformer) is the codebase for the text-to-text transfer learning model released by Google Research, corresponding to the paper "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer." The library is mainly used to load, preprocess, mix, and evaluate datasets, and supports fine-tuning the pretrained models released with the paper. Since July 2022, the official recommendation has been to use T5X, a new implementation based on JAX/Flax; the TensorFlow version is no longer under active development. The code includes modules such as data task definitions, evaluation metrics, and model connection layers, provides pretrained checkpoints from T5-Small to T5-11B, and supports training, fine-tuning, evaluation, decoding, and export on TPU or GPU.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

T5 (Text-To-Text Transfer Transformer) is a codebase released by Google Research, corresponding to the paper "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer." The library primarily serves as code for reproducing the paper's experiments, demonstrating how a text-to-text Transformer pretrained on a large-scale text corpus can achieve state-of-the-art results on multiple NLP tasks.

Uses:

  • Reproduce the pretraining, fine-tuning, evaluation, and decoding experiments in the paper.
  • Fine-tune the released pretrained checkpoints on your own data or hyperparameters.
  • Pretrain models from scratch.
  • Provide modules for training and fine-tuning (potentially very large) models for future model development.

Main capabilities:

  • The t5.data package is used to define Task objects and provides tf.data.Dataset. Each Task consists of a text preprocessor, a SentencePiece model, and a metric function, and may optionally provide a token preprocessor and postprocessing functions. The data source can be any function, and wrappers are also provided for TFDS datasets (TfdsTask) and for text files with one example per line (TextLineTask).
  • t5.data includes the Mixture class, which can combine multiple Task datasets for multitask training.
  • t5.evaluation includes evaluation metrics and utilities for applying these metrics during evaluation.
  • t5.models includes shims that connect T5 Task/Mixture with model implementations; currently there are two: Mesh TensorFlow Transformer and Hugging Face Transformers. The Hugging Face API is experimental and supports loading, fine-tuning, and evaluating pretrained models with PyTorch on a single GPU; to use the largest models on TPU or reproduce the paper's results, you should use the MtfModel API and the t5_mesh_transformer binary.
  • Provides T5-Small (60 million parameters), T5-Base (220 million parameters), T5-Large (770 million parameters), T5-3B (3 billion parameters), T5-11B (11 billion paramnumber) pretrained checkpoints, with paths gs://t5-data/pretrained_models/small, base, large, 3B, 11B respectively.
  • Supports exporting SavedModel for serving deployment.

Usage:

  • Installation: run pip install t5[gcp] (the installation command section in the material is not fully displayed, but it mentions "To install the T5 package, simply run:", and the subsequent command is not given, so the complete installation command is not provided for now).
  • Data preparation: you can use newly defined or predefined Tasks, or directly load preprocessed TSV files (each line format is <input>\t<target>). Using TFDS Tasks will automatically download and cache the dataset; the C4 dataset requires about 7 TB of raw Common Crawl data download and about 335 CPU days of preparation computation. It is recommended to use TFDS's Apache Beam support for distributed preprocessing on Google Cloud Dataflow, which takes about 16 hours with 500 workers.
  • Training: after creating TPU devices on a Cloud VM, use the t5_mesh_transformer binary and specify gin parameters such as MIXTURE_NAME for training.
  • Fine-tuning: pass in the operative config (gin_file) of the pretrained model and specify the fine-tuning mixture, for example fine-tuning T5-small on glue_mrpc_v002. You can use the gin file with the hyperparameters from the paper (constant learning rate 0.001). You need to specify the total number of steps (pretraining has already been 1 million steps, and the fine-tuning steps need to be accumulated). You can set the number of tokens in a batch.
  • Evaluation: use eval.gin, specify the model directory, decoding method, and checkpoint step, and optionally beam_search.gin, greedy_decode.gin, or sample_decode.gin.
  • Decoding: specify the model directory, decoding method, and checkpoint step, and generate predictions for the input text file.
  • Export: export SavedModel, and you can specify a checkpoint.
  • GPU usage: remove TPU-related flags (--tpu, --tpu_zone, --gcp_project), andset the gin parameters for mesh_shape and mesh_devices. For example, with 6 GPUs, 3-way model parallelism and 2-way data parallelism, or a single-GPU command.
  • Reproducing experiments: the operative configs for all experiments in the paper are located at gs://t5-data/experiments, organized by paper section directories.

Applicable scenarios:

  • NLP research and experiment reproduction.
  • Fine-tuning pretrained T5 models on text-to-text tasks (such as translation, summarization, GLUE benchmark tasks, etc.).
  • Multi-task learning and data mixture training.
  • Research scenarios that require training/fine-tuning large language models on large-scale TPUs or GPUs.

Limitations:

  • Since July 2022, the official recommendation is to use T5X (a new implementation based on JAX and Flax); T5 on TensorFlow and MeshTF are no longer actively developed.
  • The Hugging Face API is experimental and may change.
  • When using TSV files directly, you cannot define text processors, token preprocessors, postprocessing functions, or evaluation metric functions; you need to define a Task, TfdsTask, or TextLineTask.
  • Data files need to be accessible to the TPU (for example, located in a GCS bucket).
  • C4 dataset preparation requires a large amount of bandwidth and computing resources.
  • The material does not provide specific fee or price information.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools