Normalize gradient by number of words in tensorizer

This commit is contained in:
Matthew Honnibal 2018-11-03 10:53:22 +00:00
parent dac3f1b280
commit ba365ae1c9
1 changed files with 1 additions and 1 deletions

View File

@ -543,7 +543,7 @@ class Tensorizer(Pipe):
def get_loss(self, docs, golds, prediction):
ids = self.model.ops.flatten([doc.to_array(ID).ravel() for doc in docs])
target = self.vocab.vectors.data[ids]
d_scores = (prediction - target)
d_scores = (prediction - target) / prediction.shape[0]
loss = (d_scores**2).sum()
return loss, d_scores