예제 #1
0
    def __init__(self, type_content_data):
        super(SequenceDecodeModel, self).__init__(type_content_data)
        self.token_lstm = YLSTMCell(0)
        number_of_tokens = self.type_content_data[all_token_summary][
            TokenHitNum]
        self.linear_token_output_w = tf.Variable(
            random_uniform_variable_initializer(256, 566,
                                                [number_of_tokens, num_units]))
        self.one_hot_token_embedding = tf.Variable(
            random_uniform_variable_initializer(256, 56,
                                                [number_of_tokens, num_units]))
        self.token_embedder = TokenAtomEmbed(self.type_content_data,
                                             self.one_hot_token_embedding)
        self.token_attention = None
        if decode_attention_way > decode_no_attention:
            self.token_attention = YAttention(10)

        self.dup_token_lstm, self.dup_one_hot_token_embedding, self.dup_token_embedder, self.dup_token_pointer = None, None, None, None
        #     if use_dup_model:
        #       self.dup_token_lstm = YLSTMCell(125)
        #       self.dup_one_hot_token_embedding = tf.Variable(random_uniform_variable_initializer(25, 56, [number_of_tokens, num_units]))
        #       self.dup_token_embedder = TokenAtomEmbed(self.type_content_data, self.dup_one_hot_token_embedding)
        #       self.dup_token_pointer = PointerNetwork(222)

        self.token_decoder = TokenDecoder(self.type_content_data,
                                          self.metrics_index,
                                          self.linear_token_output_w,
                                          self.token_attention,
                                          self.dup_token_pointer)
    def __init__(self, type_content_data):
        super(TreeDecodeModel, self).__init__(type_content_data)
        self.direct_descedent_lstm = YLSTMCell(0)
        if tree_decode_way == tree_decode_2d:
            self.two_dimen_lstm = Y2DLSTMCell(1)
        elif tree_decode_way == tree_decode_embed:
            self.one_dimen_lstm = YLSTMCell(2)

        number_of_tokens = self.type_content_data[all_token_summary][
            TokenHitNum]
        self.linear_token_output_w = tf.Variable(
            random_uniform_variable_initializer(256, 566,
                                                [number_of_tokens, num_units]))
        self.one_hot_token_embedding = tf.Variable(
            random_uniform_variable_initializer(256, 56,
                                                [number_of_tokens, num_units]))
        self.one_hot_token_cell_embedding = tf.Variable(
            random_uniform_variable_initializer(25, 56,
                                                [number_of_tokens, num_units]))
        self.token_embedder = TokenAtomEmbed(self.type_content_data,
                                             self.one_hot_token_embedding)
        self.token_cell_embedder = TokenAtomEmbed(
            self.type_content_data, self.one_hot_token_cell_embedding)

        self.encode_tree = EncodeOneAST(self.type_content_data,
                                        self.token_embedder,
                                        self.token_cell_embedder)
예제 #3
0
 def __init__(self, num_desc):
     self.merger = EmbedMerger(num_desc)
     self.memory_update_lstm = YLSTMCell(30 + num_desc)
     self.initial_cell = tf.Variable(
         random_uniform_variable_initializer(175, 525 + num_desc,
                                             [1, num_units]))
     self.initial_h = tf.Variable(
         random_uniform_variable_initializer(1755, 525 + num_desc,
                                             [1, num_units]))
예제 #4
0
 def __init__(self, type_content_data, vocab_embeddings):
     self.type_content_data = type_content_data
     self.vocab_embeddings = vocab_embeddings
     self.sword_embed = SwordAtomEmbed(self.type_content_data,
                                       self.vocab_embeddings)
     self.merger = EmbedMerger()
     self.forward_lstm = YLSTMCell(15)
     self.backward_lstm = YLSTMCell(25)
     self.ini_forward_cell = tf.Variable(
         random_uniform_variable_initializer(881, 882, [1, num_units]))
     self.ini_forward_h = tf.Variable(
         random_uniform_variable_initializer(883, 884, [1, num_units]))
     self.ini_backward_cell = tf.Variable(
         random_uniform_variable_initializer(885, 886, [1, num_units]))
     self.ini_backward_h = tf.Variable(
         random_uniform_variable_initializer(887, 888, [1, num_units]))
 def __init__(self, num_desc):
   self.w = tf.Variable(random_uniform_variable_initializer(222, 333+num_desc, [2 * num_units, 5 * num_units], ini_range=lstm_initialize_range))
   self.b = tf.Variable(zero_variable_initializer([1, 5 * num_units]))
   if embed_merger_use_layer_norm:
     self.norm_weights = []
     self.norm_biases = []
     for _ in range(6):
       self.norm_weights.append(tf.Variable(one_variable_initializer([num_units])))
       self.norm_biases.append(tf.Variable(zero_variable_initializer([num_units])))
