給定兩個句子串計算余弦相似度從…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 similaritycosine_sim(s1, s3) # Shouldn't give high cosine similarity valuecosine_sim(s2, s3) # Shouldn't give high cosine similarity value
添加回答
舉報
0/150
提交
取消