Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scores for generated text in inference mode #164

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

allen-q
Copy link

@allen-q allen-q commented Aug 20, 2020

Background:

I was using the T5 model and wanted to get the scores at inference mode along with the generated text. However, this feature is not supported by T5 at the moment and I was advised to implement this feature and raise a pull request. Please see google-research/text-to-text-transfer-transformer#311. for more details.

This PR implemented this function to add the scores(log likelihood) along the generated text in the outputs when a model is exported in SavedModel format.

Changed file:
./mesh/mesh_tensorflow/transformer/utils.py

SignatureDef Diff
Below is how a T5 MTF SavedModel SignatureDef looks like before the change:

The given SavedModel SignatureDef contains the following input(s):
  inputs['input'] tensor_info:
      dtype: DT_STRING
      shape: (-1)
      name: inputs:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['inputs'] tensor_info:
      dtype: DT_STRING
      shape: (10)
      name: SentenceTokenizer/SentenceTokenizer/SentencepieceDetokenizeOp:0
  outputs['outputs'] tensor_info:
      dtype: DT_STRING
      shape: (10)
      name: SentenceTokenizer_1/SentenceTokenizer/SentencepieceDetokenizeOp:0
Method name is: tensorflow/serving/predict

Below is how a T5 MTF SavedModel SignatureDef looks like after the change:

The given SavedModel SignatureDef contains the following input(s):
  inputs['input'] tensor_info:
      dtype: DT_STRING
      shape: (-1)
      name: inputs:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['inputs'] tensor_info:
      dtype: DT_STRING
      shape: (10)
      name: SentenceTokenizer/SentenceTokenizer/SentencepieceDetokenizeOp:0
  outputs['outputs'] tensor_info:
      dtype: DT_STRING
      shape: (10)
      name: SentenceTokenizer_1/SentenceTokenizer/SentencepieceDetokenizeOp:0
  outputs['scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (10)
      name: reshape_17/parallel_0/Reshape:0
Method name is: tensorflow/serving/predict

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@allen-q allen-q force-pushed the Add_probability_in_inference_mode branch from a3d42a3 to 7a96222 Compare August 31, 2020 11:00
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

…nsistent with other scores. create a compute_score function to remove duplicate code.
@allen-q allen-q changed the title Add probabilities for generated text in inference model Add scores for generated text in inference model Aug 31, 2020
@allen-q allen-q changed the title Add scores for generated text in inference model Add scores for generated text in inference mode Aug 31, 2020
Copy link
Member

@adarob adarob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is going to result in an approximate doubling of inference time. Can you make it so the score is computed in sample_autoregressive?

@adarob
Copy link
Member

adarob commented Oct 2, 2020

@allen-q do you plan on following up with this? thanks!

@allen-q
Copy link
Author

allen-q commented Oct 6, 2020 via email

@adarob
Copy link
Member

adarob commented Oct 16, 2020

No worries. Perhaps we can just gate this with a bool arg for now until we have the "free" version?

@marton-avrios
Copy link

marton-avrios commented Dec 10, 2020

I am currently working on a return_logits option for sample_autoregressive that just returns the already available logits together with outputs so no extra computation is involved. If this is set to True it returns an (outputs, output_logits) tuple instead of outputs. But I think it makes no sense to return only outputs anymore so not sure another argument should be introduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants