sentiment.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:multitask_sentiment_analysis 作者: polaroidz 项目源码 文件源码
def forward(self, x, tags, hn_tags, chunks, hn_chunks, deps, hn_deps):
        tags = tags.view(1, -1, nb_postags)
        chunks = chunks.view(1, -1, nb_chunktags)
        deps = deps.view(1, deps.size(0), deps.size(1))

        gt = torch.cat([hn_chunks, hn_tags, hn_deps, x, tags, chunks, deps], dim=2)

        pad = torch.zeros(1, x.size(1), self.input_size - gt.size(2))
        pad = Variable(pad)

        gt = torch.cat([gt, pad], dim=2)

        out, hn = self.bi_lstm(gt, (self.h[:,:x.size(1),:], 
                                    self.w[:,:x.size(1),:]))

        sentiment = self.fc(out[0,-1].view(1,-1))
        sentiment = F.sigmoid(sentiment)

        return sentiment, out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号