当前位置: 首页>>代码示例>>Python>>正文


Python utils.murmurhash3_32方法代码示例

本文整理汇总了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.
# ------------------------------------------------------------------------------ 
开发者ID:thunlp,项目名称:OpenQA,代码行数:10,代码来源:utils.py

示例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) 
开发者ID:easonnie,项目名称:combine-FEVER-NSMN,代码行数:12,代码来源:additional_feature.py

示例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.
# ------------------------------------------------------------------------------ 
开发者ID:facebookresearch,项目名称:ParlAI,代码行数:12,代码来源:utils.py

示例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 
开发者ID:easonnie,项目名称:semanticRetrievalMRS,代码行数:8,代码来源:build_wiki_rindex.py

示例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 
开发者ID:google-research,项目名称:language,代码行数:5,代码来源:search_utils.py

示例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 
开发者ID:maciejkula,项目名称:spotlight,代码行数:29,代码来源:layers.py

示例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 
开发者ID:deepmipt,项目名称:DeepPavlov,代码行数:13,代码来源:hashing_tfidf_vectorizer.py


注:本文中的sklearn.utils.murmurhash3_32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。