Exemplo n.º 1
0
  def call(self, inputs, training=None, mask=None):
    kwargs = {}
    func_args = inspect.getargspec(self.layer.call).args
    if 'training' in func_args:
      kwargs['training'] = training
    if 'mask' in func_args:
      kwargs['mask'] = mask

    y = self.forward_layer.call(inputs, **kwargs)
    y_rev = self.backward_layer.call(inputs, **kwargs)
    if self.return_sequences:
      y_rev = K.reverse(y_rev, 1)
    if self.merge_mode == 'concat':
      output = K.concatenate([y, y_rev])
    elif self.merge_mode == 'sum':
      output = y + y_rev
    elif self.merge_mode == 'ave':
      output = (y + y_rev) / 2
    elif self.merge_mode == 'mul':
      output = y * y_rev
    elif self.merge_mode is None:
      output = [y, y_rev]

    # Properly set learning phase
    if 0 < self.layer.dropout + self.layer.recurrent_dropout:
      if self.merge_mode is None:
        for out in output:
          out._uses_learning_phase = True
      else:
        output._uses_learning_phase = True
    return output
Exemplo n.º 2
0
  def call(self, inputs, training=None, mask=None):
    kwargs = {}
    func_args = tf_inspect.getargspec(self.layer.call).args
    if 'training' in func_args:
      kwargs['training'] = training
    if 'mask' in func_args:
      kwargs['mask'] = mask

    y = self.forward_layer.call(inputs, **kwargs)
    y_rev = self.backward_layer.call(inputs, **kwargs)
    if self.return_sequences:
      y_rev = K.reverse(y_rev, 1)
    if self.merge_mode == 'concat':
      output = K.concatenate([y, y_rev])
    elif self.merge_mode == 'sum':
      output = y + y_rev
    elif self.merge_mode == 'ave':
      output = (y + y_rev) / 2
    elif self.merge_mode == 'mul':
      output = y * y_rev
    elif self.merge_mode is None:
      output = [y, y_rev]

    # Properly set learning phase
    if 0 < self.layer.dropout + self.layer.recurrent_dropout:
      if self.merge_mode is None:
        for out in output:
          out._uses_learning_phase = True
      else:
        output._uses_learning_phase = True
    return output
 def call(self, inputs, mask=None):
   y = self.forward_layer.call(inputs, mask)
   y_rev = self.backward_layer.call(inputs, mask)
   if self.return_sequences:
     y_rev = K.reverse(y_rev, 1)
   if self.merge_mode == 'concat':
     return K.concatenate([y, y_rev])
   elif self.merge_mode == 'sum':
     return y + y_rev
   elif self.merge_mode == 'ave':
     return (y + y_rev) / 2
   elif self.merge_mode == 'mul':
     return y * y_rev
   elif self.merge_mode is None:
     return [y, y_rev]