class_docstr: This is a abstract context-aware recommender. All the context-aware model should implement this class.
  The base context-aware recommender class provide the basic embedding function of feature fields which also
  contains a first-order part of feature fields.
class_docstr_tok: ["This","is","a","abstract","context-aware","recommender",".","All","the","context-aware","model","should","implement","this","class",".","The","base","context-aware","recommender","class","provide","the","basic","embedding","function","of","feature","fields","which","also","contains","a","first-order","part","of","feature","fields","."]
code: def __init__(self, config, dataset):
      super(ContextRecommender, self).__init__()
  
      self.field_names = dataset.fields(
          source=[
              FeatureSource.INTERACTION,
              FeatureSource.USER,
              FeatureSource.USER_ID,
              FeatureSource.ITEM,
              FeatureSource.ITEM_ID,
          ]
      )
      self.LABEL = config["LABEL_FIELD"]
      self.embedding_size = config["embedding_size"]
      self.device = config["device"]
      self.double_tower = config["double_tower"]
      self.numerical_features = config["numerical_features"]
      if self.double_tower is None:
          self.double_tower = False
      self.token_field_names = []
      self.token_field_dims = []
      self.float_field_names = []
      self.float_field_dims = []
      self.token_seq_field_names = []
      self.token_seq_field_dims = []
      self.float_seq_field_names = []
      self.float_seq_field_dims = []
      self.num_feature_field = 0
  
      if self.double_tower:
          self.user_field_names = dataset.fields(
              source=[FeatureSource.USER, FeatureSource.USER_ID]
          )
          self.item_field_names = dataset.fields(
              source=[FeatureSource.ITEM, FeatureSource.ITEM_ID]
          )
          self.field_names = (
              self.user_field_names + self.item_field_names
          )
          self.user_token_field_num = 0
          self.user_float_field_num = 0
          self.user_token_seq_field_num = 0
          for field_name in self.user_field_names:
              if dataset.field2type[field_name] == FeatureType.TOKEN:
                  self.user_token_field_num += 1
              elif (
                  dataset.field2type[field_name]
                  == FeatureType.TOKEN_SEQ
              ):
                  self.user_token_seq_field_num += 1
              else:
                  self.user_float_field_num += 1
          self.item_token_field_num = 0
          self.item_float_field_num = 0
          self.item_token_seq_field_num = 0
          for field_name in self.item_field_names:
              if dataset.field2type[field_name] == FeatureType.TOKEN:
                  self.item_token_field_num += 1
              elif (
                  dataset.field2type[field_name]
                  == FeatureType.TOKEN_SEQ
              ):
                  self.item_token_seq_field_num += 1
              else:
                  self.item_float_field_num += 1
  
      for field_name in self.field_names:
          if field_name == self.LABEL:
              continue
          if dataset.field2type[field_name] == FeatureType.TOKEN:
              self.token_field_names.append(field_name)
              self.token_field_dims.append(dataset.num(field_name))
          elif dataset.field2type[field_name] == FeatureType.TOKEN_SEQ:
              self.token_seq_field_names.append(field_name)
              self.token_seq_field_dims.append(dataset.num(field_name))
          elif (
              dataset.field2type[field_name] == FeatureType.FLOAT
              and field_name in self.numerical_features
          ):
              self.float_field_names.append(field_name)
              self.float_field_dims.append(dataset.num(field_name))
          elif (
              dataset.field2type[field_name] == FeatureType.FLOAT_SEQ
              and field_name in self.numerical_features
          ):
              self.float_seq_field_names.append(field_name)
              self.float_seq_field_dims.append(dataset.num(field_name))
          else:
              continue
  
          self.num_feature_field += 1
      if len(self.token_field_dims) > 0:
          self.token_field_offsets = np.array(
              (0, *np.cumsum(self.token_field_dims)[:-1]), dtype=np.long
          )
          self.token_embedding_table = FMEmbedding(
              self.token_field_dims,
              self.token_field_offsets,
              self.embedding_size,
          )
      if len(self.float_field_dims) > 0:
          self.float_field_offsets = np.array(
              (0, *np.cumsum(self.float_field_dims)[:-1]), dtype=np.long
          )
          self.float_embedding_table = FLEmbedding(
              self.float_field_dims,
              self.float_field_offsets,
              self.embedding_size,
          )
      if len(self.token_seq_field_dims) > 0:
          self.token_seq_embedding_table = nn.ModuleList()
          for token_seq_field_dim in self.token_seq_field_dims:
              self.token_seq_embedding_table.append(
                  nn.Embedding(token_seq_field_dim, self.embedding_size)
              )
      if len(self.float_seq_field_dims) > 0:
          self.float_seq_embedding_table = nn.ModuleList()
          for float_seq_field_dim in self.float_seq_field_dims:
              self.float_seq_embedding_table.append(
                  nn.Embedding(float_seq_field_dim, self.embedding_size)
              )
  
      self.first_order_linear = FMFirstOrderLinear(config, dataset)
  
imports: from logging import getLogger
  import numpy
  import torch
  import torch.nn
  from recbole.model.layers import FMEmbedding, FMFirstOrderLinear, FLEmbedding
  from recbole.utils import ModelType, InputType, FeatureSource, FeatureType, set_color
label_desc: Use image node_id 1 to create a new ContextRecommender object from inherited base classes: AbstractRecommender with example: obj = ContextRecommender(config, dataset)