예제 #6
0
    def initialize_parameters(self):

        self.skeleton_lstm_cell = YLSTMCell(1)

        self.one_hot_skeleton_embedding = tf.Variable(
            random_uniform_variable_initializer(258, 578,
                                                [self.vocab_num, num_units]))
        self.skeleton_embedder = SkeletonAtomEmbed(
            self.type_content_data, self.one_hot_skeleton_embedding,
            self.vocab_num)
        self.linear_skeleton_output_w = tf.Variable(
            random_uniform_variable_initializer(257, 576,
                                                [self.vocab_num, num_units]))

        if skeleton_multi_decode_mode_on:
            self.skeleton_multi_decode_transfer = tf.Variable(
                random_uniform_variable_initializer(
                    527, 567,
                    [skeleton_multi_decode_num, num_units, num_units]))
 def __init__(self, type_content_data):
   super(StatementDupModel, self).__init__(type_content_data)
   number_of_tokens = self.type_content_data[all_token_summary][TokenHitNum]
   self.dup_skeleton_forward_cell_h = tf.Variable(random_uniform_variable_initializer(155, 572, [1, 2, num_units]))
   self.dup_skeleton_backward_cell_h = tf.Variable(random_uniform_variable_initializer(152, 572, [1, 2, num_units]))
   if atom_decode_mode == token_decode:
     self.one_dup_hot_token_embedding = tf.Variable(random_uniform_variable_initializer(252, 226, [number_of_tokens, num_units]))
     self.dup_token_embedder = TokenAtomEmbed(self.type_content_data, self.one_dup_hot_token_embedding)
     self.dup_token_lstm = YLSTMCell(9)
     self.dup_token_pointer = PointerNetwork(655)
     self.integrate_computer = None
     if compute_memory_in_memory_mode:
       self.integrate_computer = Y2DirectLSTMCell(105)
     if compute_token_memory:
       self.dup_mem_nn = NTMOneDirection(800)
       self.dup_forward_token_lstm = YLSTMCell(10)
       self.dup_backward_token_lstm = YLSTMCell(11)
     self.dup_token_decoder = DupTokenDecoder(type_content_data, self.metrics_index, self.dup_token_pointer) 
   else:
     assert False, "Wrong atom_decode_mode"
 def __init__(self, type_content_data, token_embedder, token_cell_embedder):
     self.type_content_data = type_content_data
     self.token_embedder = token_embedder
     self.token_cell_embedder = token_cell_embedder
     self.y2direct_lstm = Y2DirectLSTMCell(60)
     self.y2d_lstm = Y2DLSTMCell(61)
     self.y_lstm = YLSTMCell(62)
     if tree_leaf_one_more_lstm_step:
         self.y_leaf_lstm = YLSTMCell(63)
     self.y_forward = YLSTMCell(64)
     self.y_backward = YLSTMCell(65)
     self.tree_leaf_one_more_lstm_begin_cell_h = tf.Variable(
         random_uniform_variable_initializer(25, 5, [2, num_units]))
 def __init__(self, type_content_data):
     self.type_content_data = type_content_data
     self.statistical_metrics_meta = default_metrics_meta + self.create_extra_default_metrics_meta(
     ) + special_handle_metrics_meta
     self.metrics_meta = self.statistical_metrics_meta + self.create_in_use_tensors_meta(
     )
     self.metrics_name = [metric_m[0] for metric_m in self.metrics_meta]
     self.metrics_shape = [metric_m[1] for metric_m in self.metrics_meta]
     self.index_metrics = dict(
         (k, v)
         for k, v in zip(range(len(self.metrics_name)), self.metrics_name))
     self.metrics_index = {
         value: key
         for key, value in self.index_metrics.items()
     }
     self.metrics_contingent_index = create_metrics_contingent_index(
         self.metrics_meta)
     self.contingent_parameters = tf.Variable(
         random_uniform_variable_initializer(
             2, 5, [contingent_parameters_num, 1, num_units]))
     self.contingent_parameters_for_idle = tf.Variable(
         random_uniform_variable_initializer(20, 50, [2, 1, num_units]))
