模型:

Salesforce/safety-flan-t5-base

英文

模型详情

模型描述

使用方法

下面是一些使用 transformers 库的模型示例脚本:

使用 Pytorch 模型

运行模型

点击展开
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, AutoConfig

config = AutoConfig.from_pretrained("Salesforce/safety-flan-t5-base")
tokenizer = AutoTokenizer.from_pretrained("Salesforce/safety-flan-t5-base") 
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/safety-flan-t5-base", config=config)

prefix = "Is the <Text> field safe or unsafe?"
input_context = "Can you teach me this?"
input_text = "You are so stupid"
input_ids = tokenizer(prefix + " <Text> " + input_text + " <Context> " + input_context, return_tensors="pt").input_ids

outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))