python - How to compute cosine similarity between two words in Word2Vec model in pyspark -
when use python library gensim
, train word2vec model, can call function word2vec_result.similarity('apple','banana')
cosine similarity between apple , banana @ local machine.
in pyspark(version2.2)
, can't find same function in document after model built.
code:
#!/usr/bin/env python # -*- coding: utf-8 -*- pyspark.mllib.feature import word2vec pyspark.mllib.feature import word2vecmodel pyspark import sparkconf, sparkcontext import logging directory = "data_path" inp = sc.textfile(directory).map(lambda row: row.split(" ")) model = word2vec_run(inp) model.save(sc, "/data/word2vec_model")
are there simple ways achieve goal?
Comments
Post a Comment