r - 余弦相似度:我想了解我得到的值
问题描述
我目前正在尝试使用词嵌入和余弦相似度来确定用德语编写的两个文档的相似性。
Example Data:
Document_A <- "Ich gehe heute einkaufen" ##(English: I am going shopping today)
Document_B <- "Das Wetter ist heute gut" ##(English: The weather today is good)
我使用以下方法对文档等进行了标记和词形化:
tkn <- function(SelectedGroup){
## Lemmatization
abc <- lemmatize_strings(SelectedGroup, dictionary = lemma_data)
## Delete Punctuation etc.
abc <- gsub("[[:punct:]]", "", abc[1])
## Transform everything to lower case letters
abc <- tolower(abc)
## Elimination of stopwords
abc <- tm::removeWords(tm::scan_tokenizer(abc), mystopwords)
}
treatment_tkn <- tkn(Document_A)
control_tkn <- tkn(Document_B)
为了比较我使用的两个文件:
word_embedding <- "C:/Users/Aaron/Desktop/Testordner/embeddings_german.txt"
## This file has been downloaded on http://vectors.nlpl.eu/repository/#. (Language german, ID=45)
## It has the following properties: Vector size: 100, Window: 10, Corpus: German CoNLL17 corpus,Vocabulary size: 4946997,Algorithm: Word2Vec Continuous Skipgram, Lemmatization: False
## apply the word embeddings vectors on the treatment and control variable
token_list <- list(treatment_tkn,control_tkn)
init <- Doc2Vec$new(token_list = token_list, word_vector_FILE = word_embedding)
out = init$doc2vec_methods(method = "sum_sqrt")
## Calculate the cosine similarity of the two groups (measures the angle between the two vectors)
Cosine_similarity <- cosine(out[1,], out[2,])
然而,即使对于这个例子(最后只比较了 einkaufen 和 wetter 这两个词),我得到了 0.51 的余弦相似度,即使这些词根本不相关。
同样,它发生在所有类型的文档中。比较德语和英语文档时,该值在 0.6 左右。真的不高吗?如果两个文档都是德语并且确实共享一些内容,则该值大多超过 0.9。
现在我想弄清楚为什么这些值总是那么高。我知道我的代码可能真的很弱,因为我还是个初学者。但是,我非常感谢任何意见和建议,以了解这里的问题并提高我的文本挖掘技能。
谢谢 :)
解决方案
推荐阅读
- firebase-dynamic-links - 如何获取 Google 提供的免费域(例如 yourapp.page.link)
- arrays - 为什么这个函数会产生混乱的结果而不是计算康威的生命游戏?
- amazon-web-services - 可以通过 Hive 将数据从一个 s3 存储桶复制到另一个存储桶吗?
- postgresql-9.5 - 提取纪元和当前时间不正确
- unity3d - Unity 在生成的 C++ 中使用“-”(U+2212)作为负号
- javascript - 如何使按钮可多次点击
- c# - 如何在wpf中选择list veiw数据模板的项目?
- karate - 使用 .@ 读取 json 响应。功能文件失败
- apache-spark - 有没有办法使用火花结构化流读取 ActiveMQ 中先前排队的消息?
- java - 当我有一个单独的方法来搜索数据表时,Primefaces 数据表更改项目的 ID 错误(onrowedit)