當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。