如何计算两个单词之间的余弦相似度(matlab中的word2vec)?

时间:2017-02-03 10:56:29

标签: matlab word2vec

我有这个参数形式为word2vec_matlab,我想计算余弦相似距离

wordvecs_norm - Normalized word vectors
word2Index    - Map of words to indeces
input         - Input word (string)
k             - Number of words to return 

我试过

 word1 = ('king');
 word2 = ('queen');
 cosine = dot(wordvecs(word1)/ wordvecs_norm(word1), wordvecs(word2)/ wordvecs_norm(word2));        

1 个答案:

答案 0 :(得分:0)

维基百科将此作为公式:https://en.wikipedia.org/wiki/Cosine_similarity enter image description here

我认为这可以在MATLAB中转换为:

public void onItemSelected(AdapterView<?> parent, View view, int position,long id) { //Appending the values to textview for a selected item // textViewResult.setText(""); if(!getName(posission).equals("select a name")) { textViewResult.setText("Hi " + getName(position-1) + " your ID is " + getId(position-1)); } } 让我知道它是否有效!