예제 #10
0
 def __init__(self, num_desc):
   if is_dup_mode == simple_is_dup:
     self.is_dup_w = tf.Variable(random_uniform_variable_initializer(200, 1080 + num_desc, [num_units, num_units], ini_range=lstm_initialize_range))
     self.is_not_dup_w = tf.Variable(random_uniform_variable_initializer(205, 1080 + num_desc, [num_units, num_units], ini_range=lstm_initialize_range))
   elif is_dup_mode == mlp_is_dup:
     self.is_dup_w = tf.Variable(random_uniform_variable_initializer(200, 1080 + num_desc, [2 * num_units, 2 * num_units], ini_range=lstm_initialize_range))
     self.is_dup_h = tf.Variable(random_uniform_variable_initializer(200, 1050 + num_desc, [1, 2 * num_units]))
     self.is_not_dup_w = tf.Variable(random_uniform_variable_initializer(205, 1080 + num_desc, [2 * num_units, 2 * num_units], ini_range=lstm_initialize_range))
     self.is_not_dup_h = tf.Variable(random_uniform_variable_initializer(205, 1060 + num_desc, [1, 2 * num_units]))
   elif is_dup_mode == sigmoid_is_dup:
     self.is_dup_h = tf.Variable(random_uniform_variable_initializer(200, 1050 + num_desc, [1, 2 * num_units]))
     if dup_use_two_poles:
       self.two_poles_merge_w = tf.Variable(random_uniform_variable_initializer(200, 1060 + num_desc, [2 * num_units, 1 * num_units], ini_range=lstm_initialize_range))
       self.two_poles_merge_b = tf.Variable(random_uniform_variable_initializer(200, 1070 + num_desc, [1, 1 * num_units]))
   else:
     assert False, "Unrecognized is_dup_mode!"
   self.dup_point_atten = YAttention(100 + num_desc)
   if repetition_mode == attention_repetition_mode:
     if dup_share_parameters:
       self.is_dup_point_atten = self.dup_point_atten
     else:
       self.is_dup_point_atten = YAttention(200 + num_desc)
예제 #11
0
 def __init__(self, num_desc):
   if attention_algorithm == v_attention:
     self.v = tf.Variable(random_uniform_variable_initializer(203, 21 + num_desc, [1, num_units]))
     self.w_v = tf.Variable(random_uniform_variable_initializer(2033, 231 + num_desc, [num_units, num_units], ini_range=lstm_initialize_range))
     self.w_h = tf.Variable(random_uniform_variable_initializer(2033, 131 + num_desc, [num_units, num_units], ini_range=lstm_initialize_range))
     self.w_ctx_c = tf.Variable(random_uniform_variable_initializer(203, 145 + num_desc, [2*num_units, num_units], ini_range=lstm_initialize_range))
   elif attention_algorithm == stand_attention:
     self.w = tf.Variable(random_uniform_variable_initializer(2033, 132 + num_desc, [num_units, num_units], ini_range=lstm_initialize_range))
   else:
     print("Strange Error! Unrecognized attention algorithm")
   self.w_ctx_h = tf.Variable(random_uniform_variable_initializer(203, 135 + num_desc, [2*num_units, num_units], ini_range=lstm_initialize_range))
예제 #12
0
 def __init__(self, num_desc, forget_bias=0.0, activation=tf.nn.tanh):
     self.forget_bias = forget_bias
     self.activation = activation
     self.w = tf.Variable(
         random_uniform_variable_initializer(
             9,
             88 + num_desc, [2 * num_units, 4 * num_units],
             ini_range=lstm_initialize_range))
     self.b = tf.Variable(zero_variable_initializer([1, 4 * num_units]))
     if use_layer_norm:
         self.norm_weights = []
         self.norm_biases = []
         for _ in range(5):
             self.norm_weights.append(
                 tf.Variable(one_variable_initializer([num_units])))
             self.norm_biases.append(
                 tf.Variable(zero_variable_initializer([num_units])))
    def __init__(self, type_content_data):
        super(LinearDupModel, self).__init__(type_content_data)
        number_of_tokens = self.type_content_data[all_token_summary][
            TokenHitNum]

        self.dup_token_lstm = YLSTMCell(125)
        self.dup_one_hot_token_embedding = tf.Variable(
            random_uniform_variable_initializer(25, 56,
                                                [number_of_tokens, num_units]))
        self.dup_token_embedder = TokenAtomEmbed(
            self.type_content_data, self.dup_one_hot_token_embedding)
        self.dup_token_pointer = PointerNetwork(222)

        self.integrate_computer = None
        if compute_memory_in_memory_mode:
            self.integrate_computer = Y2DirectLSTMCell(105)

        self.dup_token_decoder = DupTokenDecoder(self.type_content_data,
                                                 self.metrics_index,
                                                 self.dup_token_pointer)
