docstr: x: [B, L, H]      # 从 CNN / RNN 得到的结果
      L 作为 input_num_capsules, H 作为 input_dim_capsule
docstr_tok: ["x",":","[","B",",","L",",","H","]","#","\u4ece","CNN","\/","RNN","\u5f97\u5230\u7684\u7ed3\u679c","L","\u4f5c\u4e3a","input_num_capsules",",","H","\u4f5c\u4e3a","input_dim_capsule"]
code: def forward(self, x):
      """
      x: [B, L, H]      # 从 CNN / RNN 得到的结果
          L 作为 input_num_capsules, H 作为 input_dim_capsule
      """
      B, I, _ = x.size()  # I 是 input_num_capsules
      O, F = self.num_capsule, self.dim_capsule
  
      u = torch.matmul(x, self.W)
      u = u.view(B, I, O, F).transpose(1, 2)  # [B, O, I, F]
  
      b = torch.zeros_like(u[:, :, :, 0]).to(
          device=u.device
      )  # [B, O, I]
      for i in range(self.num_iterations):
          c = torch.softmax(b, dim=1)  # [B, O_s, I]
          v = torch.einsum("boi,boif->bof", [c, u])  # [B, O, F]
          v = self.squash(v)
          b = torch.einsum("bof,boif->boi", [v, u])  # [B, O, I]
  
      return v
  
file_path: DeepKE/src/deepke/relation_extraction/standard/module/Capsule.py
imports: import logging
  import torch
  import torch.nn
label_desc: Use image node_id 2 for calling the Capsule obj's underlying member method code with example usage: obj.forward(x) and returns: v