- def tree_lstm(c1, c2, lstm_in):
- # Takes the memory cell states (c1, c2) of the two children, as
- # well as the sum of linear transformations of the children’s
- # hidden states (lstm_in)
- # That sum of transformed hidden states is broken up into a
- # candidate output a and four gates (i, f1, f2, and o).
- a, i, f1, f2, o = lstm_in.chunk(5, 1)
- c = a.tanh() * i.sigmoid() + f1.sigmoid() * c1 + f2.sigmoid() * c2
- h = o.sigmoid() * c.tanh()
- return h, cclass Reduce(nn.Module):
- def __init__(self, size, tracker_size=None):
- super(Reduce, self).__init__()
- self.left = nn.Linear(size, 5 * size)
- self.right = nn.Linear(size, 5 * size, bias=False)
- if tracker_size is not None:
- self.track = nn.Linear(tracker_size, 5 * size, bias=False)
- def forward(self, left_in, right_in, tracking=None):
- left, right = batch(left_in), batch(right_in)
- tracking = batch(tracking)
- lstm_in = self.left(left[0])
- lstm_in += self.right(right[0])
- if hasattr(self, 'track'):
- lstm_in += self.track(tracking[0])
- return unbatch(tree_lstm(left[1], right[1], lstm_in))
推荐阅读
【义务编辑:wangxueyan TEL:(010)68476606】 >>>详细阅读
本文标题:如何用PyTorch实现递归神经网络?
地址:http://www.17bianji.com/lsqh/34965.html
1/2 1
如何用PyTorch实现递归神经网络?
作者: 来源: 2017-04-26 13:03:04 阅读次 我要评论
关键词: 探索发现
乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。
网友点评
精彩导读
品牌展示

科技快报