简体   繁体   English

从 Azure blob 容器读取 NLP 模型

[英]Reading NLP models from Azure blob container

I have uploaded the sentence transformer model on my blob container.我已经将句子转换器 model 上传到我的 blob 容器中。 The idea is to load the model into a Python notebook from the blob container.这个想法是将 model 从 blob 容器加载到 Python 笔记本中。 To do this I do the following:为此,我执行以下操作:

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
service = BlobServiceClient(account_url="https://<name_of_my_blob>.blob.core.windows.net/", credential=credential)

then point to the location on the container where my model is ie: https://<name_of_my_blob>.blob.core.windows.net/fla-models/all-MiniLM-L6-v2 ,然后指向容器上我的 model 所在的位置,即: https://<name_of_my_blob>.blob.core.windows.net/fla-models/all-MiniLM-L6-v2

model = SentenceTransformer(service.get_blob_to_path('fla-models/all-MiniLM-L6-v2'))

But I get但我得到

AttributeError: 'BlobServiceClient' object has no attribute 'get_blob_to_path'

I have the latest installation of azure-storage-blob .我有最新安装的azure-storage-blob I wonder what am I doing wrong there and if the Azure lib is not longer supporting get_blob_to_path method?我想知道我在那里做错了什么,如果 Azure 库不再支持get_blob_to_path方法?

I tried in my environment and got below results:我在我的环境中尝试并得到以下结果:

'BlobServiceClient' object has no attribute 'get_blob_to_path' 'BlobServiceClient' object 没有属性 'get_blob_to_path'

The above error tells that BlobServiceClient is not longer supporting get_blob_to_path method.上面的错误表明BlobServiceClient不再支持get_blob_to_path方法。 because Blockblobservice is the library is using get_blob_to_path .因为Blockblobservice是库正在使用get_blob_to_path

Example:例子:

from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')

block_blob_service.get_blob_to_path('mycontainer', 'myblockblob', 'filename')

if you need read the file in azure blob storage you can use the below code:如果您需要读取 azure blob 存储中的文件,您可以使用以下代码:

Code:代码:

from  azure.storage.blob  import  BlobServiceClient
import json
service=BlobServiceClient.from_connection_string("<connection_string>")

container_client = service.get_container_client("test")
model=service.get_blob_client( "test",blob="all-MiniLM-L6-v2/modules.json"))
blob_data = model.download_blob()
data = json.loads(blob_data.readall())
print(data)
 

Console:安慰:

In portal ** all-MiniLM-L6-v2 **is blob name(folder), If you run only blob folder name it won't run you need use specific file name inside the folder.在门户中 ** all-MiniLM-L6-v2 ** 是 blob 名称(文件夹),如果您只运行 blob 文件夹名称,它将不会运行,您需要在文件夹内使用特定的文件名。

在此处输入图像描述

If you need all-MiniLM-L6-v2 to get what are the files are present you can use the below code:如果您需要all-MiniLM-L6-v2来获取存在的文件,您可以使用以下代码:

Code:代码:

from  azure.storage.blob  import  BlobServiceClient

service=BlobServiceClient.from_connection_string("<connection_string>")

container_client = service.get_container_client("test")
blob_list = container_client.list_blobs()

for  blob  in  blob_list:\

print("\t" + blob.name)

Console:安慰:在此处输入图像描述

For your reference you can use this So-thread works with function.供您参考,您可以使用此So-thread works with function。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以从 Azure Blob Storage 容器中读取所有文件,并在使用 Python 读取后删除文件? - Is it possible to read in all the files from an Azure Blob Storage container, and deleting the files after reading with Python? 使用 python 从 azure 函数读取元数据(blob 和容器名称),但在处理过程中显示 NoneType - Reading the metadata (blob and container name) from azure functions using python, but during processing it says NoneType 使用 Azure-Storage-Blob Python 读取 Blob 容器目录中每个 Blob 的文件大小 - Reading the File size for each blob inside a directory of a Blob Container using Azure-Storage-Blob Python 从 python 中的 Azure Blob 读取 joblib 文件 - Reading joblib file from Azure Blob in python 从 azure blob 存储中读取多行 - Reading a number of lines from azure blob storage 如何使用 Azure Blob 存储 SDK 将 Blob 从一个容器复制到另一个容器 - How to copy a blob from one container to another container using Azure Blob storage SDK 通过 Azure notebook 从 blob 容器访问 csv 文件 - Accessing csv file from blob container through Azure notebook 如何使用 Python 从 Azure Blob 容器读取文件 - How to read a file from Azure Blob Container using Python 在PYTHON中使用SAS URI从AZURE BLOB CONTAINER下载文件 - Download file from AZURE BLOB CONTAINER using SAS URI in PYTHON Python:如何将 Azure Blob 从一个容器移动或复制到另一个容器 - Python: How to move or copy Azure Blob from one container to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM