我使用的是word2vec函數,它位於Spark的mllib庫中。我要打印的我得到的輸出詞矢量爲「getVectors」功能 我的代碼如下所示:如何在scala中打印Map [String,Array [Float]]?
import org.apache.spark._
import org.apache.spark.rdd._
import org.apache.spark.SparkContext._
import org.apache.spark.mllib.feature.{Word2Vec, Word2VecModel}
object word2vec {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("word2vec")
val sc = new SparkContext(conf)
val input = sc.textFile("file:///home/snap-01/balance.csv").map(line => line.split(",").toSeq)
val word2vec = new Word2Vec()
val model = word2vec.fit(input)
model.save(sc, "myModelPath")
val sameModel = Word2VecModel.load(sc, "myModelPath")
val vec = sameModel.getVectors
print(vec)
}
}
我得到「地圖(平衡 - > [F @ 2932e15f)」
感謝它爲我工作:) – Aditi