【问题标题】:FastText cannot be opened for loading from bucket无法打开 FastText 以从存储桶加载
【发布时间】:2021-09-20 09:22:21
【问题描述】:

我下载了 fasttext 模型 lid.176.bin。如果我在文件夹中使用模型在本地运行我的代码,一切正常。但是我需要在 GC 中运行它,所以,我将模型上传到存储桶中,并将模型的路径从本地更改为 gs 存储桶,然后出现错误:ValueError: gs://models/fasttext-model/lid.176.bin cannot be opened for loading! 如何使用存储桶中的模型?

path_to_pretrained_model = 'gs://models/fasttext-model/lid.176.bin'
fasttext_model = fasttext.load_model(path_to_pretrained_model)

【问题讨论】:

  • 我不希望自定义协议路径(如gs://models/fasttext-model/lid.176.bin)在没有特殊安排的情况下必然与任意库(如fasttext)一起使用。 (Google Cloud 是否声称要确保这一点?)因此,如果可能的话,您能否在加载之前将模型预下载到(看起来像)本地路径?
  • 我想将它与 DataFlow 一起使用
  • 请提供更多详细信息,概述。你是如何配置你的存储桶、它的区域或多区域、它的标准类、它可以从公共访问它的?你想在本地运行它吗?请提供您尝试运行的步骤。这是整个错误吗?

标签: nlp google-cloud-storage google-cloud-dataflow fasttext google-bucket


【解决方案1】:

Google Documentation的这个功能帮我解决问题

from google.cloud import storage


def download_blob(bucket_name, source_blob_name, destination_file_name):
    """Downloads a blob from the bucket."""
    # bucket_name = "your-bucket-name"
    # source_blob_name = "storage-object-name"
    # destination_file_name = "local/path/to/file"

    storage_client = storage.Client()

    bucket = storage_client.bucket(bucket_name)

    # Construct a client side representation of a blob.
    # Note `Bucket.blob` differs from `Bucket.get_blob` as it doesn't retrieve
    # any content from Google Cloud Storage. As we don't need additional data,
    # using `Bucket.blob` is preferred here.
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name)

    print(
        "Blob {} downloaded to {}.".format(
            source_blob_name, destination_file_name
        )
    )

【讨论】:

  • 嘿@m.k 我正面临这个问题!我正在尝试做确切的事情。加载存储在存储桶中的 Fasttext 模型。您能否详细说明您是如何解决的?我也想使用 Dataflow..
  • @ChaitanyaPatil 我在上面发布了一个解决方案
猜你喜欢
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 2019-07-26
  • 2017-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-02
相关资源
最近更新 更多