From 296252c49e640f252f87de037db8a62e1b9d23e1 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 30 Mar 2020 14:26:24 +0200 Subject: [PATCH] fix lm lables in docstring (#3529) --- src/transformers/modeling_t5.py | 4 +++- src/transformers/modeling_tf_t5.py | 9 ++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/transformers/modeling_t5.py b/src/transformers/modeling_t5.py index d768ddaee7..af064c2ace 100644 --- a/src/transformers/modeling_t5.py +++ b/src/transformers/modeling_t5.py @@ -900,8 +900,10 @@ class T5ForConditionalGeneration(T5PreTrainedModel): r""" lm_labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`, defaults to :obj:`None`): Labels for computing the sequence classification/regression loss. - Indices should be in :obj:`[0, ..., config.vocab_size - 1]`. + Indices should be in :obj:`[-100, 0, ..., config.vocab_size - 1]`. If :obj:`config.num_labels > 1` a classification loss is computed (Cross-Entropy). + All labels set to ``-100`` are ignored (masked), the loss is only + computed for labels in ``[0, ..., config.vocab_size]`` Returns: :obj:`tuple(torch.FloatTensor)` comprising various elements depending on the configuration (:class:`~transformers.T5Config`) and inputs. diff --git a/src/transformers/modeling_tf_t5.py b/src/transformers/modeling_tf_t5.py index dc0a0efb41..3c7dec1029 100644 --- a/src/transformers/modeling_tf_t5.py +++ b/src/transformers/modeling_tf_t5.py @@ -799,11 +799,6 @@ class TFT5ForConditionalGeneration(TFT5PreTrainedModel): @add_start_docstrings_to_callable(T5_INPUTS_DOCSTRING) def call(self, decoder_input_ids, **kwargs): r""" - lm_labels (:obj:`tf.Tensor` of shape :obj:`(batch_size,)`, `optional`, defaults to :obj:`None`): - Labels for computing the sequence classification/regression loss. - Indices should be in :obj:`[0, ..., config.vocab_size - 1]`. - If :obj:`config.num_labels > 1` a classification loss is computed (Cross-Entropy). - Return: :obj:`tuple(tf.Tensor)` comprising various elements depending on the configuration (:class:`~transformers.T5Config`) and inputs. loss (:obj:`tf.Tensor` of shape :obj:`(1,)`, `optional`, returned when :obj:`lm_label` is provided): @@ -828,8 +823,8 @@ class TFT5ForConditionalGeneration(TFT5PreTrainedModel): tokenizer = T5Tokenizer.from_pretrained('t5-small') model = TFT5ForConditionalGeneration.from_pretrained('t5-small') input_ids = tokenizer.encode("Hello, my dog is cute", return_tensors="tf") # Batch size 1 - outputs = model(input_ids, input_ids=input_ids, lm_labels=input_ids) - prediction_scores = outputs[:1] + outputs = model(input_ids, input_ids=input_ids) + prediction_scores = outputs[0] tokenizer = T5Tokenizer.from_pretrained('t5-small') model = TFT5ForConditionalGeneration.from_pretrained('t5-small')