小编GSw*_*art的帖子

训练基本的 spacy 文本分类模型

我正在尝试使用 spaCy 训练基本文本分类模型。我有一个文本列表,我想构建一个模型,将文本分类为outcome1outcome2。假设我的数据如下所示:

texts = ["This is the first example text",
         "This is the second example text",
         "This is yet another text"]
y = ["outcome2", "outcome1", "outcome1"]
Run Code Online (Sandbox Code Playgroud)

我的问题是,我什至无法将文本处理成文档:

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
Run Code Online (Sandbox Code Playgroud)
>>> ['textcat']
Run Code Online (Sandbox Code Playgroud)

但是当我尝试处理任何文本时,我收到错误:

doc = nlp("This is a sentence")
Run Code Online (Sandbox Code Playgroud)
>>> ValueError: Cannot get dimension 'nO' for model 'sparse_linear': value unset
Run Code Online (Sandbox Code Playgroud)

我尝试按照教程(有点过时)并使用spaCy 快速启动小部件设置一个项目,但在初始化配置文件时我不断遇到错误。我缺少什么?

python nlp spacy

5
推荐指数
1
解决办法
2537
查看次数

标签 统计

nlp ×1

python ×1

spacy ×1