【发布时间】:2021-07-23 13:40:05
【问题描述】:
我正在尝试使用 spaCy 训练一个基本的文本分类模型。我有一个文本列表,我想构建一个模型,将文本分类为outcome1 或outcome2。假设我的数据如下所示:
texts = ["This is the first example text",
"This is the second example text",
"This is yet another text"]
y = ["outcome2", "outcome1", "outcome1"]
我的问题是,我什至无法将文本处理成文档:
nlp = spacy.blank("en")
textcat = nlp.create_pipe("textcat")
textcat.add_label("outcome1")
textcat.add_label("outcome2")
textcat = nlp.add_pipe("textcat", last = True)
nlp.pipe_names
>>> ['textcat']
但是当我尝试处理任何文本时,我得到一个错误:
doc = nlp("This is a sentence")
>>> ValueError: Cannot get dimension 'nO' for model 'sparse_linear': value unset
我尝试按照this 教程(有点过时)并使用spaCy quickstart widget 设置项目,但在初始化配置文件时我一直遇到错误。我错过了什么?
【问题讨论】:
-
相反,对于 spaCy v3,请尝试以下示例项目:github.com/explosion/projects/tree/v3/pipelines/textcat_demo。如何开始一个项目:spacy.io/usage/projects 或者如果您来自 v2 示例:github.com/explosion/spaCy/tree/master/examples
-
在 Kaggle 上查看这个示例。导航到本文后搜索 TextCategorization kaggle.com/poonaml/text-classification-using-spacy