Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyspark - Load trained model word2vec

I want to use word2vec with PySpark to process some data. I was previously using Google trained model GoogleNews-vectors-negative300.bin with gensim in Python.

Is there a way I can load this bin file with mllib.word2vec ? Or does it make sense to export the data as a dictionary from Python {word : [vector]} (or .csv file) and then load it in PySpark?

Thanks

like image 613
Pierre Avatar asked Apr 06 '17 08:04

Pierre


1 Answers

Binary import is supported in Spark 3.x:

spark.read.format("binaryFile").option("pathGlobFilter", "*.png").load("/path/to/data")

However, this would require processing the binary data. Hence a gensim export is rather recommended:

# Save gensim model
filename = "stored_model.csv" 
trained_model.save(filename) 

Then load the model in pyspark:

df = spark.read.load("stored_model.csv",
                     format="csv", 
                     sep=";", 
                     inferSchema="true", 
                     header="true")
like image 190
RndmSymbl Avatar answered Nov 15 '22 02:11

RndmSymbl