首页 > 解决方案 > Python Spacy NLP - TypeError: Argument 'string' has wrong type (expected unicode, got str)

问题描述

当我尝试在 spacy 中读取 txt 文件时出现以下错误。

TypeError:参数“字符串”的类型不正确(预期为 unicode,得到 str)

这是下面的代码

from __future__  import unicode_literals
import spacy
nlp= spacy.load('en')
doc_file = nlp(open("example.txt").read())

标签: pythonnlpspacy

解决方案


你应该使用 nlp= spacy.blank('en') 而不是 spacy.load('en')。

nlp= spacy.blank('en')
doc_file = nlp(open("example.txt").read())


推荐阅读