spaCy 使用 anvil.works 服务器显示输出

问题描述 投票:0回答:1

我正在尝试使用 spaCy 的显示功能来显示实体。 我的渲染输出与我的

anvil.server.wait_forever()
代码一起显示在我的 Jupyter Notebook 代码单元中。

Here is an example of the code cell output I'm getting.

I would rather have the output appear here.

我已经尝试使用 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)

谢谢!

python jupyter-notebook nlp spacy displacy
1个回答
0
投票

尝试将

jupyter=False
添加到
displacy.render
以跳过 jupyter 自动检测。

© www.soinside.com 2019 - 2024. All rights reserved.