给定两个句子串计算余弦相似度

给定两个句子串计算余弦相似度

从…Python:tf-idf-cosine:查找文档相似性,利用TF-下手余弦计算文档相似度是可能的.在不导入外部库的情况下,这是计算两个字符串之间余弦相似性的任何方法吗?

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


哈士奇WWW
浏览 699回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python