예제 #14
0
  def __init__(self, type_content_data):
    super(StatementDecodeModel, self).__init__(type_content_data)
    
    self.ini_metrics = list(create_empty_tensorflow_tensors(self.metrics_meta, self.contingent_parameters, self.metrics_contingent_index))
    
    self.skeleton_forward_cell_h = tf.Variable(random_uniform_variable_initializer(255, 572, [1, 2, num_units]))
    self.skeleton_backward_cell_h = tf.Variable(random_uniform_variable_initializer(252, 572, [1, 2, num_units]))
    
    if compute_token_memory:
      self.mem_nn = NTMOneDirection(500)
      self.forward_token_lstm = YLSTMCell(3)
      self.backward_token_lstm = YLSTMCell(4)
      if compose_tokens_of_a_statement:
        if compose_mode == compose_one_way_lstm and (compose_one_way_lstm_mode == one_way_two_way_compose or compose_one_way_lstm_mode == one_way_three_way_compose):
          self.tokens_merger = Y2DirectLSTMCell(150)
        else:
          self.tokens_merger = EmbedMerger(150)
        if compose_mode == compose_one_way_lstm and compose_one_way_lstm_mode == one_way_three_way_compose:
          self.compose_lstm_cell = Y3DirectLSTMCell(5)
        else:
          self.compose_lstm_cell = YLSTMCell(5)
        if compose_mode == compose_bi_way_lstm:
          self.bi_way_merger = Y2DirectLSTMCell(155)
          self.bi_way_ini_cell = tf.Variable(random_uniform_variable_initializer(855, 55, [1, num_units]))
          self.bi_way_ini_h = tf.Variable(random_uniform_variable_initializer(850, 50, [1, num_units]))
          self.bi_way_lstm = YLSTMCell(52)
     
    self.token_attention = None
    if decode_attention_way > decode_no_attention:
      self.token_attention = YAttention(10)
     
    self.token_lstm = YLSTMCell(0)
    r_token_embedder_mode = token_embedder_mode
     
    number_of_tokens = self.type_content_data[all_token_summary][TokenHitNum]
    number_of_subwords = self.type_content_data[all_token_summary][SwordHitNum]
     
    if atom_decode_mode == token_decode:
      self.linear_token_output_w = tf.Variable(random_uniform_variable_initializer(256, 566, [number_of_tokens, num_units]))
      self.dup_token_embedder, self.dup_token_lstm, self.dup_token_pointer = None, None, None
#       if use_dup_model:
#         self.one_dup_hot_token_embedding = tf.Variable(random_uniform_variable_initializer(252, 226, [number_of_tokens, num_units]))
#         self.dup_token_embedder = TokenAtomEmbed(self.type_content_data, self.one_dup_hot_token_embedding)
#         self.dup_token_lstm = YLSTMCell(9)
#         self.dup_token_pointer = PointerNetwork(655)
#         self.dup_skeleton_forward_cell_h = tf.Variable(random_uniform_variable_initializer(155, 572, [number_of_skeletons, 2, num_units]))
#         self.dup_skeleton_backward_cell_h = tf.Variable(random_uniform_variable_initializer(152, 572, [number_of_skeletons, 2, num_units]))
#         if compute_token_memory:
#           self.dup_mem_nn = NTMOneDirection(800)
#           self.dup_forward_token_lstm = YLSTMCell(10)
#           self.dup_backward_token_lstm = YLSTMCell(11)
      self.token_decoder = TokenDecoder(type_content_data, self.metrics_index, self.linear_token_output_w, self.token_attention, self.dup_token_pointer)
       
    elif atom_decode_mode == sword_decode:
      self.linear_sword_output_w = tf.Variable(random_uniform_variable_initializer(256, 566, [number_of_subwords, num_units]))
      self.sword_lstm = YLSTMCell(12)
      r_token_embedder_mode = swords_compose_mode
      
    else:
      assert False, "Wrong atom_decode_mode"
       
    if r_token_embedder_mode == token_only_mode:
      self.one_hot_token_embedding = tf.Variable(random_uniform_variable_initializer(256, 56, [number_of_tokens, num_units]))
      self.token_embedder = TokenAtomEmbed(self.type_content_data, self.one_hot_token_embedding)
    elif r_token_embedder_mode == swords_compose_mode:
      self.one_hot_sword_embedding = tf.Variable(random_uniform_variable_initializer(256, 56, [number_of_subwords, num_units]))
      self.sword_embedder = SwordAtomEmbed(self.type_content_data, self.one_hot_sword_embedding)
      self.token_embedder = BiLSTMEmbed(self.type_content_data, self.one_hot_sword_embedding)
    else:
      assert False, "Wrong token_embedder_mode"