MCPcopy Create free account
hub / github.com/twitter/the-algorithm-ml / update

Method update

metrics/rce.py:246–273  ·  view source on GitHub ↗

Update the current nrce. Args: predictions: Predicted values. target: Ground truth. Should have same shape as predictions. weight: The weight to use for the predicted values. Shape should be broadcastable to that of predictions.

(
    self,
    predictions: torch.Tensor,
    target: torch.Tensor,
    weight: Union[float, torch.Tensor] = 1.0,
  )

Source from the content-addressed store, hash-verified

244 self.batch_metric = copy.deepcopy(self)
245
246 def update(
247 self,
248 predictions: torch.Tensor,
249 target: torch.Tensor,
250 weight: Union[float, torch.Tensor] = 1.0,
251 ):
252 """
253 Update the current nrce.
254 Args:
255 predictions: Predicted values.
256 target: Ground truth. Should have same shape as predictions.
257 weight: The weight to use for the predicted values. Shape should be broadcastable to that of
258 predictions.
259 """
260 predictions = torch.sigmoid(predictions) if self.nrce_from_logits else predictions
261
262 target = _smooth(target, self.nrce_label_smoothing)
263 self.mean_label.update(target, weight)
264
265 self.mean_prediction.update(predictions, weight)
266
267 normalizer = self.mean_label.compute() / self.mean_prediction.compute()
268
269 predictions = predictions * normalizer
270
271 self.binary_cross_entropy.update(
272 self.bce_loss_fn(predictions, target, reduction="none"), weight
273 )
274
275 def reset(self):
276 """

Callers

nothing calls this directly

Calls 3

_smoothFunction · 0.85
updateMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected