You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
latest_tokens= [h.latest_tokenforhinhyps] # latest token produced by each hypothesis
latest_tokens= [tiftinxrange(vocab.size()) elsevocab.word2id(data.UNKNOWN_TOKEN) fortinlatest_tokens] # change any in-article temporary OOV ids to [UNK] id, so that we can lookup word embeddings
states= [h.stateforhinhyps] # list of current decoder states of the hypotheses
prev_coverage= [h.coverageforhinhyps] # list of coverage vectors (or None)
# Extend each hypothesis and collect them all in all_hyps
all_hyps= []
num_orig_hyps=1ifsteps==0elselen(hyps) # On the first step, we only had one original hypothesis (the initial hypothesis). On subsequent steps, all original hypotheses are distinct.
foriinxrange(num_orig_hyps):
h, new_state, attn_dist, p_gen, new_coverage_i=hyps[i], new_states[i], attn_dists[i], p_gens[i], new_coverage[i] # take the ith hypothesis and new decoder state info
forjinxrange(FLAGS.beam_size*2): # for each of the top 2*beam_size hyps:
# Extend the ith hypothesis with the jth option
new_hyp=h.extend(token=topk_ids[i, j],
log_prob=topk_log_probs[i, j],
state=new_state,
attn_dist=attn_dist,
p_gen=p_gen,
coverage=new_coverage_i)
all_hyps.append(new_hyp)
# Filter and collect any hypotheses that have produced the end token.
hyps= [] # will contain hypotheses for the next step
forhinsort_hyps(all_hyps): # in order of most likely h
ifh.latest_token==vocab.word2id(data.STOP_DECODING): # if stop token is reached...
# If this hypothesis is sufficiently long, put in results. Otherwise discard.
ifsteps>=FLAGS.min_dec_steps:
results.append(h)
else: # hasn't reached stop token, so continue to extend this hypothesis