explosion / spaCy

πŸ’« Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
30.27k stars 4.4k forks source link

TypeError: an integer is required (using Spacy example code) #3305

Closed schlies closed 5 years ago

schlies commented 5 years ago

Hello Ines, I am going through your Datacamp course. The following code worked within the Datacamp site, but it didn't work when I directly copied and pasted it into my local environment. Why isn't it working? Thank you!

How to reproduce the behaviour

# Import the Doc and Span classes
from spacy.tokens import Doc, Span

# Create a doc from the words and spaces
doc = Doc(nlp.vocab, words=['I', 'like', 'David', 'Bowie'],
spaces=[True, True, True, False])

# Create a span for "David Bowie" from the doc and assign it the label "PERSON"
span = Span(doc, 2, 4, label="PERSON")
print(span.text, span.label_)

ERROR Message:

TypeError Traceback (most recent call last)

in 6 7 # Create a span for "David Bowie" from the doc and assign it the label "PERSON" ----> 8 span = Span(doc, 2, 4, label="PERSON") 9 print(span.text, span.label_) span.pyx in spacy.tokens.span.Span.__cinit__() TypeError: an integer is required

Your Environment

ines commented 5 years ago

Ah, sorry about that – the Datacamp course is currently in soft launch (so you were among the very first people to take it!) and already uses the very new version of spaCy, which will be released as a stable version very soon and includes a lot of improvements – including string labels for spans.

Solution 1 using the current version: Look up the span label in the StringStore first to get its integer ID.

label = nlp.vocab.strings["PERSON"]
span = Span(doc, 2, 4, label=label)

Solution 2: Uninstall spaCy and install the latest alpha version using pip install spacy-nightly.

schlies commented 5 years ago

Thanks Ines. I like David Bowie too ;)

Dictated via iPhone

On Feb 20, 2019, at 6:55 PM, Ines Montani notifications@github.com wrote:

Ah, sorry about that – the Datacamp course is currently in soft launch (so you were one of the first people to take it!) and already uses the very new version of spaCy, which will be released as a stable version very soon and includes a lot of improvements – including string labels for spans.

Solution 1 using the current version: Look up the span label in the StringStore first to get its integer ID.

label = nlp.vocab.strings["PERSON"] span = Span(doc, 2, 4, label=label) Solution 2: Uninstall spaCy and install the latest alpha version using pip install spacy-nightly.

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.