美文网首页
python查看simhash,minhash转换后的值

python查看simhash,minhash转换后的值

作者: 丙吉 | 来源:发表于2022-01-27 17:42 被阅读0次

看了下simhash, minhash算法原理。
查到的大多是直接用它们做计算,但想了解下hash后的值长什么样子。
https://leons.im/posts/a-python-implementation-of-simhash-algorithm/

simhash 查其值,用.value

from simhash import Simhash

def get_features(s):
    width = 3
    s = s.lower()
    s = re.sub(r'[^\w]+', '', s)
    return [s[i:i + width] for i in range(max(len(s) - width + 1, 1))]

print('%x' % Simhash(get_features('How are you? I am fine. Thanks.')).value)
print('%x' % Simhash(get_features('How are u? I am fine.     Thanks.')).value)
print('%x' % Simhash(get_features('How r you?I    am fine. Thanks.')).value)

结果如下:

image.png

minhash 查看值用,digest()

from datasketch import MinHashLSHEnsemble, MinHash

m1 = MinHash()
m2 = MinHash()
m1.update('How are you? I am fine. Thanks.'.encode('utf8'))
m2.update('How r you?I am fine. Thanks.'.encode('utf8'))
print(m1.digest())
print(m2.digest())

是个128维的向量


image.png

查看hashlib中的相关算法

https://docs.python.org/3.5/library/hashlib.html

import hashlib
hashlib.algorithms_guaranteed
image.png

相关文章

  • python查看simhash,minhash转换后的值

    看了下simhash, minhash算法原理。查到的大多是直接用它们做计算,但想了解下hash后的值长什么样子。...

  • SimHash和MinHash

    在搜索中,文本滤重可以节省存储空间,并使得排序效果更优。在推荐中,如果应用协同过滤算法,可以节省计算时间。不管在哪...

  • 文本去重之MinHash算法

    1.概述 跟SimHash一样,MinHash也是LSH的一种,可以用来快速估算两个集合的相似度。MinHash由...

  • python批量查看修改文件编码

    使用python批量查看文件编码,或者批量修改文件编码 代码 结果 查看文件编码 执行编码转换 再次查看转换后的编码

  • SimHash

    1.采用Hanlp分词,再计算SimHash值,及Hamming距离。2.SimHash适用于较长文本(大于三五百...

  • python查看package的安装路径及包的方法

    查看包的相关信息,可以直接在安装路径下查看它的原码:如查看simhash包的相关文档、安装路径、方法:

  • Python数据类型转换

    Python数据类型之间的转换 查看变量数据类型: Python数学函数 Python随机数函数

  • simhash python实现

    https://github.com/leonsim/simhash https://my.oschina.net...

  • python struct

    此模块可以执行 Python 值和以 Python bytes 对象之间的转换https://www.liaoxu...

  • 2018-10-11 基本数据类型

    1.python中没有隐式类型转换。 2.查看数据类型有 type()方法。 类型转换方法: int() 转换为数...

网友评论

      本文标题:python查看simhash,minhash转换后的值

      本文链接:https://www.haomeiwen.com/subject/ifpahrtx.html