class_docstr: FwFM is a context-based recommendation model. It aims to model the different feature interactions
  between different fields in a much more memory-efficient way. It proposes a field pair weight matrix
  :math:`r_{F(i),F(j)}`, to capture the heterogeneity of field pair interactions.
  
  The model defines as follows:
  
  .. math::
     y = w_0 + \sum_{i=1}^{m}x_{i}w_{i} + \sum_{i=1}^{m}\sum_{j=i+1}^{m}x_{i}x_{j}<v_{i}, v_{j}>r_{F(i),F(j)}
class_docstr_tok: ["FwFM","is","a","context-based","recommendation","model",".","It","aims","to","model","the","different","feature","interactions","between","different","fields","in","a","much","more","memory-efficient","way",".","It","proposes","a","field","pair","weight","matrix",":","math",":","`","r_","{","F","(","i",")",",","F","(","j",")","}","`",",","to","capture","the","heterogeneity","of","field","pair","interactions",".","The","model","defines","as","follows",":","..","math",":",":","y","=","w_0","+","\\sum_","{","i=1","}","^","{","m","}","x_","{","i","}","w_","{","i","}","+","\\sum_","{","i=1","}","^","{","m","}","\\sum_","{","j=i+1","}","^","{","m","}","x_","{","i","}","x_","{","j","}","<","v_","{","i","}",",","v_","{","j","}",">","r_","{","F","(","i",")",",","F","(","j",")","}"]
docstr: Get the field pair weight matrix r_{F(i),F(j)}, and model the different interaction strengths of
  different field pairs :math:`\sum_{i=1}^{m}\sum_{j=i+1}^{m}x_{i}x_{j}<v_{i}, v_{j}>r_{F(i),F(j)}`.
  
  Args:
      infeature (torch.cuda.FloatTensor): [batch_size, field_size, embed_dim]
  
  Returns:
      torch.cuda.FloatTensor: [batch_size, 1]
docstr_tok: ["Get","the","field","pair","weight","matrix","r_","{","F","(","i",")",",","F","(","j",")","}",",","and","model","the","different","interaction","strengths","of","different","field","pairs",":","math",":","`","\\sum_","{","i=1","}","^","{","m","}","\\sum_","{","j=i+1","}","^","{","m","}","x_","{","i","}","x_","{","j","}","<","v_","{","i","}",",","v_","{","j","}",">","r_","{","F","(","i",")",",","F","(","j",")","}","`",".","Args",":","infeature","(","torch.cuda.FloatTensor",")",":","[","batch_size",",","field_size",",","embed_dim","]","Returns",":","torch.cuda.FloatTensor",":","[","batch_size",",","1","]"]
code: def fwfm_layer(self, infeature):
      r"""Get the field pair weight matrix r_{F(i),F(j)}, and model the different interaction strengths of
      different field pairs :math:`\sum_{i=1}^{m}\sum_{j=i+1}^{m}x_{i}x_{j}<v_{i}, v_{j}>r_{F(i),F(j)}`.
  
      Args:
          infeature (torch.cuda.FloatTensor): [batch_size, field_size, embed_dim]
  
      Returns:
          torch.cuda.FloatTensor: [batch_size, 1]
      """
      # get r(Fi, Fj)
      batch_size = infeature.shape[0]
      weight = self.weight.expand(batch_size, -1, -1, -1)
  
      fwfm_inter = list()  # [batch_size, num_fields, emb_dim]
      for i in range(self.num_features - 1):
          for j in range(i + 1, self.num_features):
              Fi, Fj = self.feature2field[i], self.feature2field[j]
              fwfm_inter.append(
                  infeature[:, i] * infeature[:, j] * weight[:, Fi, Fj]
              )
      fwfm_inter = torch.stack(fwfm_inter, dim=1)
      fwfm_inter = torch.sum(fwfm_inter, dim=1)  # [batch_size, emb_dim]
      fwfm_inter = self.dropout_layer(fwfm_inter)
  
      fwfm_output = torch.sum(
          fwfm_inter, dim=1, keepdim=True
      )  # [batch_size, 1]
  
      return fwfm_output
  
file_path: RecBole/recbole/model/context_aware_recommender/fwfm.py
imports: import torch
  import torch.nn
  from torch.nn.init import xavier_normal_, constant_
  from recbole.model.abstract_recommender import ContextRecommender
label_desc: Use image node_id 4 for calling the FwFM obj's underlying member method code with example usage: obj.fwfm_layer(infeature) and returns: fwfm_output