class_docstr: Implementation of https://arxiv.org/abs/1710.09412
class_docstr_tok: ["Implementation","of","https",":","\/\/arxiv.org\/abs\/1710.09412"]
docstr: Blend xb and yb with another random item in a second batch (xb1,yb1) with `lam` weights
docstr_tok: ["Blend","xb","and","yb","with","another","random","item","in","a","second","batch","(","xb1",",","yb1",")","with","`","lam","`","weights"]
code: def before_batch(self):
      "Blend xb and yb with another random item in a second batch (xb1,yb1) with `lam` weights"
      lam = (
          self.distrib.sample((self.y.size(0),))
          .squeeze()
          .to(self.x.device)
      )
      lam = torch.stack([lam, 1 - lam], 1)
      self.lam = lam.max(1)[0]
      shuffle = torch.randperm(self.y.size(0)).to(self.x.device)
      xb1, self.yb1 = tuple(L(self.xb).itemgot(shuffle)), tuple(
          L(self.yb).itemgot(shuffle)
      )
      nx_dims = len(self.x.size())
      self.learn.xb = tuple(
          L(xb1, self.xb).map_zip(
              torch.lerp, weight=unsqueeze(self.lam, n=nx_dims - 1)
          )
      )
  
      if not self.stack_y:
          ny_dims = len(self.y.size())
          self.learn.yb = tuple(
              L(self.yb1, self.yb).map_zip(
                  torch.lerp, weight=unsqueeze(self.lam, n=ny_dims - 1)
              )
          )
  
imports: from __future__ import annotations
  from ..basics import *
  from torch.distributions.beta import Beta
label_desc: Use image node_id 2 for calling the MixUp obj's underlying member method code with example usage: obj.before_batch() without return types