Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Spacy NLP - TypeError: Argument 'string' has incorrect type (expected unicode, got str)

Tags:

python

nlp

spacy

I was getting the following error while i was trying to read a txt file in spacy.

TypeError: Argument 'string' has incorrect type (expected unicode, got str)

Here is the code below

from __future__  import unicode_literals
import spacy
nlp= spacy.load('en')
doc_file = nlp(open("example.txt").read())
like image 868
Madu Nishant Avatar asked Nov 07 '22 03:11

Madu Nishant


1 Answers

you should use nlp= spacy.blank('en') instead of spacy.load('en').

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

like image 138
parvaneh shayegh Avatar answered Nov 15 '22 13:11

parvaneh shayegh