fix #993
This commit is contained in:
@@ -683,9 +683,10 @@ class GPT2DoubleHeadsModel(GPT2PreTrainedModel):
|
|||||||
|
|
||||||
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
||||||
model = GPT2DoubleHeadsModel.from_pretrained('gpt2')
|
model = GPT2DoubleHeadsModel.from_pretrained('gpt2')
|
||||||
choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"] # Assume you've added [CLS] to the vocabulary
|
tokenizer.add_special_tokens({'cls_token': '[CLS]'}) # Add a [CLS] to the vocabulary (we should train it also!)
|
||||||
|
choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"]
|
||||||
input_ids = torch.tensor([tokenizer.encode(s) for s in choices]).unsqueeze(0) # Batch size 1, 2 choices
|
input_ids = torch.tensor([tokenizer.encode(s) for s in choices]).unsqueeze(0) # Batch size 1, 2 choices
|
||||||
mc_token_ids = torch.tensor([-1, -1]).unsqueeze(0) # Batch size 1
|
mc_token_ids = torch.tensor([input_ids.size(-1), input_ids.size(-1)]).unsqueeze(0) # Batch size 1
|
||||||
outputs = model(input_ids, mc_token_ids)
|
outputs = model(input_ids, mc_token_ids)
|
||||||
lm_prediction_scores, mc_prediction_scores = outputs[:2]
|
lm_prediction_scores, mc_prediction_scores = outputs[:2]
|
||||||
|
|
||||||
|
|||||||
@@ -665,9 +665,10 @@ class OpenAIGPTDoubleHeadsModel(OpenAIGPTPreTrainedModel):
|
|||||||
|
|
||||||
tokenizer = OpenAIGPTTokenizer.from_pretrained('openai-gpt')
|
tokenizer = OpenAIGPTTokenizer.from_pretrained('openai-gpt')
|
||||||
model = OpenAIGPTDoubleHeadsModel.from_pretrained('openai-gpt')
|
model = OpenAIGPTDoubleHeadsModel.from_pretrained('openai-gpt')
|
||||||
choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"] # Assume you've added [CLS] to the vocabulary
|
tokenizer.add_special_tokens({'cls_token': '[CLS]'}) # Add a [CLS] to the vocabulary (we should train it also!)
|
||||||
|
choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"]
|
||||||
input_ids = torch.tensor([tokenizer.encode(s) for s in choices]).unsqueeze(0) # Batch size 1, 2 choices
|
input_ids = torch.tensor([tokenizer.encode(s) for s in choices]).unsqueeze(0) # Batch size 1, 2 choices
|
||||||
mc_token_ids = torch.tensor([-1, -1]).unsqueeze(0) # Batch size 1
|
mc_token_ids = torch.tensor([input_ids.size(-1), input_ids.size(-1)]).unsqueeze(0) # Batch size 1
|
||||||
outputs = model(input_ids, mc_token_ids)
|
outputs = model(input_ids, mc_token_ids)
|
||||||
lm_prediction_scores, mc_prediction_scores = outputs[:2]
|
lm_prediction_scores, mc_prediction_scores = outputs[:2]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user