【问题标题】:Pyspark - Load trained model word2vecPyspark - 加载训练好的模型 word2vec
【发布时间】:2017-09-01 03:52:45
【问题描述】:

我想使用 word2vec 和 PySpark 来处理一些数据。 我之前在 Python 中使用 Google 训练的模型 GoogleNews-vectors-negative300.bingensim

有没有办法可以用 mllib.word2vec 加载这个 bin 文件? 或者将数据作为字典从 Python {word : [vector]}(或 .csv 文件)导出,然后将其加载到 PySpark 中是否有意义?

谢谢

【问题讨论】:

  • 我已经加载了 .parquet 格式的 pyspark 模型。

标签: python load pyspark gensim word2vec


【解决方案1】:

Binary import is supported in Spark 3.x:

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

但是,这需要处理二进制数据。因此建议使用gensim export

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

然后在 pyspark 中 load the model

df = spark.read.load("stored_model.csv",
                     format="csv", 
                     sep=";", 
                     inferSchema="true", 
                     header="true")

【讨论】:

    猜你喜欢
    • 2017-06-26
    • 1970-01-01
    • 2018-01-11
    • 2021-12-05
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多