总结的T5模型

问题描述

我试着总结课文。使用以下代码

import torch
from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
import io

tokenizer = AutoTokenizer.from_pretrained('t5-small')
model = AutoModelForSeq2SeqLM.from_pretrained('t5-small',return_dict=True)


text = io.open("text.txt",mode = "r",encoding="utf-8")
text = text.read().replace('\n',' ')


inputs = tokenizer.encode("summarize: " + text,return_tensors='pt',max_length=512,truncation=True)


summary_ids = model.generate(inputs,max_length=150,min_length=80,length_penalty=5.,num_beams=2)
summary = tokenizer.decode(summary_ids[0])
print(summary)

当我多次运行代码时,在我看来: See an example

我的问题是: 如何训练网络、保存并重复使用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)