mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
loop instead of any
This commit is contained in:
parent
278e9eaa14
commit
aa3ad8825d
|
@ -291,14 +291,16 @@ def forward(model: Tok2VecListener, inputs, is_train: bool):
|
|||
# of data.
|
||||
# When the components batch differently, we don't receive a matching
|
||||
# prediction from the upstream, so we can't predict.
|
||||
if not any(doc.tensor.size for doc in inputs):
|
||||
# But we do need to do *something* if the tensor hasn't been set.
|
||||
# The compromise is to at least return data of the right shape,
|
||||
# so the output is valid.
|
||||
width = model.get_dim("nO")
|
||||
outputs = [model.ops.alloc2f(len(doc), width) for doc in inputs]
|
||||
else:
|
||||
outputs = [doc.tensor for doc in inputs]
|
||||
outputs = []
|
||||
width = model.get_dim("nO")
|
||||
for doc in inputs:
|
||||
if doc.tensor.size == 0:
|
||||
# But we do need to do *something* if the tensor hasn't been set.
|
||||
# The compromise is to at least return data of the right shape,
|
||||
# so the output is valid.
|
||||
outputs.append(model.ops.alloc2f(len(doc), width))
|
||||
else:
|
||||
outputs.append(doc.tensor)
|
||||
return outputs, lambda dX: []
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user