私は持っている:
from transformers import XLNetTokenizer, XLNetForQuestionAnswering
import torch
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
model = XLNetForQuestionAnswering.from_pretrained('xlnet-base-cased')
input_ids = torch.tensor(tokenizer.encode("What is my name?", add_special_tokens=True)).unsqueeze(0) # Batch size 1
start_positions = torch.tensor([1])
end_positions = torch.tensor([3])
outputs = model(input_ids, start_positions=start_positions, end_positions=end_positions)
loss = outputs[0]
print(outputs)
print(loss)
ドキュメントに従って。これは何かを与えます:
(tensor(2.3008, grad_fn=<DivBackward0>),)
tensor(2.3008, grad_fn=<DivBackward0>)
しかし、可能であれば実際の答えが欲しいですか?