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

How to get top N results for seq2seq? #1872

Closed
lingz opened this issue Apr 12, 2016 · 1 comment
Closed

How to get top N results for seq2seq? #1872

lingz opened this issue Apr 12, 2016 · 1 comment
Assignees

Comments

@lingz
Copy link
Contributor

lingz commented Apr 12, 2016

In the example translate seq2seq model, mentioned in the tutorial and in the code here (reproduced below):

      # Get a 1-element batch to feed the sentence to the model.
      encoder_inputs, decoder_inputs, target_weights = model.get_batch(
          {bucket_id: [(token_ids, [])]}, bucket_id)
      # Get output logits for the sentence.
      _, _, output_logits = model.step(sess, encoder_inputs, decoder_inputs,
                                       target_weights, bucket_id, True)
      # This is a greedy decoder - outputs are just argmaxes of output_logits.
      outputs = [int(np.argmax(logit, axis=1)) for logit in output_logits]

It uses only a greedy decoder, and uses argmax to find the best match. I'm wondering if there's a way to get the top N results instead of just doing it greedily. I've tried argsort, but everything apart from the 0th index is just garbage results. I've also looked into tf.nn.top_k(), but because this is batched, I get the error "List of Tensors when single Tensor expected" and I'm not sure how to unroll the list within TF.

@lukaszkaiser
Copy link
Contributor

To get top-N results in a sequential network you need to run a beam search. While it's not implemented in the tutorial, there were already some suggestions and code on github -- please see #654 .

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

No branches or pull requests

2 participants