of stacks, one for each example in # the batch, that we can pop from independently. The words in # each example have already been reversed, so that they can # be read from left to right by popping from the end of each # list; they have also been prefixed with a null value. buffers = [list(torch.split(b.squeeze(1), 1, 0)) for b in torch.split(buffers, 1, 1)] # we also need two null values at the bottom of each stack, # so we can copy from the nulls in the input; these nulls # are all needed so that the tracker can run even if the # buffer or stack is empty stacks = [[buf[0], buf[0]] for buf in buffers] if hasattr(self, 'tracker'): self.tracker.reset_state() for trans_batch in transitions: if hasattr(self, 'tracker'): # I described the Tracker earlier as taking 4 # arguments (context_t, b, s1, s2), but here I # provide the stack contents as a single argument # while storing the context inside the Tracker
推荐阅读
未来的人们,将会如何看待我们现在的机器人?
【义务编辑:wangxueyan TEL:(010)68476606】
>>>详细阅读
本文标题:如何用PyTorch实现递归神经网络?
地址:http://www.17bianji.com/lsqh/34965.html
1/2 1