Skip to content

Commit

Permalink
WIP reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
thomwolf committed Sep 4, 2019
1 parent e25cba7 commit 7fba47b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pytorch_transformers/modeling_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def forward(self, input_ids, past=None, attention_mask=None, token_type_ids=None
all_hidden_states = all_hidden_states + (hidden_states.view(*output_shape),)

outputs = block(hidden_states,
past=layer_past,
layer_past=layer_past,
attention_mask=attention_mask,
head_mask=head_mask[i])

Expand Down Expand Up @@ -666,7 +666,7 @@ def forward(self, input_ids, past=None, attention_mask=None, token_type_ids=None
""", GPT2_START_DOCSTRING, GPT2_INPUTS_DOCSTRING)
class GPT2DoubleHeadsModel(GPT2PreTrainedModel):
r"""
**mc_token_ids**: ``torch.LongTensor`` of shape ``(batch_size, num_choices)``:
**mc_token_ids**: (`optional`, default to index of the last token of the input) ``torch.LongTensor`` of shape ``(batch_size, num_choices)``:
Index of the classification token in each input sequence.
Selected in the range ``[0, input_ids.size(-1) - 1[``.
**lm_labels**: (`optional`) ``torch.LongTensor`` of shape ``(batch_size, sequence_length)``:
Expand Down
6 changes: 3 additions & 3 deletions pytorch_transformers/modeling_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def forward(self, input_ids, attention_mask=None, token_type_ids=None, position_
""", OPENAI_GPT_START_DOCSTRING, OPENAI_GPT_INPUTS_DOCSTRING)
class OpenAIGPTDoubleHeadsModel(OpenAIGPTPreTrainedModel):
r"""
**mc_token_ids**: ``torch.LongTensor`` of shape ``(batch_size, num_choices)``:
**mc_token_ids**: (`optional`, default to index of the last token of the input) ``torch.LongTensor`` of shape ``(batch_size, num_choices)``:
Index of the classification token in each input sequence.
Selected in the range ``[0, input_ids.size(-1) - 1[``.
**lm_labels**: (`optional`) ``torch.LongTensor`` of shape ``(batch_size, sequence_length)``:
Expand Down Expand Up @@ -678,7 +678,7 @@ class OpenAIGPTDoubleHeadsModel(OpenAIGPTPreTrainedModel):
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
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=mc_token_ids)
lm_prediction_scores, mc_prediction_scores = outputs[:2]
"""
Expand All @@ -700,7 +700,7 @@ def tie_weights(self):
self.transformer.tokens_embed)

def forward(self, input_ids, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None,
lm_labels=None, mc_labels=None):
mc_token_ids=None, lm_labels=None, mc_labels=None):
transformer_outputs = self.transformer(input_ids,
attention_mask=attention_mask,
token_type_ids=token_type_ids,
Expand Down
6 changes: 3 additions & 3 deletions pytorch_transformers/tests/modeling_roberta_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def create_and_check_roberta_model(self, config, input_ids, token_type_ids, inpu
token_labels, choice_labels):
model = RobertaModel(config=config)
model.eval()
sequence_output, pooled_output = model(input_ids, token_type_ids, input_mask)
sequence_output, pooled_output = model(input_ids, token_type_ids)
sequence_output, pooled_output = model(input_ids, attention_mask=input_mask, token_type_ids=token_type_ids)
sequence_output, pooled_output = model(input_ids, token_type_ids=token_type_ids)
sequence_output, pooled_output = model(input_ids)

result = {
Expand All @@ -140,7 +140,7 @@ def create_and_check_roberta_for_masked_lm(self, config, input_ids, token_type_i
token_labels, choice_labels):
model = RobertaForMaskedLM(config=config)
model.eval()
loss, prediction_scores = model(input_ids, token_type_ids, input_mask, token_labels)
loss, prediction_scores = model(input_ids, attention_mask=input_mask, token_type_ids=token_type_ids, masked_lm_labels=token_labels)
result = {
"loss": loss,
"prediction_scores": prediction_scores,
Expand Down

0 comments on commit 7fba47b

Please sign in to comment.