Azure ML服务是否支持导入spacy? [英] Does Azure ML services support importing spacy?

查看:70
本文介绍了Azure ML服务是否支持导入spacy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NLP脚本作为score.py的一部分,但在部署服务时,我在init()函数中遇到错误。似乎是导入spacy的问题。还尝试使用dill序列化模型,注册模型然后加载,但
也不起作用。



任何有使用Azure ML中的spacy经验的人?有什么建议吗?



这是脚本:



Hi, I'm working on an NLP script to use as part of the score.py, but when deploying the service I get an error in init() function. Seems to be an issue with importing spacy. Also tried to serialize model using dill, register model and then load, but that doesn't work either.

Anyone with experience using spacy within Azure ML? Any advice?

Here is the script:


import re
import spacy
import en_core_web_sm
import json
import numpy as np
from azureml.core.model import Model

def init():
    global model
    model = spacy.load('en_core_web_sm')
    
def run(raw_data):

    data = json.loads(raw_data)['data']
    doc = model(data)
    sentence = doc.text

    for ent in doc.ents:
        if ent.label_ == 'PERSON':
            sentence = re.sub(ent.text, '**PII-NAME**', sentence)
        if ent.label_ == 'NUM':
            sentence = re.sub(ent.text, '**PII-NUM**', sentence) 
        if ent.label_ == 'DATE':
            sentence = re.sub(ent.text, '**PII-NUM**', sentence)
        if ent.label_ == 'CARDINAL':
            sentence = re.sub(ent.text, '**PII-NUM**', sentence)
        return json.dumps({"PII FREE": sentence})

推荐答案

很抱歉听到您有这样的问题,我是否可以仔细检查您是否使用Azure机器学习服务或Azure机器学习工作室?

Sorry to hear you have such issue, may I double check if you are using Azure Machine Learning Service or Azure Machine Learning Studio?

问候,

宇通


这篇关于Azure ML服务是否支持导入spacy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