示例#1
0
 def combine_states(self, hyps):
     """Batch all states in different hyptheses.
     """
     states = MapDict()
     # Combine states
     for name in self.model.state_names():
         states[name] = torch.cat([h["state"][name] for h in hyps], 1)
     # Combine last tokens
     last_tokens = torch.tensor([h["tokens"][-1] for h in hyps])
     if torch.cuda.is_available():
         last_tokens = last_tokens.cuda()
         states.feedback_embed = self.model.lookup_feedback(last_tokens)
     return states
示例#2
0
 def combine_states(self, t, hyps):
     """Batch all states in different hyptheses.
     Args:
         t - time step
         hyps - hypotheses
     """
     states = MapDict({"t": t})
     # Combine states
     for name in self.model.state_names():
         states[name] = torch.cat([h["state"][name] for h in hyps], 1)
     # Combine last tokens
     last_tokens = torch.tensor([h["tokens"][-1] for h in hyps])
     if torch.cuda.is_available():
         last_tokens = last_tokens.cuda()
     states.prev_token = last_tokens.unsqueeze(0)
     states.feedback_embed = self.model.lookup_feedback(last_tokens)
     return states