我正在尝试在 Amazon Sagemekar 中创建 Sklearn 处理作业,以便在进行模型训练之前对输入数据执行一些数据转换。
我编写了一个自定义 python 脚本preprocessing.py来完成所需的工作。我在这个脚本中使用了一些 python 包。这是我遵循的 Sagemaker 示例。
当我尝试提交处理作业时,出现错误 -
............................Traceback (most recent call last):
File "/opt/ml/processing/input/code/preprocessing.py", line 6, in <module>
import snowflake.connector
ModuleNotFoundError: No module named 'snowflake.connector'
Run Code Online (Sandbox Code Playgroud)
我了解我的处理作业无法找到此软件包,我需要安装它。我的问题是如何使用 Sagemaker 处理作业 API 来完成此任务?理想情况下,应该有一种方法可以requirements.txt在 API 调用中定义 a,但我在文档中没有看到这样的功能。
我知道我可以使用相关包创建自定义图像,然后在处理作业中使用该图像,但这对于应该内置的东西来说似乎工作量太大了?
是否有更简单/优雅的方法来安装 Sagemaker 处理作业所需的软件包?
我想知道是否有一种优雅的方法来获取实体相对于句子的索引。我知道我可以使用ent.start_charand获取字符串中实体的索引ent.end_char,但该值是相对于整个字符串的。
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp(u"Apple is looking at buying U.K. startup for $1 billion. Apple just launched a new Credit Card.")
for ent in doc.ents:
print(ent.text, ent.start_char, ent.end_char, ent.label_)
Run Code Online (Sandbox Code Playgroud)
我希望Apple两个句子中的实体分别指向开始和结束索引 0 和 5。我怎样才能做到这一点?
我正在为生物医学文本(来自 Pubmed 的癌症论文)构建命名实体识别模型。我使用 spacy 为 3 种实体(疾病、基因和药物)类型训练了一个自定义 NER 模型。此外,我将模型与基于规则的组件相结合,以提高模型的准确性。
这是我当前的代码 -
# Loaded the trained NER Model
nlp = spacy.load("my_spacy_model")
# Define entity patterns for EntityRuler (just showing 2 relevant patterns here, it contains more patterns)
patterns = [{"label": "GENE", "pattern": "BRCA1"},
{"label": "GENE", "pattern": "BRCA2"}]
ruler = EntityRuler(nlp)
ruler.add_patterns(patterns)
nlp.add_pipe(ruler)
Run Code Online (Sandbox Code Playgroud)
当我在以下文本中测试上述代码时 -
text = "Exceptional response to olaparib in BRCA2-altered breast cancer after PD-L1 inhibitor and chemotherapy failure"
Run Code Online (Sandbox Code Playgroud)
我得到以下结果 -
DISEASE BRCA2-altered breast cancer
DRUG …Run Code Online (Sandbox Code Playgroud)