追一科技开源的t5-pegasus的pytorch版本
- base版本 百度网盘: https://pan.baidu.com/s/1yv9rVGjEmV8NJcIgm5farA 提取码: rpux
- samll版本 百度网盘:https://pan.baidu.com/s/1vhqgjTNACo1Upu6TYWITeQ 提取码:3wzc
pytorch1.7.0 + transformers4.3.3
from tokenizer import T5PegasusTokenizer
from transformers.models.mt5.modeling_mt5 import MT5ForConditionalGeneration
model_path = './'
model = MT5ForConditionalGeneration.from_pretrained(model_path)
tokenizer = T5PegasusTokenizer.from_pretrained(model_path)
text = '蓝蓝的天上有一朵白白的云'
ids = tokenizer.encode(text, return_tensors='pt')
output = model.generate(ids,
decoder_start_token_id=tokenizer.cls_token_id,
eos_token_id=tokenizer.sep_token_id,
max_length=30).numpy()[0]
print(''.join(tokenizer.decode(output[1:])).replace(' ', ''))
模型名 | MODEL_NAME |
---|---|
t5-pegasus-base | imxly/t5-pegasus |
t5-pegasus-small | imxly/t5-pegasus-small |
python test.py
输出
原文:蓝蓝的天上有一朵白白的云
bert4keras预测 《蓝蓝的天上有一朵白白的云》是蓝蓝的天上有一朵白白的云创作的网络小说,发表于
torch预测 《蓝蓝的天上有一朵白白的云》是蓝蓝的天上有一朵白白的云创作的网络小说,发表于