Python tensorflow.python.ops.array_ops.split() Examples
The following are 30
code examples of tensorflow.python.ops.array_ops.split().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.array_ops
, or try the search function
.
Example #1
Source File: rnn_cell.py From ecm with Apache License 2.0 | 6 votes |
def __call__(self, inputs, state, emotion, imemory, scope=None): """Gated recurrent unit (GRU) with nunits cells.""" params = [] if emotion is not None: params.append(emotion) if imemory is not None: params.append(imemory) with vs.variable_scope(scope or 'GRUCell'): # "GRUCell" with vs.variable_scope("Emotion_Imemory"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. _r, _u, _c = array_ops.split(1, 3, _linear(params, 3 * self._num_units, False)) with vs.variable_scope("Gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. r, u = array_ops.split(1, 2, _linear([inputs, state], 2 * self._num_units, True, 1.0)) r, u = sigmoid(r+_r), sigmoid(u+_u) with vs.variable_scope("Candidate"): c = self._activation(_c+_linear([inputs, r * state], self._num_units, True)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #2
Source File: backend.py From lambda-packs with MIT License | 6 votes |
def batch_set_value(tuples): """Sets the values of many tensor variables at once. Arguments: tuples: a list of tuples `(tensor, value)`. `value` should be a Numpy array. """ if tuples: assign_ops = [] feed_dict = {} for x, value in tuples: value = np.asarray(value) tf_dtype = _convert_string_dtype(x.dtype.name.split('_')[0]) if hasattr(x, '_assign_placeholder'): assign_placeholder = x._assign_placeholder assign_op = x._assign_op else: assign_placeholder = array_ops.placeholder(tf_dtype, shape=value.shape) assign_op = x.assign(assign_placeholder) x._assign_placeholder = assign_placeholder x._assign_op = assign_op assign_ops.append(assign_op) feed_dict[assign_placeholder] = value get_session().run(assign_ops, feed_dict=feed_dict)
Example #3
Source File: attention_gru_cell.py From BERT with Apache License 2.0 | 6 votes |
def __call__(self, inputs, state, scope=None): """Attention GRU with nunits cells.""" with vs.variable_scope(scope or "attention_gru_cell"): with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. if inputs.get_shape()[-1] != self._num_units + 1: raise ValueError("Input should be passed as word input concatenated with 1D attention on end axis") # extract input vector and attention inputs, g = array_ops.split(inputs, num_or_size_splits=[self._num_units,1], axis=1) r = _linear([inputs, state], self._num_units, True) r = sigmoid(r) with vs.variable_scope("candidate"): r = r*_linear(state, self._num_units, False) with vs.variable_scope("input"): x = _linear(inputs, self._num_units, True) h_hat = self._activation(r + x) new_h = (1 - g) * state + g * h_hat return new_h, new_h
Example #4
Source File: tensor_forest.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _weighted_gini(self, class_counts): """Our split score is the Gini impurity times the number of examples. If c(i) denotes the i-th class count and c = sum_i c(i) then score = c * (1 - sum_i ( c(i) / c )^2 ) = c - sum_i c(i)^2 / c Args: class_counts: A 2-D tensor of per-class counts, usually a slice or gather from variables.node_sums. Returns: A 1-D tensor of the Gini impurities for each row in the input. """ smoothed = 1.0 + array_ops.slice(class_counts, [0, 1], [-1, -1]) sums = math_ops.reduce_sum(smoothed, 1) sum_squares = math_ops.reduce_sum(math_ops.square(smoothed), 1) return sums - sum_squares / sums
Example #5
Source File: backend.py From lambda-packs with MIT License | 6 votes |
def set_value(x, value): """Sets the value of a variable, from a Numpy array. Arguments: x: Tensor to set to a new value. value: Value to set the tensor to, as a Numpy array (of the same shape). """ value = np.asarray(value) tf_dtype = _convert_string_dtype(x.dtype.name.split('_')[0]) if hasattr(x, '_assign_placeholder'): assign_placeholder = x._assign_placeholder assign_op = x._assign_op else: assign_placeholder = array_ops.placeholder(tf_dtype, shape=value.shape) assign_op = x.assign(assign_placeholder) x._assign_placeholder = assign_placeholder x._assign_op = assign_op get_session().run(assign_op, feed_dict={assign_placeholder: value})
Example #6
Source File: GRU.py From Question_Answering_Models with MIT License | 6 votes |
def __call__(self, inputs, state, scope=None): """Run one step of SRU.""" with tf.variable_scope(scope or type(self).__name__): # "SRUCell" with tf.variable_scope("x_hat"): x = linear([inputs], self._num_units, False) with tf.variable_scope("gates"): concat = tf.sigmoid(linear([inputs], 2 * self._num_units, True)) f, r = tf.split(concat, 2, axis = 1) with tf.variable_scope("candidates"): c = self._activation(f * state + (1 - f) * x) # variational dropout as suggested in the paper (disabled) # if self._is_training and Params.dropout is not None: # c = tf.nn.dropout(c, keep_prob = 1 - Params.dropout) # highway connection # Our implementation is slightly different to the paper # https://arxiv.org/abs/1709.02755 in a way that highway network # uses x_hat instead of the cell inputs. Check equation (7) from the original # paper for SRU. h = r * c + (1 - r) * x return h, c
Example #7
Source File: tensor_forest.py From lambda-packs with MIT License | 6 votes |
def _weighted_gini(self, class_counts): """Our split score is the Gini impurity times the number of examples. If c(i) denotes the i-th class count and c = sum_i c(i) then score = c * (1 - sum_i ( c(i) / c )^2 ) = c - sum_i c(i)^2 / c Args: class_counts: A 2-D tensor of per-class counts, usually a slice or gather from variables.node_sums. Returns: A 1-D tensor of the Gini impurities for each row in the input. """ smoothed = 1.0 + array_ops.slice(class_counts, [0, 1], [-1, -1]) sums = math_ops.reduce_sum(smoothed, 1) sum_squares = math_ops.reduce_sum(math_ops.square(smoothed), 1) return sums - sum_squares / sums
Example #8
Source File: rnn_cell.py From nlstm with MIT License | 6 votes |
def call(self, inputs, state): """forward propagation of the cell Args: inputs: a 2D `Tensor` of [batch_size x input_size] shape state: a `tuple` of 2D `Tensor` of [batch_size x num_units] shape or a `Tensor` of [batch_size x (num_units * (self.depth + 1))] shape Returns: outputs: a 2D `Tensor` of [batch_size x num_units] shape next_state: a `tuple` of 2D `Tensor` of [batch_size x num_units] shape or a `Tensor` of [batch_size x (num_units * (self.depth + 1))] shape """ if not self._state_is_tuple: states = array_ops.split(state, self.depth + 1, axis=1) else: states = state hidden_state = states[0] cell_states = states[1:] outputs, next_state = self._recurrence(inputs, hidden_state, cell_states, 0) if self._state_is_tuple: next_state = tuple(next_state) else: next_state = array_ops.concat(next_state, axis=1) return outputs, next_state
Example #9
Source File: rnn_cell.py From Multiview2Novelview with MIT License | 6 votes |
def call(self, inputs, state, scope=None): cell, hidden = state new_hidden = _conv([inputs, hidden], self._kernel_shape, 4*self._output_channels, self._use_bias) gates = array_ops.split(value=new_hidden, num_or_size_splits=4, axis=self._conv_ndims+1) input_gate, new_input, forget_gate, output_gate = gates new_cell = math_ops.sigmoid(forget_gate + self._forget_bias) * cell new_cell += math_ops.sigmoid(input_gate) * math_ops.tanh(new_input) output = math_ops.tanh(new_cell) * self._activation(output_gate) if self._skip_connection: output = array_ops.concat([output, inputs], axis=-1) new_state = rnn_cell_impl.LSTMStateTuple(new_cell, output) return output, new_state
Example #10
Source File: rnn_cell.py From ROLO with Apache License 2.0 | 6 votes |
def __call__(self, inputs, state, scope=None): """Long short-term memory cell (LSTM).""" with vs.variable_scope(scope or type(self).__name__): # "BasicLSTMCell" # Parameters of gates are concatenated into one multiply for efficiency. if self._state_is_tuple: c, h = state else: c, h = array_ops.split(1, 2, state) concat = _linear([inputs, h], 4 * self._num_units, True) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = array_ops.split(1, 4, concat) new_c = (c * sigmoid(f + self._forget_bias) + sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = array_ops.concat(1, [new_c, new_h]) return new_h, new_state
Example #11
Source File: rev_block_lib_test.py From tf-slim with Apache License 2.0 | 6 votes |
def testForwardBackward(self): def f(x): return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) def g(x): return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) x = random_ops.random_uniform( [self.BATCH_SIZE, self.CHANNELS], dtype=dtypes.float32) x1, x2 = array_ops.split(x, 2, axis=-1) block = rev_block_lib.RevBlock(f, g, num_layers=3) y1, y2 = block.forward(x1, x2) x1_inv, x2_inv = block.backward(y1, y2) with self.cached_session() as sess: sess.run(variables.global_variables_initializer()) x1, x2, x1_inv, x2_inv = sess.run([x1, x2, x1_inv, x2_inv]) self.assertAllClose(x1, x1_inv, atol=1e-5) self.assertAllClose(x2, x2_inv, atol=1e-5)
Example #12
Source File: rev_block_lib_test.py From tf-slim with Apache License 2.0 | 6 votes |
def testBackwardForward(self): def f(x): return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) def g(x): return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) y = random_ops.random_uniform( [self.BATCH_SIZE, self.CHANNELS], dtype=dtypes.float32) y1, y2 = array_ops.split(y, 2, axis=-1) block = rev_block_lib.RevBlock(f, g, num_layers=3) x1, x2 = block.backward(y1, y2) y1_inv, y2_inv = block.forward(x1, x2) with self.cached_session() as sess: sess.run(variables.global_variables_initializer()) y1, y2, y1_inv, y2_inv = sess.run([y1, y2, y1_inv, y2_inv]) self.assertAllClose(y1, y1_inv, rtol=1e-5) self.assertAllClose(y2, y2_inv, rtol=1e-5)
Example #13
Source File: rnn_cell.py From deep_image_model with Apache License 2.0 | 6 votes |
def __call__(self, inputs, state, scope=None): """Long short-term memory cell (LSTM).""" with vs.variable_scope(scope or type(self).__name__): # "BasicLSTMCell" # Parameters of gates are concatenated into one multiply for efficiency. if self._state_is_tuple: c, h = state else: c, h = array_ops.split(1, 2, state) concat = _linear([inputs, h], 4 * self._num_units, True) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = array_ops.split(1, 4, concat) new_c = (c * sigmoid(f + self._forget_bias) + sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = array_ops.concat(1, [new_c, new_h]) return new_h, new_state
Example #14
Source File: tensor_forest.py From deep_image_model with Apache License 2.0 | 6 votes |
def _weighted_gini(self, class_counts): """Our split score is the Gini impurity times the number of examples. If c(i) denotes the i-th class count and c = sum_i c(i) then score = c * (1 - sum_i ( c(i) / c )^2 ) = c - sum_i c(i)^2 / c Args: class_counts: A 2-D tensor of per-class counts, usually a slice or gather from variables.node_sums. Returns: A 1-D tensor of the Gini impurities for each row in the input. """ smoothed = 1.0 + array_ops.slice(class_counts, [0, 1], [-1, -1]) sums = math_ops.reduce_sum(smoothed, 1) sum_squares = math_ops.reduce_sum(math_ops.square(smoothed), 1) return sums - sum_squares / sums
Example #15
Source File: convLSTM.py From Tensorflow-SegNet with MIT License | 6 votes |
def __call__(self, inputs, state, scope=None): """Convolutional Long short-term memory cell (ConvLSTM).""" with vs.variable_scope(scope or type(self).__name__): # "ConvLSTMCell" if self._state_is_tuple: c, h = state else: c, h = array_ops.split(3, 2, state) # batch_size * height * width * channel concat = _conv([inputs, h], 4 * self._num_units, self._k_size, True, initializer=self._initializer) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = array_ops.split(3, 4, concat) new_c = (c * sigmoid(f + self._forget_bias) + sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = array_ops.concat(3, [new_c, new_h]) return new_h, new_state
Example #16
Source File: rnn_cell_impl.py From lambda-packs with MIT License | 6 votes |
def call(self, inputs, state): """Long short-term memory cell (LSTM).""" sigmoid = math_ops.sigmoid # Parameters of gates are concatenated into one multiply for efficiency. if self._state_is_tuple: c, h = state else: c, h = array_ops.split(value=state, num_or_size_splits=2, axis=1) concat = _linear([inputs, h], 4 * self._num_units, True) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = array_ops.split(value=concat, num_or_size_splits=4, axis=1) new_c = ( c * sigmoid(f + self._forget_bias) + sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = array_ops.concat([new_c, new_h], 1) return new_h, new_state
Example #17
Source File: rnn_cell.py From ecm with Apache License 2.0 | 6 votes |
def __call__(self, inputs, state, scope=None): """Long short-term memory cell (LSTM).""" with vs.variable_scope(scope or type(self).__name__): # "BasicLSTMCell" # Parameters of gates are concatenated into one multiply for efficiency. if self._state_is_tuple: c, h = state else: c, h = array_ops.split(1, 2, state) concat = _linear([inputs, h], 4 * self._num_units, True) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = array_ops.split(1, 4, concat) new_c = (c * sigmoid(f + self._forget_bias) + sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = array_ops.concat(1, [new_c, new_h]) return new_h, new_state
Example #18
Source File: mod_core_rnn_cell_impl.py From RGAN with MIT License | 6 votes |
def __call__(self, inputs, state, scope=None): """Gated recurrent unit (GRU) with nunits cells.""" with _checked_scope(self, scope or "gru_cell", reuse=self._reuse): with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. value = sigmoid(_linear( [inputs, state], 2 * self._num_units, True, 1.0)) r, u = array_ops.split( value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation(_linear([inputs, r * state], self._num_units, True)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #19
Source File: mod_core_rnn_cell_impl.py From RGAN with MIT License | 6 votes |
def __call__(self, inputs, state, scope=None): """Long short-term memory cell (LSTM).""" with _checked_scope(self, scope or "basic_lstm_cell", reuse=self._reuse): # Parameters of gates are concatenated into one multiply for efficiency. if self._state_is_tuple: c, h = state else: c, h = array_ops.split(value=state, num_or_size_splits=2, axis=1) concat = _linear([inputs, h], 4 * self._num_units, True) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = array_ops.split(value=concat, num_or_size_splits=4, axis=1) new_c = (c * sigmoid(f + self._forget_bias) + sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = array_ops.concat([new_c, new_h], 1) return new_h, new_state
Example #20
Source File: inception_score.py From Robust-Conditional-GAN with MIT License | 6 votes |
def inception_logits(images=inception_images, num_splits=1): # images = tf.transpose(images, [0, 2, 3, 1]) size = 299 images = tf.image.resize_bilinear(images, [size, size]) generated_images_list = array_ops.split( images, num_or_size_splits=num_splits) logits_ = functional_ops.map_fn( fn=functools.partial(tfgan.eval.run_inception, output_tensor='logits:0'), elems=array_ops.stack(generated_images_list), parallel_iterations=1, back_prop=False, swap_memory=True, name='RunClassifier') logits_ = array_ops.concat(array_ops.unstack(logits_), 0) return logits_
Example #21
Source File: convrnn.py From audio-super-res with MIT License | 6 votes |
def __call__(self, inputs, state, scope=None): """Long short-term memory cell (LSTM).""" with tf.variable_scope(scope or type(self).__name__): # "BasicLSTMCell" # Parameters of gates are concatenated into one multiply for efficiency. if self._state_is_tuple: c, h = state else: c, h = tf.split(axis=3, num_or_size_splits=2, value=state) concat = _conv_linear([inputs, h], self.filter_size, self.num_features * 4, True) # i = input_gate, j = new_input, f = forget_gate, o = output_gate i, j, f, o = tf.split(axis=3, num_or_size_splits=4, value=concat) new_c = (c * tf.nn.sigmoid(f + self._forget_bias) + tf.nn.sigmoid(i) * self._activation(j)) new_h = self._activation(new_c) * tf.nn.sigmoid(o) if self._state_is_tuple: new_state = LSTMStateTuple(new_c, new_h) else: new_state = tf.concat(axis=3, values=[new_c, new_h]) return new_h, new_state
Example #22
Source File: convrnn.py From audio-super-res with MIT License | 6 votes |
def call(self, inputs, state, scope=None): cell, hidden = state new_hidden = _conv([inputs, hidden], self._kernel_shape, 4*self._output_channels, self._use_bias) gates = array_ops.split(value=new_hidden, num_or_size_splits=4, axis=self._conv_ndims+1) input_gate, new_input, forget_gate, output_gate = gates new_cell = math_ops.sigmoid(forget_gate + self._forget_bias) * cell new_cell += math_ops.sigmoid(input_gate) * math_ops.tanh(new_input) output = math_ops.tanh(new_cell) * math_ops.sigmoid(output_gate) if self._skip_connection: output = array_ops.concat([output, inputs], axis=-1) new_state = rnn_cell_impl.LSTMStateTuple(new_cell, output) return output, new_state
Example #23
Source File: inception_score_tpu_tf1.py From Inception-Score with Apache License 2.0 | 6 votes |
def inception_logits(num_splits = 1): images = inception_images[0] images = tf.transpose(images, [0, 2, 3, 1]) size = 299 images = tf.compat.v1.image.resize_bilinear(images, [size, size]) generated_images_list = array_ops.split(images, num_or_size_splits = num_splits) logits = tf.map_fn( fn = functools.partial( tfgan.eval.run_inception, default_graph_def_fn = functools.partial( tfgan.eval.get_graph_def_from_url_tarball, INCEPTION_URL, INCEPTION_FROZEN_GRAPH, os.path.basename(INCEPTION_URL)), output_tensor = 'logits:0'), elems = array_ops.stack(generated_images_list), parallel_iterations = 8, back_prop = False, swap_memory = True, name = 'RunClassifier') logits = array_ops.concat(array_ops.unstack(logits), 0) return logits
Example #24
Source File: inception_score_tf1.py From Inception-Score with Apache License 2.0 | 6 votes |
def inception_logits(images = inception_images, num_splits = 1): images = tf.transpose(images, [0, 2, 3, 1]) size = 299 images = tf.compat.v1.image.resize_bilinear(images, [size, size]) generated_images_list = array_ops.split(images, num_or_size_splits = num_splits) logits = tf.map_fn( fn = functools.partial( tfgan.eval.run_inception, default_graph_def_fn = functools.partial( tfgan.eval.get_graph_def_from_url_tarball, INCEPTION_URL, INCEPTION_FROZEN_GRAPH, os.path.basename(INCEPTION_URL)), output_tensor = 'logits:0'), elems = array_ops.stack(generated_images_list), parallel_iterations = 8, back_prop = False, swap_memory = True, name = 'RunClassifier') logits = array_ops.concat(array_ops.unstack(logits), 0) return logits
Example #25
Source File: seq2seq_model.py From DeepAffinity with GNU General Public License v3.0 | 6 votes |
def call(self, inputs, state): """Gated recurrent unit (GRU) with nunits cells.""" with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. bias_ones = self._bias_initializer if self._bias_initializer is None: dtype = [a.dtype for a in [inputs, state]][0] bias_ones = init_ops.constant_initializer(1.0, dtype=dtype) value = math_ops.sigmoid( _linear([inputs, state], 2 * self._num_units, True, bias_ones, self._kernel_initializer)) r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation( _linear([inputs, r * state], self._num_units, True, self._bias_initializer, self._kernel_initializer)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #26
Source File: seq2seq_model.py From DeepAffinity with GNU General Public License v3.0 | 6 votes |
def call(self, inputs, state): """Gated recurrent unit (GRU) with nunits cells.""" with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. bias_ones = self._bias_initializer if self._bias_initializer is None: dtype = [a.dtype for a in [inputs, state]][0] bias_ones = init_ops.constant_initializer(1.0, dtype=dtype) value = math_ops.sigmoid( _linear([inputs, state], 2 * self._num_units, True, bias_ones, self._kernel_initializer)) r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation( _linear([inputs, r * state], self._num_units, True, self._bias_initializer, self._kernel_initializer)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #27
Source File: seq2seq_model.py From DeepAffinity with GNU General Public License v3.0 | 6 votes |
def call(self, inputs, state): """Gated recurrent unit (GRU) with nunits cells.""" with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. bias_ones = self._bias_initializer if self._bias_initializer is None: dtype = [a.dtype for a in [inputs, state]][0] bias_ones = init_ops.constant_initializer(1.0, dtype=dtype) value = math_ops.sigmoid( _linear([inputs, state], 2 * self._num_units, True, bias_ones, self._kernel_initializer)) r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation( _linear([inputs, r * state], self._num_units, True, self._bias_initializer, self._kernel_initializer)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #28
Source File: seq2seq_model.py From DeepAffinity with GNU General Public License v3.0 | 6 votes |
def call(self, inputs, state): """Gated recurrent unit (GRU) with nunits cells.""" with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. bias_ones = self._bias_initializer if self._bias_initializer is None: dtype = [a.dtype for a in [inputs, state]][0] bias_ones = init_ops.constant_initializer(1.0, dtype=dtype) value = math_ops.sigmoid( _linear([inputs, state], 2 * self._num_units, True, bias_ones, self._kernel_initializer)) r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation( _linear([inputs, r * state], self._num_units, True, self._bias_initializer, self._kernel_initializer)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #29
Source File: seq2seq_model.py From DeepAffinity with GNU General Public License v3.0 | 6 votes |
def call(self, inputs, state): """Gated recurrent unit (GRU) with nunits cells.""" with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. bias_ones = self._bias_initializer if self._bias_initializer is None: dtype = [a.dtype for a in [inputs, state]][0] bias_ones = init_ops.constant_initializer(1.0, dtype=dtype) value = math_ops.sigmoid( _linear([inputs, state], 2 * self._num_units, True, bias_ones, self._kernel_initializer)) r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation( _linear([inputs, r * state], self._num_units, True, self._bias_initializer, self._kernel_initializer)) new_h = u * state + (1 - u) * c return new_h, new_h
Example #30
Source File: seq2seq_model.py From DeepAffinity with GNU General Public License v3.0 | 6 votes |
def call(self, inputs, state): """Gated recurrent unit (GRU) with nunits cells.""" with vs.variable_scope("gates"): # Reset gate and update gate. # We start with bias of 1.0 to not reset and not update. bias_ones = self._bias_initializer if self._bias_initializer is None: dtype = [a.dtype for a in [inputs, state]][0] bias_ones = init_ops.constant_initializer(1.0, dtype=dtype) value = math_ops.sigmoid( _linear([inputs, state], 2 * self._num_units, True, bias_ones, self._kernel_initializer)) r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) with vs.variable_scope("candidate"): c = self._activation( _linear([inputs, r * state], self._num_units, True, self._bias_initializer, self._kernel_initializer)) new_h = u * state + (1 - u) * c return new_h, new_h