def __init__(self, size, vocab, cuda=False):
"""Initialize params."""
self.size = size
self.done = False
self.pad = vocab['<pad>']
self.bos = vocab['<s>']
self.eos = vocab['</s>']
self.tt = torch.cuda if cuda else torch
# The score for each translation on the beam.
self.scores = self.tt.FloatTensor(size).zero_()
# The backpointers at each time-step.
self.prevKs = []
# The outputs at each time-step.
self.nextYs = [self.tt.LongTensor(size).fill_(self.pad)]
self.nextYs[0][0] = self.bos
# The attentions (matrix) for each time.
self.attn = []
# Get the outputs for the current timestep.
评论列表
文章目录