def _common_vocabulary_batch(self, words1, weights1, i2):
words2, weights2 = self._get_vocabulary(i2)
joint, index = numpy.unique(numpy.concatenate((words1, words2)),
return_index=True)
nw1 = numpy.zeros(len(joint), dtype=numpy.float32)
cmp = index < len(words1)
nw1[numpy.nonzero(cmp)] = weights1[index[cmp]]
nw2 = numpy.zeros(len(joint), dtype=numpy.float32)
nw2[numpy.searchsorted(joint, words2)] = weights2
return joint, nw1, nw2
评论列表
文章目录