class_docstr: Adaptive variant of `UniformRegularizer` which learns the mix-in noise distribution.
  
  Learning Better Structured Representations using Low-Rank Adaptive Label Smoothing
  (Ghoshal+ 2021; https://openreview.net/pdf?id=5NsEIflpbSv)
class_docstr_tok: ["Adaptive","variant","of","`","UniformRegularizer","`","which","learns","the","mix-in","noise","distribution",".","Learning","Better","Structured","Representations","using","Low-Rank","Adaptive","Label","Smoothing","(","Ghoshal+","2021",";","https",":","\/\/openreview.net\/pdf","?","id=5NsEIflpbSv",")"]
docstr: Using Equation 3 and 4, computes several terms of the adaptive penalty.
  Specifically, we implement adaptive smoothing (`smooth_term`) and
  an entropy constraint (`eta_term`).
docstr_tok: ["Using","Equation","3","and","4",",","computes","several","terms","of","the","adaptive","penalty",".","Specifically",",","we","implement","adaptive","smoothing","(","`","smooth_term","`",")","and","an","entropy","constraint","(","`","eta_term","`",")","."]
code: def compute_adaptive_loss(self, logits, targets, label_embedding):
      """
      Using Equation 3 and 4, computes several terms of the adaptive penalty.
      Specifically, we implement adaptive smoothing (`smooth_term`) and
      an entropy constraint (`eta_term`).
      """
  
      if targets.dim() == logits.dim() - 1:
          targets = targets.unsqueeze(-1)
  
      U = torch.mm(
          torch.index_select(label_embedding, 0, targets.squeeze(-1)),
          label_embedding.T,
      )
      V = F.softmax(U.float(), dim=-1).to(logits.dtype)
  
      smooth_term = -torch.bmm(
          V.unsqueeze(1), logits.unsqueeze(2)
      ).squeeze(2)
      eta_term = -self.eta * (
          -torch.bmm(U.unsqueeze(1), V.unsqueeze(2)).mean()
          + torch.logsumexp(U, axis=-1).mean()
      )
      loss = smooth_term + eta_term
  
      return loss
  
file_path: pytext/pytext/loss/regularizer.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from pytext.config import ConfigBase
  from .loss import Loss
label_desc: Use image node_id 2 for calling the AdaptiveRegularizer obj's underlying member method code with example usage: obj.compute_adaptive_loss(logits, targets, label_embedding) and returns: loss