0
我想用PySpark生成單詞向量。使用gensim我能看到的話,最近的話如下:如何從pyspark word2vec模型獲取單詞列表?
sentences = open(os.getcwd() + "/tweets.txt").read().splitlines()
w2v_input=[]
for i in sentences:
tokenised=i.split()
w2v_input.append(tokenised)
model = word2vec.Word2Vec(w2v_input)
for key in model.wv.vocab.keys():
print key
print model.most_similar(positive=[key])
使用PySpark
inp = sc.textFile("tweet.txt").map(lambda row: row.split(" "))
word2vec = Word2Vec()
model = word2vec.fit(inp)
怎樣才能從模型中的向量空間的話?那是gensim model.wv.vocab.keys()
的pyspark相當於?
背景:我需要在地圖中存儲模型中的單詞和同義詞,以便稍後可以使用它們來查找推文的情緒。由於模型屬於火花上下文(下面粘貼錯誤),因此我無法在pyspark中的地圖函數中重複使用單詞矢量模型。我想要pyspark word2vec版本而不是gensim,因爲它爲某些測試單詞提供了更好的同義詞。
Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation.SparkContext can only be used on the driver, not in code that it run on workers.
任何替代解決方案也是受歡迎的。
Thanks..this正是我想要的 – Solo
@Solo你非常歡迎 - 並感謝接受和upvoting – desertnaut