【发布时间】:2021-11-11 06:47:03
【问题描述】:
我在我的代码上使用了这个应用函数:
def entities_extraction(text):
doc = nlp(text)
entities= [ent.text for sentence in doc.sentences for ent in sentence.entities if ent.type in {"PERSON", "ORG", "GPE", "NORP", "FAC", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "MISC"}]
return entities
df["entities"] = df['text'].progress_apply(lambda x: entities_extraction(x))
问题是,目前太慢了(需要将近12个小时)
所以我尝试修改它以使用colab gpu:
@cuda.jit
def entities_extraction(text):
doc = nlp(text)
entities= [ent.text for sentence in doc.sentences for ent in sentence.entities if ent.type in {"PERSON", "ORG", "GPE", "NORP", "FAC", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "MISC"}]
return entities
但我收到此错误:
ValueError:
Kernel launch configuration was not specified. Use the syntax:
kernel_function[blockspergrid, threadsperblock](arg0, arg1, ..., argn)
See https://numba.pydata.org/numba-doc/latest/cuda/kernels.html#kernel-invocation for help.
您知道如何解决它,或者您在应用函数上有更好的 gpu 实现吗?
对不起,如果我犯了很多错误,我对 gpu 的论点是新的,以获得更快的代码。 感谢您的帮助!
【问题讨论】:
-
nlp 函数是取自 spaCy 还是其他?
-
取自 Stanza
-
你不能使用 Numba cuda 内核来做你想做的事情。 GPU 不支持
entities_extraction函数中的任何内容
标签: python cuda gpu google-colaboratory stanford-nlp