72c304fa7cac16ed19d8bc75a017f17c8073dd2f,parlai/core/torch_generator_agent.py,TorchGeneratorAgent,compute_loss,#TorchGeneratorAgent#Any#Any#,613
Before Change
// save loss to metrics
notnull = batch.label_vec.ne(self.NULL_IDX)
target_tokens = notnull.long().sum().item()
correct = ((batch.label_vec == preds) * notnull).sum().item()
self.metrics["correct_tokens"] += correct
self.metrics["nll_loss"] += loss.item()
self.metrics["num_tokens"] += target_tokens
loss /= target_tokens // average loss per token
if return_output:
return (loss, model_output)
else:
After Change
scores, preds, *_ = model_output
score_view = scores.view(-1, scores.size(-1))
loss = self.criterion(score_view, batch.label_vec.view(-1))
loss = loss.view(scores.shape[:-1]).sum(dim=1)
// save loss to metrics
notnull = batch.label_vec.ne(self.NULL_IDX)
target_tokens = notnull.long().sum(dim=-1)
In pattern: SUPERPATTERN
Frequency: 5
Non-data size: 4
Instances
Project Name: facebookresearch/ParlAI
Commit Name: 72c304fa7cac16ed19d8bc75a017f17c8073dd2f
Time: 2020-02-13
Author: roller@fb.com
File Name: parlai/core/torch_generator_agent.py
Class Name: TorchGeneratorAgent
Method Name: compute_loss
Project Name: elbayadm/attn2d
Commit Name: 29d7182447c4120057c116eb22c06d1d909eb3a1
Time: 2019-12-13
Author: yunwang@fb.com
File Name: fairseq/distributed_utils.py
Class Name:
Method Name: all_gather_list
Project Name: facebookresearch/poincare-embeddings
Commit Name: 5f465041619a63bf1de99c55d1298865bf70fd9e
Time: 2020-01-07
Author: mattle@fb.com
File Name: embed.py
Class Name:
Method Name: async_eval
Project Name: arraiy/torchgeometry
Commit Name: bd21bb4fec8d10b257ceccc3d302abd6d5b7c7d5
Time: 2020-08-26
Author: sj8716643@126.com
File Name: kornia/augmentation/augmentation.py
Class Name: RandomResizedCrop
Method Name: generate_parameters