elmo.py 文件源码

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

项目:allennlp 作者: allenai 项目源码 文件源码
def __init__(self,
                 options_file: str,
                 weight_file: str) -> None:
        super(_ElmoCharacterEncoder, self).__init__()

        with open(cached_path(options_file), 'r') as fin:
            self._options = json.load(fin)
        self._weight_file = weight_file

        self.output_dim = self._options['lstm']['projection_dim']

        self._load_weights()

        # Cache the arrays for use in forward -- +1 due to masking.
        self._beginning_of_sentence_characters = Variable(torch.from_numpy(
                numpy.array(ELMoCharacterMapper.beginning_of_sentence_characters) + 1
        ))
        self._end_of_sentence_characters = Variable(torch.from_numpy(
                numpy.array(ELMoCharacterMapper.end_of_sentence_characters) + 1
        ))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号