簡體   English   中英

對兩個結果詞pyspark

[英]Pairs of two consequent words pyspark

我正在研究語言模型,並希望計算兩個后續單詞的數字對。 我在scala slicing功能上找到了此類問題的示例。 雖然我沒有設法在pyspark找到類比

data.splicing(2).map(lambda (x,y): ((x,y),1).redcueByKey(lambda x,y: x+y)

我想應該是這樣的。 解決方法可能是一個創建函數,該函數可以找到數組中的下一個單詞,但是我想應該有一個內置的解決方案。

也許這會有所幫助。 您可以在此處找到其他拆分方法: 是否可以通過Python中的第n個分隔符來拆分字符串?

from itertools import izip

text = "I'm working on language model and want to count the number pairs of two consequent words.\
        I found an examples of such problem on language model and want to count the number pairs"

i = iter(text.split())

rdd = sc.parallelize([" ".join(x) for x in izip(i,i)])

print rdd.map(lambda x: (x, 1)).reduceByKey(lambda x, y: x + y).collect()

[('found an',1),('count the',2),('want to',2),('examples of',1),('model and',2),('on language ',2),('數字對',2),(“我正在工作”,1),('常用詞.I',1),('此類問題',1),('兩個' ,1)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM