[英]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.