mirror of
https://github.com/explosion/spaCy.git
synced 2025-09-19 02:22:43 +03:00
Don't use a generator for no reason
This commit is contained in:
parent
d6fd5fe1c0
commit
d6389b133d
|
@ -2,7 +2,7 @@ from dataclasses import dataclass
|
||||||
|
|
||||||
from thinc.api import Model, Linear, Relu, Dropout, chain, noop
|
from thinc.api import Model, Linear, Relu, Dropout, chain, noop
|
||||||
from thinc.types import Floats2d, Floats1d, Ints2d, Ragged
|
from thinc.types import Floats2d, Floats1d, Ints2d, Ragged
|
||||||
from typing import List, Callable, Tuple, Any, Generator
|
from typing import List, Callable, Tuple, Any
|
||||||
from ...tokens import Doc
|
from ...tokens import Doc
|
||||||
from ...util import registry
|
from ...util import registry
|
||||||
|
|
||||||
|
@ -70,10 +70,6 @@ def tuplify(layer1: Model, layer2: Model, *layers) -> Model:
|
||||||
def tuplify_forward(model, X, is_train):
|
def tuplify_forward(model, X, is_train):
|
||||||
Ys = []
|
Ys = []
|
||||||
backprops = []
|
backprops = []
|
||||||
# If the input is a generator we need to unroll it.
|
|
||||||
# The type check is necessary because arrays etc. are also OK.
|
|
||||||
if isinstance(X, Generator):
|
|
||||||
X = list(X)
|
|
||||||
for layer in model.layers:
|
for layer in model.layers:
|
||||||
Y, backprop = layer(X, is_train)
|
Y, backprop = layer(X, is_train)
|
||||||
Ys.append(Y)
|
Ys.append(Y)
|
||||||
|
|
|
@ -207,7 +207,7 @@ class CoreferenceResolver(TrainablePipe):
|
||||||
return losses
|
return losses
|
||||||
set_dropout_rate(self.model, drop)
|
set_dropout_rate(self.model, drop)
|
||||||
|
|
||||||
inputs = (example.predicted for example in examples)
|
inputs = [example.predicted for example in examples]
|
||||||
preds, backprop = self.model.begin_update(inputs)
|
preds, backprop = self.model.begin_update(inputs)
|
||||||
score_matrix, mention_idx = preds
|
score_matrix, mention_idx = preds
|
||||||
loss, d_scores = self.get_loss(examples, score_matrix, mention_idx)
|
loss, d_scores = self.get_loss(examples, score_matrix, mention_idx)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user