class_docstr: KGCN is a knowledge-based recommendation model that captures inter-item relatedness effectively by mining their
  associated attributes on the KG. To automatically discover both high-order structure information and semantic
  information of the KG, we treat KG as an undirected graph and sample from the neighbors for each entity in the KG
  as their receptive field, then combine neighborhood information with bias when calculating the representation of a
  given entity.
class_docstr_tok: ["KGCN","is","a","knowledge-based","recommendation","model","that","captures","inter-item","relatedness","effectively","by","mining","their","associated","attributes","on","the","KG",".","To","automatically","discover","both","high-order","structure","information","and","semantic","information","of","the","KG",",","we","treat","KG","as","an","undirected","graph","and","sample","from","the","neighbors","for","each","entity","in","the","KG","as","their","receptive","field",",","then","combine","neighborhood","information","with","bias","when","calculating","the","representation","of","a","given","entity","."]
docstr: For each item, aggregate the entity representation and its neighborhood representation into a single vector.
  
  Args:
      user_embeddings(torch.FloatTensor): The embeddings of users, shape: [batch_size, embedding_size]
      entities(list): entities is a list of i-iter (i = 0, 1, ..., n_iter) neighbors for the batch of items.
                      dimensions of entities: {[batch_size, 1],
                      [batch_size, n_neighbor],
                      [batch_size, n_neighbor^2],
                      ...,
                      [batch_size, n_neighbor^n_iter]}
      relations(list): relations is a list of i-iter (i = 0, 1, ..., n_iter) corresponding relations for entities.
                       relations have the same shape as entities.
  
  Returns:
      item_embeddings(torch.FloatTensor): The embeddings of items, shape: [batch_size, embedding_size]
docstr_tok: ["For","each","item",",","aggregate","the","entity","representation","and","its","neighborhood","representation","into","a","single","vector",".","Args",":","user_embeddings","(","torch.FloatTensor",")",":","The","embeddings","of","users",",","shape",":","[","batch_size",",","embedding_size","]","entities","(","list",")",":","entities","is","a","list","of","i-iter","(","i","=","0",",","1",",","...",",","n_iter",")","neighbors","for","the","batch","of","items",".","dimensions","of","entities",":","{","[","batch_size",",","1","]",",","[","batch_size",",","n_neighbor","]",",","[","batch_size",",","n_neighbor^2","]",",","...",",","[","batch_size",",","n_neighbor^n_iter","]","}","relations","(","list",")",":","relations","is","a","list","of","i-iter","(","i","=","0",",","1",",","...",",","n_iter",")","corresponding","relations","for","entities",".","relations","have","the","same","shape","as","entities",".","Returns",":","item_embeddings","(","torch.FloatTensor",")",":","The","embeddings","of","items",",","shape",":","[","batch_size",",","embedding_size","]"]
code: def aggregate(self, user_embeddings, entities, relations):
      r"""For each item, aggregate the entity representation and its neighborhood representation into a single vector.
  
      Args:
          user_embeddings(torch.FloatTensor): The embeddings of users, shape: [batch_size, embedding_size]
          entities(list): entities is a list of i-iter (i = 0, 1, ..., n_iter) neighbors for the batch of items.
                          dimensions of entities: {[batch_size, 1],
                          [batch_size, n_neighbor],
                          [batch_size, n_neighbor^2],
                          ...,
                          [batch_size, n_neighbor^n_iter]}
          relations(list): relations is a list of i-iter (i = 0, 1, ..., n_iter) corresponding relations for entities.
                           relations have the same shape as entities.
  
      Returns:
          item_embeddings(torch.FloatTensor): The embeddings of items, shape: [batch_size, embedding_size]
  
      """
      entity_vectors = [self.entity_embedding(i) for i in entities]
      relation_vectors = [self.relation_embedding(i) for i in relations]
  
      for i in range(self.n_iter):
          entity_vectors_next_iter = []
          for hop in range(self.n_iter - i):
              shape = (
                  self.batch_size,
                  -1,
                  self.neighbor_sample_size,
                  self.embedding_size,
              )
              self_vectors = entity_vectors[hop]
              neighbor_vectors = entity_vectors[hop + 1].reshape(shape)
              neighbor_relations = relation_vectors[hop].reshape(shape)
  
              neighbors_agg = self.mix_neighbor_vectors(
                  neighbor_vectors, neighbor_relations, user_embeddings
              )  # [batch_size, -1, dim]
  
              if self.aggregator_class == "sum":
                  output = (self_vectors + neighbors_agg).reshape(
                      -1, self.embedding_size
                  )  # [-1, dim]
              elif self.aggregator_class == "neighbor":
                  output = neighbors_agg.reshape(
                      -1, self.embedding_size
                  )  # [-1, dim]
              elif self.aggregator_class == "concat":
                  # [batch_size, -1, dim * 2]
                  output = torch.cat(
                      [self_vectors, neighbors_agg], dim=-1
                  )
                  output = output.reshape(
                      -1, self.embedding_size * 2
                  )  # [-1, dim * 2]
              else:
                  raise Exception(
                      "Unknown aggregator: " + self.aggregator_class
                  )
  
              output = self.linear_layers[i](output)
              # [batch_size, -1, dim]
              output = output.reshape(
                  self.batch_size, -1, self.embedding_size
              )
  
              if i == self.n_iter - 1:
                  vector = self.Tanh(output)
              else:
                  vector = self.ReLU(output)
  
              entity_vectors_next_iter.append(vector)
          entity_vectors = entity_vectors_next_iter
  
      item_embeddings = entity_vectors[0].reshape(
          self.batch_size, self.embedding_size
      )
  
      return item_embeddings
  
file_path: RecBole/recbole/model/knowledge_aware_recommender/kgcn.py
imports: import numpy
  import torch
  import torch.nn
  from recbole.model.abstract_recommender import KnowledgeRecommender
  from recbole.model.init import xavier_normal_initialization
  from recbole.model.loss import EmbLoss
  from recbole.utils import InputType
label_desc: Use image node_id 5 for calling the KGCN obj's underlying member method code with example usage: obj.aggregate(user_embeddings, entities, relations) and returns: item_embeddings