tagger_data.py 文件源码

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

项目:deep_srl 作者: luheng 项目源码 文件源码
def tensorize(sentence, max_length):
  """ Input:
      - sentence: The sentence is a tuple of lists (s1, s2, ..., sk)
            s1 is always a sequence of word ids.
            sk is always a sequence of label ids.
            s2 ... sk-1 are sequences of feature ids,
              such as predicate or supertag features.
      - max_length: The maximum length of sequences, used for padding.
  """
  x = np.array([t for t in zip(*sentence[:-1])])
  y = np.array(sentence[-1])
  weights = (y >= 0).astype(float)
  x.resize([max_length, x.shape[1]])
  y.resize([max_length])
  weights.resize([max_length])
  return x, np.absolute(y), len(sentence[0]), weights
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号