def __init__(self, t_layer_sizes, p_layer_sizes, dropout=0): self.t_layer_sizes = t_layer_sizes self.p_layer_sizes = p_layer_sizes # From our architecture definition, size of the notewise input self.t_input_size = 80 # time network maps from notewise input size to various hidden sizes self.time_model = StackedCells( self.t_input_size, celltype=LSTM, layers = t_layer_sizes) self.time_model.layers.append(PassthroughLayer()) # pitch network takes last layer of time model and state of last note, moving upward # and eventually ends with a two-element sigmoid layer p_input_size = t_layer_sizes[-1] + 2 self.pitch_model = StackedCells( p_input_size, celltype=LSTM, layers = p_layer_sizes) self.pitch_model.layers.append(Layer(p_layer_sizes[-1], 2, activation = T.nnet.sigmoid)) self.dropout = dropout self.conservativity = T.fscalar() self.srng = T.shared_randomstreams.RandomStreams(np.random.randint(0, 1024)) self.setup_train() self.setup_predict() self.setup_slow_walk()
def __init__(self, t_layer_sizes, p_layer_sizes, dropout=0): self.t_layer_sizes = t_layer_sizes self.p_layer_sizes = p_layer_sizes # From our architecture definition, size of the notewise input self.t_input_size = 80 # time network maps from notewise input size to various hidden sizes self.time_model = StackedCells( self.t_input_size, celltype=LSTM, layers = t_layer_sizes) self.time_model.layers.append(PassthroughLayer()) #add the output layer of time model # pitch network takes last layer of time model and state of last note, moving upward # and eventually ends with a two-element sigmoid layer #The extra 2 input elements are #1. a value (0 or 1) for whether the previous (half-step lower) # note was chosen to be played (based on previous note-step, starts 0) #2. a value (0 or 1) for whether the previous (half-step lower) note was chosen to be articulated #(based on previous note-step, starts 0) p_input_size = t_layer_sizes[-1] + 2 self.pitch_model = StackedCells( p_input_size, celltype=LSTM, layers = p_layer_sizes) self.pitch_model.layers.append(Layer(p_layer_sizes[-1], 2, activation = T.nnet.sigmoid)) self.dropout = dropout self.conservativity = T.fscalar() #A placeholder for float number self.srng = T.shared_randomstreams.RandomStreams(np.random.randint(0, 1024))#an object that is used to generate random number self.setup_train() self.setup_predict() self.setup_slow_walk()
def __init__(self, data_manager, t_layer_sizes, p_layer_sizes, dropout=0): print('{:25}'.format("Initializing Model"), end='', flush=True) self.t_layer_sizes = t_layer_sizes self.p_layer_sizes = p_layer_sizes self.dropout = dropout self.data_manager = data_manager self.t_input_size = self.data_manager.f.feature_count self.output_size = self.data_manager.s.information_count self.time_model = StackedCells(self.t_input_size, celltype=LSTM, layers=t_layer_sizes) self.time_model.layers.append(PassthroughLayer()) p_input_size = t_layer_sizes[-1] + self.output_size self.pitch_model = StackedCells(p_input_size, celltype=LSTM, layers=p_layer_sizes) self.pitch_model.layers.append( Layer(p_layer_sizes[-1], self.output_size, activation=T.nnet.sigmoid)) self.conservativity = T.fscalar() self.srng = T.shared_randomstreams.RandomStreams( np.random.randint(0, 1024)) self.epsilon = np.spacing(np.float32(1.0)) print("Done")
def __init__(self, time_model_layer_sizes, note_model_layer_sizes): self.time_model = StackedCells(input_size, celltype=LSTM, layers=time_model_layer_sizes) self.time_model.layers.append(Router()) note_model_input_size = time_model_layer_sizes[-1] + outptu_size self.note_model = StackedCells(note_model_input_size, celltype=LSTM, layers=note_model_layer_sizes) self.note_model.layers.append(Layer(note_model_layer_sizes[-1], output_size, activation=T.nnet.sigmoid)) self.time_model_layer_sizes = time_model_layer_sizes self.note_model_layer_sizes = note_model_layer_sizes self._initialize_update_function() self._initialize_predict_function()
def __init__(self, hidden_size, input_size, stack_size=2, celltype=LSTM): self.input_size = input_size # Modelling self.model = StackedCells(input_size, celltype=celltype, activation=T.tanh, layers=[hidden_size] * stack_size) # disable modulation of the input layer self.model.layers[0].in_gate2.activation = lambda x: x # add an output layer self.model.layers.append( Layer(hidden_size, input_size, activation=softmax)) # Setup symbolic tensor variables that will be used in computation # inputs are windows of spectrum data self.input = T.fvector("input") self.prev_input = T.fvector("prev_input") # create symbolic variables for prediction: self.prediction = self.create_prediction() # create gradient training functions: self.create_cost_fun() self.create_training_function() self.create_predict_function()
def __init__(self, hidden_size, input_size, vocab_size, stack_size=1, celltype=LSTM): # declare model self.model = StackedCells(input_size, celltype=celltype, layers=[hidden_size] * stack_size) # add an embedding self.model.layers.insert(0, Embedding(vocab_size, input_size)) # add a classifier: self.model.layers.append( Layer(hidden_size, vocab_size, activation=softmax)) # inputs are matrices of indices, # each row is a sentence, each column a timestep self._stop_word = theano.shared(np.int32(999999999), name="stop word") self.for_how_long = T.ivector() self.input_mat = T.imatrix() self.priming_word = T.iscalar() self.srng = T.shared_randomstreams.RandomStreams( np.random.randint(0, 1024)) # create symbolic variables for prediction: self.predictions = self.create_prediction() # create symbolic variable for greedy search: self.greedy_predictions = self.create_prediction(greedy=True) # create gradient training functions: self.create_cost_fun() self.create_training_function() self.create_predict_function() # For saving state self.epochs = 0
def __init__(self, hidden_size, input_size, output_size, stack_size=1, celltype=RNN, steps=40): # declare model self.model = StackedCells(input_size, celltype=celltype, layers=[hidden_size] * stack_size) # add a classifier: self.model.layers.append( Layer(hidden_size, output_size, activation=T.tanh)) # inputs are matrices of indices, # each row is a sentence, each column a timestep self.steps = steps self.gfs = T.tensor3('gfs') #输入gfs数据 self.pm25in = T.tensor3('pm25in') #pm25初始数据部分 self.layerstatus = None self.results = None self.cnt = T.tensor3('cnt') # create symbolic variables for prediction:(就是做一次整个序列完整的进行预测,得到结果是prediction) self.predictions = self.create_prediction() self.create_predict_function() '''上面几步的意思就是先把公式写好'''
def __init__(self, input_parts, layer_sizes, output_size, window_size=0, dropout=0, mode="drop", unroll_batch_num=None): """ Parameters: input_parts: A list of InputParts layer_sizes: A list of the form [ (indep, per_note), ... ] where indep is the number of non-shifted cells to have, and per_note is the number of cells to have per window note, which shift as the network moves Alternately can just be [ indep, ... ] output_size: An integer, the width of the desired output dropout: How much dropout to apply. mode: Either "drop" or "roll". If drop, discard memory that goes out of range. If roll, roll it instead """ self.input_parts = input_parts self.window_size = window_size layer_sizes = [ x if isinstance(x, tuple) else (x, 0) for x in layer_sizes ] self.layer_sizes = layer_sizes self.tot_layer_sizes = [(indep + per_note * self.window_size) for indep, per_note in layer_sizes] self.output_size = output_size self.dropout = dropout self.input_size = sum(part.PART_WIDTH for part in input_parts) self.cells = StackedCells(self.input_size, celltype=LSTM, activation=T.tanh, layers=self.tot_layer_sizes) self.cells.layers.append( Layer(self.tot_layer_sizes[-1], self.output_size, activation=lambda x: x)) assert mode in ("drop", "roll"), "Must specify either drop or roll mode" self.mode = mode self.unroll_batch_num = unroll_batch_num