A. 以下是我的配置:
操作系统:Windows 7
Spark 版本:1.4.1(问题也出现在 1.4.0 中)
语言:Python 和 Scala 都有
B. 示例源代码:
from pyspark import SparkContext
from pyspark.mllib.feature import Word2Vec
sc = SparkContext(appName='Word2Vec')
inp = sc.textFile("news2.txt").map(lambda row: row.split(" "))
word2vec = Word2Vec()
model = word2vec.fit(inp) #Results in exception...
C.Following 是堆栈跟踪:
Traceback (most recent call last):
File "E:/StudySpark/Projects/Example/poc/poc5/main.py", line 10, in <module>
model = word2vec.fit(inp)
File "E:\StudySpark\Projects\Example\spark1.4.1\spark-1.4.1-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\mllib\feature.py", line 519, in fit
File "E:\StudySpark\Projects\Example\spark1.4.1\spark-1.4.1-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\mllib\common.py", line 128, in callMLlibFunc
File "E:\StudySpark\Projects\Example\spark1.4.1\spark-1.4.1-bin-hadoop2.6\python\lib\pyspark.zip\pyspark\mllib\common.py", line 121, in callJavaFunc
File "E:\StudySpark\Projects\Example\spark1.4.1\spark-1.4.1-bin-hadoop2.6\python\lib\py4j-0.8.2.1-src.zip\py4j\java_gateway.py", line 538, in __call__
File "E:\StudySpark\Projects\Example\spark1.4.1\spark-1.4.1-bin-hadoop2.6\python\lib\py4j-0.8.2.1-src.zip\py4j\protocol.py", line 300, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o19.trainWord2Vec.
: java.util.NoSuchElementException: next on empty iterator
at scala.collection.Iterator$$anon$2.next(Iterator.scala:39)
at scala.collection.Iterator$$anon$2.next(Iterator.scala:37)
at scala.collection.IterableLike$class.head(IterableLike.scala:91)
at scala.collection.AbstractIterable.head(Iterable.scala:54)
at org.apache.spark.mllib.feature.Word2VecModel.<init>(Word2Vec.scala:442)
at org.apache.spark.mllib.feature.Word2Vec.fit(Word2Vec.scala:413)
at org.apache.spark.mllib.feature.Word2Vec.fit(Word2Vec.scala:422)
at org.apache.spark.mllib.api.python.PythonMLLibAPI.trainWord2Vec(PythonMLLibAPI.scala:560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
at py4j.Gateway.invoke(Gateway.java:259)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:207)
at java.lang.Thread.run(Thread.java:744)
有什么线索吗?
此致,
维沙尔