code: def attention_kbc_model(
      config, train_graph, is_train_ph, input_tensors
  ):
      """Use attention model to score candidates for kbc."""
      # with tf.variable_scope(scope, reuse=reuse):
      # if reuse:
      #   tf_scope.reuse_variables()
      s, nbrs_s, r, candidates, nbrs_candidates = input_tensors
      model = {}
      entity_encoder = encoders.EmbeddingLookup(
          config.emb_dim,
          is_train_ph,
          train_dropout=config.entity_encoder_dropout,
          input_dim=train_graph.ent_vocab_size,
          scope="entity_embeddings",
      )
      model["entity_encoder"] = entity_encoder
      if config.use_separate_attention_emb:
          init_entity_encoder = encoders.EmbeddingLookup(
              config.emb_dim,
              is_train_ph,
              train_dropout=config.init_entity_encoder_dropout,
              input_dim=train_graph.ent_vocab_size,
              scope="init_entity_embeddings",
          )
      else:
          init_entity_encoder = entity_encoder
      model["init_entity_encoder"] = init_entity_encoder
      relation_encoder = encoders.EmbeddingLookup(
          config.emb_dim,
          is_train_ph,
          train_dropout=config.relation_encoder_dropout,
          input_dim=train_graph.rel_vocab_size,
          scope="relation_embeddings",
      )
      model["relation_encoder"] = relation_encoder
  
      attention_encoder = encoders.NbrAttentionEmbedding(
          config.emb_dim,
          is_train_ph,
          train_dropout=config.attention_encoder_dropout,
          emb_dim=config.emb_dim,
          scope="attention",
      )
      model["attention_encoder"] = attention_encoder
  
      source_emb = entity_encoder.lookup(s)
      nbrs_source_emb = init_entity_encoder.lookup(nbrs_s)
      relation_emb = relation_encoder.lookup(r)
      candidates_emb = entity_encoder.lookup(candidates)
      candidates_emb_flat = tf.reshape(
          candidates_emb, (-1, entity_encoder.emb_dim)
      )
      nbrs_candidates_emb = init_entity_encoder.lookup(nbrs_candidates)
      if config.max_neighbors:
          max_neighbors = config.max_neighbors
      else:
          max_neighbors = train_graph.max_neighbors
      nbrs_candidates_emb_flat = tf.reshape(
          nbrs_candidates_emb,
          (-1, max_neighbors, init_entity_encoder.emb_dim),
      )
      relation_emb_expand = tf.expand_dims(relation_emb, 1)
      relation_emb_tile = tf.tile(
          relation_emb_expand,  # [1, config.max_negatives+1, 1]
          tf.concat([[1], tf.shape(candidates)[-1:], [1]], 0),
      )
      relation_emb_tile_flat = tf.reshape(
          relation_emb_tile, [-1, config.emb_dim]
      )
  
      # Perform attention to construct feature vectors
      mask_nbrs_s = tf.cast(
          tf.not_equal(nbrs_s, train_graph.ent_pad), tf.float32
      )
      mask_nbrs_candidates = tf.cast(
          tf.reshape(
              tf.not_equal(nbrs_candidates, train_graph.ent_pad),
              (-1, max_neighbors),
          ),
          tf.float32,
      )
  
      source_vec = attention_encoder.attend(
          source_emb,
          nbrs_source_emb,
          relation_emb,
          mask_nbrs_s,
          name="source",
      )
      # source_vec_tile = tf.tile(
      #     tf.expand_dims(source_vec, 1), [1, config.max_negatives + 1, 1]
      # )
      candidates_vec = attention_encoder.attend(
          candidates_emb_flat,
          nbrs_candidates_emb_flat,
          relation_emb_tile_flat,
          mask_nbrs_candidates,
          name="candidates",
      )
      candidates_vec = tf.reshape(
          candidates_vec,
          tf.concat(
              [tf.shape(candidates_emb)[:2], [config.emb_dim]], 0
          ),
      )
  
      # Score candidates
      source_dot_query = source_vec * relation_emb
      scores = tf.squeeze(
          tf.matmul(
              tf.expand_dims(source_dot_query, 1),
              candidates_vec,
              transpose_b=True,
          ),
          axis=1,
      )
  
      # loss = losses.softmax_crossentropy(logits=candidates_scores, labels=labels)
  
      return scores, model
  
file_path: neural-structured-learning/research/a2n/models.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import encoders
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: attention_kbc_model(config, train_graph, is_train_ph, input_tensors) and returns: scores,  model