Exemplo n.º 1
0
 def get_batch_data(x_f,
                    sen_len_f,
                    x_b,
                    sen_len_b,
                    n_asp_b,
                    yi,
                    y_sen_i,
                    target,
                    tl,
                    batch_size,
                    is_shuffle=True):
     # for index in batch_index(len(yi), batch_size, 1, is_shuffle):
     for index in batch_index(len(n_asp_b), batch_size, 1, is_shuffle):
         selected_rows = itemgetter(*index)(list(n_asp_b.values()))
         r_index = []
         for idxs in selected_rows:
             if idxs != []:
                 r_index.extend(idxs)
         _n_asp = np.asarray(
             [len(tup) for tup in list(selected_rows) if len(tup) != 0])
         # print(f"length of _n_asp: {_n_asp.shape[0]}")
         feed_dict = {
             x: x_f[r_index],
             x_bw: x_b[r_index],
             y: yi[r_index],
             y_sen: y_sen_i[index],
             n_asp: _n_asp,
             sen_len: sen_len_f[r_index],
             sen_len_bw: sen_len_b[r_index],
             target_words: target[r_index],
             tar_len: tl[r_index]
         }
         yield feed_dict, len(r_index)
Exemplo n.º 2
0
 def train_get_batch_data(x_f,
                          sen_len_f,
                          x_b,
                          sen_len_b,
                          yi,
                          target,
                          tl,
                          batch_size,
                          kp1,
                          kp2,
                          learning,
                          moment,
                          is_shuffle=True):
     for index in batch_index(len(yi), batch_size, 1, is_shuffle):
         feed_dict = {
             x: x_f[index],
             x_bw: x_b[index],
             y: yi[index],
             sen_len: sen_len_f[index],
             sen_len_bw: sen_len_b[index],
             target_words: target[index],
             tar_len: tl[index],
             keep_prob1: kp1,
             keep_prob2: kp2,
             learning_rate: learning,
             momentum: moment,
         }
         yield feed_dict, len(index)
Exemplo n.º 3
0
 def get_batches(self, x, y=None, batch_size=100, is_shuffle=True):
     for index in batch_index(len(x), batch_size, is_shuffle=is_shuffle):
         n = len(index)
         feed_dict = {self.x: x[index]}
         if y is not None:
             feed_dict[self.y] = y[index]
         yield feed_dict, n
Exemplo n.º 4
0
 def get_batch_data(self, x, y, batch_size, keep_prob):
     for index in batch_index(len(y), batch_size, 1):
         feed_dict = {
             self.x: x[index],
             self.y: y[index],
             self.dropout_keep_prob: keep_prob,
         }
         yield feed_dict, len(index)
