张芷铭的个人博客

T5(Text-to-Text Transfer Transformer)将所有 NLP 任务统一为"文本到文本"格式,基于编码器-解码器架构处理翻译、分类、摘要、问答等任务。

核心设计

特性说明
架构标准 Transformer 编码器-解码器
统一格式所有任务转为 text-to-text
输入任务特定格式文本(如 “translate English to French: This is a book”)
输出目标文本

论文:Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer

T5 1.1 版本改进

改进说明
相对位置编码更高效的位置编码方式
训练优化增强模型稳定性和优化效率
预训练目标span-masked denoising

xxl 模型

规格说明
参数量超过 110 亿
适用场景自然语言生成、文本摘要、问答系统、对话生成

加载配置

1
2
3
4
5
6
7
from transformers import T5EncoderModel

model = T5EncoderModel.from_pretrained(
    "google/t5-v1_1-xxl",
    max_length=256,
    torch_dtype=torch.bfloat16
).to(device)
参数说明
google/t5-v1_1-xxlHugging Face 模型路径
max_length文本序列最大长度(64/128/256/512)
torch_dtype=torch.bfloat16高效数据类型(A100 等现代 GPU)
.to(device)加载到指定设备

应用场景

  • 文本生成与摘要
  • 问答系统
  • 对话生成
  • 文本嵌入编码

Comments