updating model loading and adding special tokens ids

This commit is contained in:
thomwolf
2019-06-21 23:23:37 +02:00
parent ebd2cb8d74
commit 181075635d
4 changed files with 34 additions and 7 deletions

View File

@@ -6,14 +6,13 @@ import logging
logging.basicConfig(level=logging.INFO)
tokenizer = XLNetTokenizer.from_pretrained('xlnet-large-cased')
model = XLNetModel.from_pretrained('xlnet-large-cased')
model = XLNetLMHeadModel.from_pretrained('xlnet-large-cased')
model = XLNetLMHeadModel.from_pretrained('xlnet-large-cased', attn_type='uni')
tokens = tokenizer.encode('I am very ')
tokens = tokenizer.encode('I am very happy')
for i in range(len(tokens), 20):
mask = torch.tensor([[[0.0] * i + [1.0]]])
logits, _ = model(torch.tensor([tokens + [0]]),
perm_mask=mask.expand(-1, i+1, -1),
# perm_mask=mask.expand(-1, i+1, -1),
target_mapping=mask,
inp_q=mask.squeeze(1))
output = torch.multinomial(F.softmax(logits[0, 0, :]), 1)