Fix Doc.from_array example to make it work (see #1527)

This commit is contained in:
ines 2018-01-03 16:59:38 +01:00
parent 49635350f0
commit 1fa6ba8130
1 changed files with 3 additions and 3 deletions

View File

@ -401,11 +401,11 @@ p
+aside-code("Example"). +aside-code("Example").
from spacy.attrs import LOWER, POS, ENT_TYPE, IS_ALPHA from spacy.attrs import LOWER, POS, ENT_TYPE, IS_ALPHA
from spacy.tokens import Doc from spacy.tokens import Doc
doc = nlp(text) doc = nlp("Hello world!")
np_array = doc.to_array([LOWER, POS, ENT_TYPE, IS_ALPHA]) np_array = doc.to_array([LOWER, POS, ENT_TYPE, IS_ALPHA])
doc2 = Doc(doc.vocab) doc2 = Doc(doc.vocab, words=[t.text for t in doc])
doc2.from_array([LOWER, POS, ENT_TYPE, IS_ALPHA], np_array) doc2.from_array([LOWER, POS, ENT_TYPE, IS_ALPHA], np_array)
assert doc.text == doc2.text assert doc[0].pos_ == doc2[0].pos_
+table(["Name", "Type", "Description"]) +table(["Name", "Type", "Description"])
+row +row