def _encode(self, s, V, context):
"""
Arguments
----------
s: Sentence as a list of strings
V: Vocabulary as a np array of strings
context: The maximum length of previous words to include
"""
idxs = np.searchsorted(V, s)
x = np.zeros((len(s)-1, context), dtype=np.int32)
y = np.zeros((len(s)-1, 1), np.int32)
for i in range(1, len(s)):
x[i-1, :i] = idxs[:i][-context:] + 1 # 0 means missing value
y[i-1] = idxs[i]
return x, y
评论列表
文章目录