From 0d22c6e006e27b34351b6b7ff361f367628fade2 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 20 Jun 2020 03:50:36 +0200 Subject: [PATCH] Allow DocBin to take list of Doc objects. --- spacy/tokens/_serialize.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spacy/tokens/_serialize.py b/spacy/tokens/_serialize.py index d3f49550c..7bf3faab3 100644 --- a/spacy/tokens/_serialize.py +++ b/spacy/tokens/_serialize.py @@ -39,7 +39,7 @@ class DocBin(object): document from the DocBin. """ - def __init__(self, attrs=None, store_user_data=False): + def __init__(self, attrs=None, store_user_data=False, docs=[]): """Create a DocBin object to hold serialized annotations. attrs (list): List of attributes to serialize. 'orth' and 'spacy' are @@ -59,6 +59,8 @@ class DocBin(object): self.user_data = [] self.strings = set() self.store_user_data = store_user_data + for doc in docs: + self.add(docs) def __len__(self): """RETURNS: The number of Doc objects added to the DocBin."""