mirror of https://github.com/explosion/spaCy.git
Normalize gradient by number of words in tensorizer
This commit is contained in:
parent
dac3f1b280
commit
ba365ae1c9
|
@ -543,7 +543,7 @@ class Tensorizer(Pipe):
|
||||||
def get_loss(self, docs, golds, prediction):
|
def get_loss(self, docs, golds, prediction):
|
||||||
ids = self.model.ops.flatten([doc.to_array(ID).ravel() for doc in docs])
|
ids = self.model.ops.flatten([doc.to_array(ID).ravel() for doc in docs])
|
||||||
target = self.vocab.vectors.data[ids]
|
target = self.vocab.vectors.data[ids]
|
||||||
d_scores = (prediction - target)
|
d_scores = (prediction - target) / prediction.shape[0]
|
||||||
loss = (d_scores**2).sum()
|
loss = (d_scores**2).sum()
|
||||||
return loss, d_scores
|
return loss, d_scores
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue