Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions decode_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ def eval(self, alpha=1.0):
decoder = DecoderRNN()


def beam_decode(target_tensor, decoder_hiddens, encoder_outputs=None):
def beam_decode(target_tensor,
decoder_hiddens,
encoder_outputs=None,
topk=1,
beam_width=10,
SOS_token=0,
EOS_token=10):
'''
:param target_tensor: target indexes tensor of shape [B, T] where B is the batch size and T is the maximum length of the output sentence
:param decoder_hidden: input tensor of shape [1, B, H] for start of the decoding
:param encoder_outputs: if you are using attention mechanism you can pass encoder outputs, [T, B, H] where T is the maximum length of input sentence
:param topk: how many sentence do you want to generate
:return: decoded_batch
'''

beam_width = 10
topk = 1 # how many sentence do you want to generate
decoded_batch = []

# decoding goes sentence by sentence
Expand Down