Skip to content

为什么要在预测阶段随机初始化hidden层? #1

@pustar

Description

@pustar

您好!感谢分享。有个问题,每次测试结果在一定范围随机变化,这不合理。即使model.eval()关掉dropout,也依然随机。原因是:

    def init_hidden(self):
        return (torch.randn(2, self.batch_size, self.hidden_dim // 2),
                torch.randn(2, self.batch_size, self.hidden_dim // 2))
    def _get_lstm_features(self, sentences):
        """BiLSTM的输出(还没经过CRF层)"""
        self.hidden = self.init_hidden()

为什么要在预测阶段采用随机初始化?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions