Shows token.tag_ instead of token.pos_. Disabled by default, to not cause rendering issues for models with long fine-grained tags (e.g. merged morphological features).
The function `dependency_labels_to_root(token)` defined in section *Get syntactic dependencies* does not terminate. Here is a complete example:
import spacy
nlp = spacy.load('en')
doc = nlp("Apple and banana are similar. Pasta and hippo aren't.")
def dependency_labels_to_root(token):
"""Walk up the syntactic tree, collecting the arc labels."""
dep_labels = []
while token.head is not token:
dep_labels.append(token.dep)
token = token.head
return dep_labels
dep_labels = dependency_labels_to_root(doc[1])
dep_labels
Replacing `is not` with `!=` solves the issue:
import spacy
nlp = spacy.load('en')
doc = nlp("Apple and banana are similar. Pasta and hippo aren't.")
def dependency_labels_to_root(token):
"""Walk up the syntactic tree, collecting the arc labels."""
dep_labels = []
while token.head != token:
dep_labels.append(token.dep)
token = token.head
return dep_labels
dep_labels = dependency_labels_to_root(doc[1])
dep_labels
The output is
['cc', 'nsubj']
Python 3 throws an error message on the original assert statement. Also, according to the Python documentation regarding the assert statement (https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement), `assert` takes at least one argument and at most two. In the two-argument form the second argument is meant as an error message to be displayed when the assertion fails. I don't think this is intended in this case.
I'm using SpaCy version 2.0.3. If I don't use the *-operator in the example, Python throws an error message. With the operator it works fine. Also according to the documentation of the function `nlp.disable_pipes()`, it expects one or more strings as arguments and not one argument being a list of strings.