在hugging face上下载了一个预训练的模型,但是我发现每次加载后输出的结果都不一样
text = '今天天气不好'
tokenizer=BertTokenizer.from_pretrained('bert-base-chinese')
logging.set_verbosity_error()
for i in range(3):
with torch.no_grad():
model=BertForSequenceClassification.from_pretrained('bert-base-chinese')
model.eval()
model.cuda(0)
token = tokenizer.encode(text)
output = model(torch.tensor([token]).cuda(0))
print(torch.nn.functional.softmax(output.logits,dim=-1))