Exemplo n.º 5
0
 def get_batch_data(self, x, y, sen_len, batch_size, keep_prob):
     for index in batch_index(len(y), batch_size, 1):
         feed_dict = {
             self.x: x[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.dropout_keep_prob: keep_prob,
         }
         yield feed_dict, len(index)
Exemplo n.º 6
0
 def get_batch_data(self, x, sen_len, y, target_words, batch_size, keep_prob1, keep_prob2, is_shuffle=True):
     for index in batch_index(len(y), batch_size, 1, is_shuffle):
         feed_dict = {
             self.x: x[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.aspect_id: target_words[index],
             self.keep_prob1: keep_prob1,
             self.keep_prob2: keep_prob2,
         }
         yield feed_dict, len(index)
Exemplo n.º 7
0
 def get_batch_data(self, x_fw, len_fw, x_bw, len_bw, y, batch_size,
                    keep_prob):
     for index in batch_index(len(y), batch_size, 1):
         feed_dict = {
             self.x_fw: x_fw[index],
             self.x_bw: x_bw[index],
             self.y: y[index],
             self.len_fw: len_fw[index],
             self.len_bw: len_bw[index],
             self.dropout_keep_prob: keep_prob
         }
         yield feed_dict, len(index)
Exemplo n.º 8
0
 def get_batch_data(self, x, sen_len, x_bw, sen_len_bw, y, target_words, batch_size, keep_prob):
     for index in batch_index(len(y), batch_size, 1):
         feed_dict = {
             self.x: x[index],
             self.x_bw: x_bw[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.sen_len_bw: sen_len_bw[index],
             self.target_words: target_words[index],
             self.dropout_keep_prob: keep_prob,
         }
         yield feed_dict, len(index)
Exemplo n.º 9
0
 def get_batch_data(self, x, sen_len, x_bw, sen_len_bw, y, batch_size,
                    keep_prob):
     for index in batch_index(len(y), batch_size, 1, is_shuffle=False):
         feed_dict = {
             self.x: x[index],
             self.x_bw: x_bw[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.sen_len_bw: sen_len_bw[index],
             self.dropout_keep_prob: keep_prob,
         }
         yield feed_dict, len(index)
Exemplo n.º 10
0
 def get_batch_data(self, x, sen_len, x_bw, sen_len_bw, y, target_words, batch_size, keep_prob):
     for index in batch_index(len(y), batch_size, 1):
         feed_dict = {
             self.x: x[index],
             self.x_bw: x_bw[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.sen_len_bw: sen_len_bw[index],
             self.target_words: target_words[index],
             self.dropout_keep_prob: keep_prob,
         }
         yield feed_dict, len(index)
 def get_batch_data(self, x, sen_len, y, target_words, batch_size, keep_prob1, keep_prob2, is_shuffle=True):
     if y!=None:
         for index in batch_index(len(y), batch_size, 1, is_shuffle):
             feed_dict = {
                 self.x: x[index],
                 self.y: y[index],
                 self.sen_len: sen_len[index],
                 self.aspect: target_words[index],
                 self.keep_prob1: keep_prob1,
                 self.keep_prob2: keep_prob2,
             }
             yield feed_dict, len(index)
     else:
         for index in batch_index(len(sen_len), batch_size, 1, None):
             feed_dict = {
                 self.x: x[index],
                 self.sen_len: sen_len[index],
                 self.aspect: target_words[index],
                 self.keep_prob1: keep_prob1,
                 self.keep_prob2: keep_prob2,
             }
             yield feed_dict, len(index)
Exemplo n.º 12
0
    def get_batch_data(self, x, sen_len, y, target_words, batch_size, keep_prob1, keep_prob2, is_shuffle=True):
        for index in batch_index(len(y), batch_size, 1, is_shuffle):

            #print ('第一个batch训练集下标',index)

            feed_dict = {
                self.x: x[index],
                self.y: y[index],
                self.sen_len: sen_len[index],
                self.aspect_id: target_words[index],
                self.keep_prob1: keep_prob1,
                self.keep_prob2: keep_prob2,
            }
            yield feed_dict, len(index)
Exemplo n.º 13
0
 def get_batches(self, X, y=None, batch_size=100, shuffle=True):
     x, sen_len, x_bw, sen_len_bw, target_words = X
     for index in batch_index(len(x), batch_size, shuffle):
         n = len(index)
         feed_dict = {
             self.x: x[index],
             self.x_bw: x_bw[index],
             self.sen_len: sen_len[index],
             self.sen_len_bw: sen_len_bw[index],
             self.target_words: target_words[index],
         }
         if y is not None:
             feed_dict[self.y] = y[index]
         yield feed_dict, n
Exemplo n.º 14
0
 def get_batch_data(self,
                    x,
                    y,
                    sen_len,
                    aspect,
                    position,
                    batch_size,
                    is_shuffle=True):
     for index in batch_index(len(y), batch_size, 1, is_shuffle):
         feed_dict = {
             self.x: x[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.aspect_id: aspect[index],
             self.position: position[index]
         }
         yield feed_dict, len(index)
Exemplo n.º 15
0
 def get_batch_data(x_f, sen_len_f, x_b, sen_len_b, yi, target, tl, batch_size, kp1, kp2, senshort, sen, multMask, is_shuffle=True):
     for index in batch_index(len(yi), batch_size, 1, is_shuffle):
             
         feed_dict = {
             x: x_f[index],
             x_bw: x_b[index],
             y: yi[index],
             sen_len: sen_len_f[index],
             sen_len_bw: sen_len_b[index],
             target_words: target[index],
             tar_len: tl[index],
             keep_prob1: kp1,
             keep_prob2: kp2,
             sent_short: sen[index],
             sent: sen[index],
             mult_mask: multMask[index]
         }
         yield feed_dict, len(index)
Exemplo n.º 16
0
 def get_batch_data(self,
                    x,
                    pos,
                    sen_len,
                    y,
                    entity,
                    aspect,
                    batch_size,
                    keep_prob1,
                    keep_prob2,
                    is_shuffle=True):
     for index in batch_index(len(y), batch_size, 1, is_shuffle):
         feed_dict = {
             self.x: x[index],
             self.pos_x: pos[index],
             self.y: y[index],
             self.sen_len: sen_len[index],
             self.entity_id: entity[index],
             self.aspect_id: aspect[index],
             self.keep_prob1: keep_prob1,
             self.keep_prob2: keep_prob2,
         }
         yield feed_dict, len(index)
Exemplo n.º 17
0
 def get_batch_data(x_f,
                    sen_len_f,
                    x_b,
                    sen_len_b,
                    yi,
                    target,
                    tl,
                    batch_size,
                    kp1,
                    kp2,
                    is_shuffle=True):
     for index in batch_index(len(yi), batch_size, 1, is_shuffle):
         feed_dict = {
             x_real: x_f[index],
             x_bw: x_b[index],
             y_real: yi[index],
             sen_len: sen_len_f[index],
             sen_len_bw: sen_len_b[index],
             target_words: target[index],
             tar_len: tl[index],
             keep_prob1: kp1,
             keep_prob2: kp2,
         }
         yield feed_dict, len(index)