code: def loss(self, predict, target, reduction="mean"):
      m_plus, m_minus, loss_lambda = 0.9, 0.1, 0.5
  
      target = to_one_hot(target, self.num_attributes)
      max_l = (torch.relu(m_plus - predict)) ** 2
      max_r = (torch.relu(predict - m_minus)) ** 2
      loss = target * max_l + loss_lambda * (1 - target) * max_r
      loss = torch.sum(loss, dim=-1)
  
      if reduction == "sum":
          return loss.sum()
      else:
          # 默认情况为求平均
          return loss.mean()
  
file_path: DeepKE/src/deepke/attribution_extraction/standard/models/Capsule.py
imports: import os
  import sys
  import torch
  from .None import BasicModule
  from module import Embedding, CNN
  from module import Capsule
  from utils import seq_len_to_mask, to_one_hot
label_desc: Use image node_id 3 for calling the Capsule obj's underlying member method code with example usage: obj.loss(predict, target, reduction) and returns: loss, loss