本文整理汇总了Python中sklearn.utils.murmurhash3_32方法的典型用法代码示例。如果您正苦于以下问题:Python utils.murmurhash3_32方法的具体用法?Python utils.murmurhash3_32怎么用?Python utils.murmurhash3_32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.utils
的用法示例。
在下文中一共展示了utils.murmurhash3_32方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hash
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def hash(token, num_buckets):
"""Unsigned 32 bit murmurhash for feature hashing."""
return murmurhash3_32(token, positive=True) % num_buckets
# ------------------------------------------------------------------------------
# Text cleaning.
# ------------------------------------------------------------------------------
示例2: get_embedding
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def get_embedding(self, token, seed=6):
max_length = 5
if self.matrix is None:
self.create(seed)
if len(token) <= max_length and token.isdigit():
hash_index = murmurhash3_32(token, positive=True) % self.size
return self.matrix[hash_index]
else:
return np.zeros(self.dim)
示例3: hash
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def hash(token, num_buckets):
"""
Unsigned 32 bit murmurhash for feature hashing.
"""
return murmurhash3_32(token, positive=True) % num_buckets
# ------------------------------------------------------------------------------
# Text cleaning.
# ------------------------------------------------------------------------------
示例4: hash
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def hash(token, num_buckets=None):
"""Unsigned 32 bit murmurhash for feature hashing."""
if num_buckets is None:
return murmurhash3_32(token, positive=True)
else:
return murmurhash3_32(token, positive=True) % num_buckets
示例5: mm3hash
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def mm3hash(token, num_buckets):
"""Returns a murmur hash for given string."""
return murmurhash3_32(token, positive=True) % num_buckets
示例6: _get_hashed_indices
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def _get_hashed_indices(self, original_indices):
def _hash(x, seed):
# TODO: integrate with padding index
result = murmurhash3_32(x, seed=seed)
result[self.padding_idx] = 0
return result % self.compressed_num_embeddings
if self._hashes is None:
indices = np.arange(self.num_embeddings, dtype=np.int32)
hashes = np.stack([_hash(indices, seed)
for seed in self._masks],
axis=1).astype(np.int64)
assert hashes[self.padding_idx].sum() == 0
self._hashes = torch.from_numpy(hashes)
if original_indices.is_cuda:
self._hashes = self._hashes.cuda()
hashed_indices = torch.index_select(self._hashes,
0,
original_indices.squeeze())
return hashed_indices
示例7: hash_
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import murmurhash3_32 [as 别名]
def hash_(token: str, hash_size: int) -> int:
"""Convert a token to a hash of given size.
Args:
token: a word
hash_size: hash size
Returns:
int, hashed token
"""
return murmurhash3_32(token, positive=True) % hash_size