question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop if token texts don't match input text

See original GitHub issue

It works with other text but running this code will cause an infinite loop. It does not like “im Anhang”.

snlp = stanfordnlp.Pipeline(lang="de")
nlp = StanfordNLPLanguage(snlp)

doc = nlp("im Anhang")
for token in doc:
    print(token.text, token.lemma_, token.pos_, token.dep_)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
inescommented, Feb 7, 2019

Yes, in that case, "des enfants" would become a Doc consisting of the tokens ["de", "les", "enfants"] and doc.text would be "de les enfants". (So text == doc.text wouldn’t hold true anymore, which is usually a fundamental principle in spaCy.)

Edit: Wrote a little fix and just trying it out with German. If this works, the compromise would be that if the tokens align with the text, you get tokens with whitespace information (token.whitespace, token.text_with_ws and by proxy Doc.text, Span.text). If the tokens do not align with the input text, you get the tokens but no aligned whitespace information, so Doc.text and Span.text may not be perfectly accurate.

Edit 2: The fix is now available in the latest release. I think it’s an okay compromise.

0reactions
scallericommented, Apr 8, 2019

hey there first of all, thank you for the great work with spacy!! it’s so nice 😃 when trying out the stanfordnlp + spacy parser with the default parser for Italian and I get this result for prepositions with articles and apostrophes, I think the problem sometimes is the “wrong” apostrophe but maybe if the mwt would be accessible in any way (I couldn’t figure out if it is), this could be solved? (here they solve it with a ‘parent’ structure: https://stanfordnlp.github.io/stanfordnlp/mwt.html) :

snlp_it = stanfordnlp.Pipeline(lang='it') 
nlp_it_stanford = StanfordNLPLanguage(snlp_it)

test_it = ["Lei non c'ha raccontato dell’idea."]

for text in test_it:
    doc1 = nlp_it_stanford(text)
    print(text)
    for token in doc1:
        
        print(token.text,"\t",token.pos_,"\t",token.tag_,"\t",token.dep_,"\t",token.lemma_)
    print()

Non posso certo ridurre il grande ritorno di Roger Federer vincitore dell’Open d’Australia con una finale vinta contro Rafa Nadal il maiorchino che in carriera gli ha pure dato molti dispiaceri con un temino di quelli che hanno assicurato finora una discreta fama al Federer fans club di via Collinetta.
Non 	 ADV 	 BN 	 advmod 	 non
posso 	 AUX 	 VM 	 aux 	 potere
certo 	 ADV 	 B 	 advmod 	 certo
ridurre 	 VERB 	 V 	 root 	 ridurre
il 	 DET 	 RD 	 det 	 il
grande 	 ADJ 	 A 	 amod 	 grande
ritorno 	 NOUN 	 S 	 obj 	 ritorno
di 	 ADP 	 E 	 case 	 di
Roger 	 PROPN 	 SP 	 nmod 	 Roger
Federer 	 PROPN 	 SP 	 flat:name 	 Federer
vincitore 	 NOUN 	 S 	 nmod 	 vincitore
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
le 	 DET 	 _ 	 det 	 le
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
le 	 DET 	 _ 	 det 	 le
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
le 	 DET 	 _ 	 det 	 le
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
a 	 ADP 	 E 	 case 	 a
il 	 DET 	 RD 	 det 	 il
Open 	 PROPN 	 SP 	 nmod 	 Open
d’ 	 ADP 	 E 	 case 	 di
Australia 	 PROPN 	 SP 	 nmod 	 Australia
con 	 ADP 	 E 	 case 	 con
una 	 DET 	 RI 	 det 	 uno
finale 	 NOUN 	 S 	 obl 	 finale
vinta 	 VERB 	 V 	 acl 	 vincere
contro 	 ADP 	 E 	 case 	 contro
Rafa 	 PROPN 	 SP 	 obl 	 Rafa
Nadal 	 PROPN 	 SP 	 flat:name 	 Nadal
il 	 DET 	 RD 	 det 	 il
maiorchino 	 NOUN 	 S 	 obj 	 maiorchino
che 	 PRON 	 PR 	 nsubj 	 che
in 	 ADP 	 E 	 case 	 in
carriera 	 NOUN 	 S 	 obl 	 carriera
gli 	 PRON 	 PC 	 iobj 	 gli
ha 	 AUX 	 VA 	 aux 	 avere
pure 	 ADV 	 B 	 advmod 	 pure
dato 	 VERB 	 V 	 acl:relcl 	 dare
molti 	 DET 	 DI 	 det 	 molto
dispiaceri 	 NOUN 	 S 	 obj 	 dispiacere
con 	 ADP 	 E 	 case 	 con

I just had a quick look at the french one, and saw similar issues:

input: "En décembre , l'émir du Qatar , cheikh Tamim ben Hamad Al-Thani , a mis en garde en décembre contre les dangers de l'Etat-providence."


En 	 ADP 	 _ 	 case 	 en
décembre 	 NOUN 	 _ 	 obl:mod 	 décembre
, 	 PUNCT 	 _ 	 punct 	 ,
l' 	 DET 	 _ 	 det 	 le
émir 	 NOUN 	 _ 	 nsubj 	 émir
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
le 	 DET 	 _ 	 det 	 le
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
le 	 DET 	 _ 	 det 	 le
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l’ 	 DET 	 RD 	 det 	 il
di 	 ADP 	 E 	 case 	 di
l' 	 DET 	 RD 	 det 	 il
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
les 	 DET 	 _ 	 det 	 le
de 	 ADP 	 _ 	 case 	 de
le 	 DET 	 _ 	 det 	 le
à 	 ADP 	 _ 	 case 	 à
le 	 DET 	 _ 	 det 	 le

thanks for the help 😃)))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infinite Loop in Tokenizing Input
In my example code, workwithtokenstuff() is executing infinitely. I have formed similar loops before, I am not sure why the scanf at the...
Read more >
Dependency Matcher execution time · Discussion #10481
I am heavily using spacy Dependency Matcher (https://spacy.io/api/dependencymatcher) to extract information from long texts. Some executions take very long ...
Read more >
PARSERS AND STATE MACHINES
A parser reads a stream or sequence of tokens and generates a “parse tree” out of it. Or rather, a tree is gener-...
Read more >
Java Basics - Java Programming Tutorial
This chapter explains the basic syntaxes of the Java programming language. I shall assume that you have written some simple Java programs.
Read more >
Chapter 5. The Rule Language
This error indicates that the parser was looking for a particular symbol that it didn't find at the current input position. Here are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found