def __init__(self, num_input, num_output, input_layers, name=""): if len(input_layers) >= 2: self.X = T.concatenate( [input_layer.output() for input_layer in input_layers], axis=1) else: self.X = input_layers[0].output() self.W_yh = random_weights((num_input, num_output), name="W_yh_FC") self.b_y = zeros(num_output, name="b_y_FC") self.params = [self.W_yh, self.b_y]
def __init__(self, num_input, num_hidden, input_layers=None, name="", go_backwards=False): """ MGU Layer from 周志华paper Takes as input sequence of inputs, returns sequence of outputs """ self.name = name self.num_input = num_input self.num_hidden = num_hidden if len(input_layers) >= 2: # axis=1 an row xiang jia self.X = T.concatenate( [input_layer.output() for input_layer in input_layers], axis=1) else: self.X = input_layers[0].output() self.h0 = theano.shared(floatX(np.zeros(num_hidden))) self.s0 = theano.shared(floatX(np.zeros(num_hidden))) self.go_backwards = go_backwards self.W_fx = random_weights((num_input, num_hidden), name=self.name + "W_fx") self.W_fh = random_weights((num_hidden, num_hidden), name=self.name + "W_fh") self.U_h = random_weights((num_input, num_hidden), name=self.name + "U_h") self.W_h = random_weights((num_hidden, num_hidden), name=self.name + "W_h") self.b_f = zeros(num_hidden, name=self.name + "b_f") self.b_h = zeros(num_hidden, name=self.name + "b_h") self.params = [self.W_fx, self.W_fh, self.b_f] self.output()
def __init__(self, num_input, num_output, input_layers, name=""): if len(input_layers) >= 2: print "number of input layers: %s" % len(input_layers) print "len of list comprehension: %s" % len( [input_layer.output() for input_layer in input_layers]) self.X = T.concatenate( [input_layer.output() for input_layer in input_layers], axis=1) else: self.X = input_layers[0].output() self.W_yh = random_weights((num_input, num_output), name="W_yh") self.b_y = zeros(num_output, name="b_y") self.params = [self.W_yh, self.b_y]
def __init__(self, num_input, num_output, input_layer, temperature=1.0, name="FC"): self.name = name self.X = input_layer self.params = [] self.temp = temperature self.W_yh = random_weights((num_input, num_output), name="W_yh") self.b_y = zeros(num_output, name="b_y") self.params = [self.W_yh, self.b_y]
def __init__(self, num_input, num_cells, input_layers=None, name="", go_backwards=False): """ GRU Layer Takes as input sequence of inputs, returns sequence of outputs """ self.name = name self.num_input = num_input self.num_cells = num_cells if len(input_layers) >= 2: self.X = T.concatenate( [input_layer.output() for input_layer in input_layers], axis=1) else: self.X = input_layers[0].output() self.s0 = zeros(num_cells) self.go_backwards = go_backwards self.U_z = random_weights((num_input, num_cells), name=self.name + "U_z") self.W_z = random_weights((num_cells, num_cells), name=self.name + "W_z") self.U_r = random_weights((num_input, num_cells), name=self.name + "U_r") self.W_r = random_weights((num_cells, num_cells), name=self.name + "W_r") self.U_h = random_weights((num_input, num_cells), name=self.name + "U_h") self.W_h = random_weights((num_cells, num_cells), name=self.name + "W_h") self.b_z = zeros(num_cells, name=self.name + "b_z") self.b_r = zeros(num_cells, name=self.name + "b_r") self.b_h = zeros(num_cells, name=self.name + "b_h") self.params = [ self.U_z, self.W_z, self.U_r, self.W_r, self.U_h, self.W_h, self.b_z, self.b_r, self.b_h ] self.output()
def __init__(self, num_input, num_hidden, input_layers=None, name="", go_backwards=False): self.name = name self.num_input = num_input self.num_hidden = num_hidden if len(input_layers) >= 2: self.X = T.concatenate( [input_layer.output() for input_layer in input_layers], axis=1) else: self.X = input_layers[0].output() self.h0 = theano.shared(floatX(np.zeros(num_hidden))) self.s0 = theano.shared(floatX(np.zeros(num_hidden))) self.go_backwards = go_backwards self.W_gx = random_weights((num_input, num_hidden), name=self.name + "W_gx") self.W_ix = random_weights((num_input, num_hidden), name=self.name + "W_ix") self.W_fx = random_weights((num_input, num_hidden), name=self.name + "W_fx") self.W_ox = random_weights((num_input, num_hidden), name=self.name + "W_ox") self.W_gh = random_weights((num_hidden, num_hidden), name=self.name + "W_gh") self.W_ih = random_weights((num_hidden, num_hidden), name=self.name + "W_ih") self.W_fh = random_weights((num_hidden, num_hidden), name=self.name + "W_fh") self.W_oh = random_weights((num_hidden, num_hidden), name=self.name + "W_oh") self.b_g = zeros(num_hidden, name=self.name + "b_g") self.b_i = zeros(num_hidden, name=self.name + "b_i") self.b_f = zeros(num_hidden, name=self.name + "b_f") self.b_o = zeros(num_hidden, name=self.name + "b_o") self.params = [ self.W_gx, self.W_ix, self.W_ox, self.W_fx, self.W_gh, self.W_ih, self.W_oh, self.W_fh, self.b_g, self.b_i, self.b_f, self.b_o, ] self.output()