Refactor handling when doc._.trf_data is None
@@ -58,13 +58,13 @@ def forward(model: TransformerListener, docs, is_train):
model.verify_inputs(docs)
return model._outputs, model.backprop_and_clear
else:
- if len(docs) == 0:
- outputs = []
- elif any(doc._.trf_data is None for doc in docs):
width = model.get_dim("nO")
- outputs = [
- TransformerData.zeros(len(doc), width, xp=model.ops.xp) for doc in docs
- ]
+ outputs = []
+ for doc in docs:
+ if doc._.trf_data is None:
+ outputs.append(
+ TransformerData.zeros(len(doc), width, xp=model.ops.xp)
+ )
else:
- outputs = [doc._.trf_data for doc in docs]
+ outputs.append(doc._.trf_data)
return outputs, lambda d_data: []
