Created
August 15, 2016 16:38
-
-
Save Ogaday/f06bf048f29a03598e90a263269cedc9 to your computer and use it in GitHub Desktop.
Unexpected behaviour when creating dependency lables from array as according the tutorial at http://spacy.io/docs/tutorials/byo-annotations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3 | |
# coding: utf-8 | |
import spacy | |
from spacy.attrs import HEAD, DEP | |
from spacy.symbols import nsubj, root, dobj, punct | |
from numpy import ndarray | |
nlp = spacy.load('en') | |
doc = nlp('I eat apples.', parse=False) | |
columns = [HEAD, DEP] | |
values = ndarray(shape=(len(columns), len(doc)), dtype='int32') | |
# Syntactic parse specified as head offsets | |
heads = [1,1,1,1] | |
# Integer IDs for the dependency labels. See the parse in the displaCy | |
# demo at spacy.io/demos/displacy | |
labels = [nsubj, root, dobj, punct] | |
values[0] = heads | |
values[1] = labels | |
doc.from_array(columns, values) | |
print([t.dep_ for t in doc]) | |
print([t.dep for t in doc]) | |
print(values) | |
#print([t.head for t in doc]) # This raises an index error. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment