You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use nlp(text) to get human names from news articles. I gather all PERSON ents into a list but when I try to manipulate the list I get this error: TypeError: unhashable type: 'spacy.tokens.span.Span'
My code:
text='James Harding, professor at the UCL, and Lucy Smith, a student.'
text=u"{}".format(text)
all_tags = nlp(text)
names=[]
for ent in all_tags.ents:
if ent.label_=="PERSON":
names.append(ent)
print names
print type(names)
myset = list(set(names)) #remove duplicates
print(myset)
mynewlist = [ x for x in myset if " " in x ] # remove lonely names
print(mynewlist)
Output:
[James Harding, Lucy Smith]
<type 'list'>
TypeError Traceback (most recent call last)
in ()
8 print names
9 print type(names)
---> 10 myset = list(set(names)) #remove duplicates
11 print(myset)
12 mynewlist = [ x for x in myset if " " in x ] # remove lonely names
TypeError: unhashable type: 'spacy.tokens.span.Span'
I use nlp(text) to get human names from news articles. I gather all PERSON ents into a list but when I try to manipulate the list I get this error: TypeError: unhashable type: 'spacy.tokens.span.Span'
My code:
Output:
[James Harding, Lucy Smith]
<type 'list'>
TypeError Traceback (most recent call last)
in ()
8 print names
9 print type(names)
---> 10 myset = list(set(names)) #remove duplicates
11 print(myset)
12 mynewlist = [ x for x in myset if " " in x ] # remove lonely names
TypeError: unhashable type: 'spacy.tokens.span.Span'
Your Environment
Info about spaCy
The text was updated successfully, but these errors were encountered: