我正在尝试使用 spaCy 的显示功能来显示实体。 我的渲染输出与我的
anvil.server.wait_forever()
代码一起显示在我的 Jupyter Notebook 代码单元中。
我已经尝试使用 displacy.server 而不是 displacy.render 并尝试了 auto_port。
这是我的代码:
def visualize_entities_in_sentences(self, doc_id):
"""Visualize entities in the sentences of a document.
:param doc_id: the id of the document to visualize
:type doc_id: str
"""
doc = self.get_document(doc_id)
sentences = list(doc.sents)
labels = displacy.render(sentences, style="ent", page=False, minify=True)
return labels
还有我的 Anvil 实现调用:
@anvil.server.callable
def get_visualize_entities_in_sentences(doc_id):
""""Get the document markdown for a document in my_corpus with entity labels visualized.
:param doc_id: a document id
:type doc_id: str
:returns: markdown
:rtype: str
"""
return my_corpus.visualize_entities_in_sentences(doc_id)
谢谢!
尝试将
jupyter=False
添加到 displacy.render
以跳过 jupyter 自动检测。