相关疑难解决方法(0)

找到两个字符串之间的相似性度量

如何在Python中获得字符串与另一个字符串类似的概率?

我想获得像0.9(意味着90%)等十进制值.最好使用标准的Python和库.

例如

similar("Apple","Appel") #would have a high prob.

similar("Apple","Mango") #would have a lower prob.
Run Code Online (Sandbox Code Playgroud)

python probability similarity metric

245
推荐指数
11
解决办法
17万
查看次数

给出2个句子字符串计算余弦相似度

Python:tf-idf-cosine:为了找到文档相似性,可以使用tf-idf余弦计算文档相似度.没有导入外部库,是否有任何方法可以计算2个字符串之间的余弦相似度?

s1 = "This is a foo bar sentence ."
s2 = "This sentence is similar to a foo bar sentence ."
s3 = "What is this string ? Totally not related to the other two lines ."

cosine_sim(s1, s2) # Should give high cosine similarity
cosine_sim(s1, s3) # Shouldn't give high cosine similarity value
cosine_sim(s2, s3) # Shouldn't give high cosine similarity value
Run Code Online (Sandbox Code Playgroud)

python string nlp similarity cosine-similarity

69
推荐指数
3
解决办法
9万
查看次数