Fix update when 0 docs

This commit is contained in:
Matthew Honnibal 2017-08-01 22:10:17 +02:00
parent 8fce187de4
commit 2e00361522

View File

@ -292,6 +292,11 @@ class Language(object):
>>> for docs, golds in epoch:
>>> state = nlp.update(docs, golds, sgd=optimizer)
"""
if len(docs) != len(golds):
raise IndexError("Update expects same number of docs and golds "
"Got: %d, %d" % (len(docs), len(golds)))
if len(docs) == 0:
return
tok2vec = self.pipeline[0]
feats = tok2vec.doc2feats(docs)
grads = {}