當前位置: 首頁>>代碼示例>>Python>>正文


Python rnn_cell.LSTMCell方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.rnn_cell.LSTMCell方法的典型用法代碼示例。如果您正苦於以下問題:Python rnn_cell.LSTMCell方法的具體用法?Python rnn_cell.LSTMCell怎麽用?Python rnn_cell.LSTMCell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.rnn_cell的用法示例。


在下文中一共展示了rnn_cell.LSTMCell方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def __init__(self,
               num_units,
               forget_bias=1.0,
               use_peephole=False,
               use_compatible_names=False):
    """Initialize the basic LSTM cell.

    Args:
      num_units: int, The number of units in the LSTM cell.
      forget_bias: float, The bias added to forget gates (see above).
      use_peephole: Whether to use peephole connections or not.
      use_compatible_names: If True, use the same variable naming as
        rnn_cell.LSTMCell
    """
    self._num_units = num_units
    self._forget_bias = forget_bias
    self._use_peephole = use_peephole
    if use_compatible_names:
      self._names = {
          "W": "W_0",
          "b": "B",
          "wci": "W_I_diag",
          "wco": "W_O_diag",
          "wcf": "W_F_diag",
          "scope": "LSTMCell"
      }
    else:
      self._names = {
          "W": "W",
          "b": "b",
          "wci": "wci",
          "wco": "wco",
          "wcf": "wcf",
          "scope": "LSTMBlockCell"
      } 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:37,代碼來源:lstm_ops.py

示例2: __init__

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def __init__(self, num_units, use_peepholes=False, forget_bias=1.0):
    super(Grid1LSTMCell, self).__init__(
        num_units=num_units, num_dims=1,
        input_dims=0, output_dims=0, priority_dims=0,
        cell_fn=lambda n, i: rnn_cell.LSTMCell(
            num_units=n, input_size=i, use_peepholes=use_peepholes,
            forget_bias=forget_bias, state_is_tuple=False)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:9,代碼來源:grid_rnn_cell.py

示例3: _build_pre

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def _build_pre(self):
        self.dimA = 20
        self.cellA = MultiRNNCell([LSTMCell(self.dimA)] * 2)
        self.b1 = 0.95
        self.b2 = 0.95
        self.lr = 0.1
        self.eps = 1e-8 
開發者ID:vfleaking,項目名稱:rnnprop,代碼行數:9,代碼來源:rnn.py

示例4: _build_pre

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def _build_pre(self):
        self.dimH = 20
        self.cellH = MultiRNNCell([LSTMCell(self.dimH)] * 2)
        self.lr = 0.1 
開發者ID:vfleaking,項目名稱:rnnprop,代碼行數:6,代碼來源:deepmind.py

示例5: _create_rnn_cell

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def _create_rnn_cell(self):
        cell = GRUCell(self.cfg.num_units) if self.cfg.cell_type == "gru" else LSTMCell(self.cfg.num_units)
        if self.cfg.use_dropout:
            cell = DropoutWrapper(cell, output_keep_prob=self.keep_prob)
        if self.cfg.use_residual:
            cell = ResidualWrapper(cell)
        return cell 
開發者ID:IsaacChanghau,項目名稱:AmusingPythonCodes,代碼行數:9,代碼來源:seq2seq_model.py

示例6: __init__

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def __init__(self, num_units, cell_type='lstm', scope='bi_rnn'):
        self.cell_fw = LSTMCell(num_units) if cell_type == 'lstm' else GRUCell(num_units)
        self.cell_bw = LSTMCell(num_units) if cell_type == 'lstm' else GRUCell(num_units)
        self.scope = scope 
開發者ID:IsaacChanghau,項目名稱:AmusingPythonCodes,代碼行數:6,代碼來源:rnns.py

示例7: _create_single_rnn_cell

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def _create_single_rnn_cell(self, num_units):
        cell = GRUCell(num_units) if self.cfg["cell_type"] == "gru" else LSTMCell(num_units)
        return cell 
開發者ID:IsaacChanghau,項目名稱:neural_sequence_labeling,代碼行數:5,代碼來源:base_model.py

示例8: _create_single_rnn_cell

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def _create_single_rnn_cell(self, num_units):
        cell = GRUCell(num_units) if self.cfg["cell_type"] == "gru" else LSTMCell(num_units)
        if self.cfg["use_dropout"]:
            cell = DropoutWrapper(cell, output_keep_prob=self.rnn_keep_prob)
        if self.cfg["use_residual"]:
            cell = ResidualWrapper(cell)
        return cell 
開發者ID:IsaacChanghau,項目名稱:neural_sequence_labeling,代碼行數:9,代碼來源:multi_attention_model.py

示例9: __init__

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def __init__(self, num_units, cell_type='lstm', scope=None):
        self.cell_fw = GRUCell(num_units) if cell_type == 'gru' else LSTMCell(num_units)
        self.cell_bw = GRUCell(num_units) if cell_type == 'gru' else LSTMCell(num_units)
        self.scope = scope or "bi_rnn" 
開發者ID:IsaacChanghau,項目名稱:neural_sequence_labeling,代碼行數:6,代碼來源:nns.py

示例10: __init__

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def __init__(self, num_units, scope='bi_rnn'):
        self.num_units = num_units
        self.cell_fw = LSTMCell(self.num_units)
        self.cell_bw = LSTMCell(self.num_units)
        self.scope = scope 
開發者ID:IsaacChanghau,項目名稱:Dense_BiLSTM,代碼行數:7,代碼來源:nns.py

示例11: _build_model

# 需要導入模塊: from tensorflow.python.ops import rnn_cell [as 別名]
# 或者: from tensorflow.python.ops.rnn_cell import LSTMCell [as 別名]
def _build_model(self):
        with tf.variable_scope("embeddings"):
            self.source_embs = tf.get_variable(name="source_embs", shape=[self.cfg.source_vocab_size, self.cfg.emb_dim],
                                               dtype=tf.float32, trainable=True)
            self.target_embs = tf.get_variable(name="embeddings", shape=[self.cfg.vocab_size, self.cfg.emb_dim],
                                               dtype=tf.float32, trainable=True)
            source_emb = tf.nn.embedding_lookup(self.source_embs, self.enc_source)
            target_emb = tf.nn.embedding_lookup(self.target_embs, self.dec_target_in)
            print("source embedding shape: {}".format(source_emb.get_shape().as_list()))
            print("target input embedding shape: {}".format(target_emb.get_shape().as_list()))

        with tf.variable_scope("encoder"):
            if self.cfg.use_bi_rnn:
                with tf.variable_scope("bi-directional_rnn"):
                    cell_fw = GRUCell(self.cfg.num_units) if self.cfg.cell_type == "gru" else \
                        LSTMCell(self.cfg.num_units)
                    cell_bw = GRUCell(self.cfg.num_units) if self.cfg.cell_type == "gru" else \
                        LSTMCell(self.cfg.num_units)
                    bi_outputs, _ = bidirectional_dynamic_rnn(cell_fw, cell_bw, source_emb, dtype=tf.float32,
                                                              sequence_length=self.enc_seq_len)
                    source_emb = tf.concat(bi_outputs, axis=-1)
                    print("bi-directional rnn output shape: {}".format(source_emb.get_shape().as_list()))
            input_project = tf.layers.Dense(units=self.cfg.num_units, dtype=tf.float32, name="input_projection")
            source_emb = input_project(source_emb)
            print("encoder input projection shape: {}".format(source_emb.get_shape().as_list()))
            enc_cells = self._create_encoder_cell()
            self.enc_outputs, self.enc_states = dynamic_rnn(enc_cells, source_emb, sequence_length=self.enc_seq_len,
                                                            dtype=tf.float32)
            print("encoder output shape: {}".format(self.enc_outputs.get_shape().as_list()))

        with tf.variable_scope("decoder"):
            self.max_dec_seq_len = tf.reduce_max(self.dec_seq_len, name="max_dec_seq_len")
            self.dec_cells, self.dec_init_states = self._create_decoder_cell()
            # define input and output projection layer
            input_project = tf.layers.Dense(units=self.cfg.num_units, name="input_projection")
            self.dense_layer = tf.layers.Dense(units=self.cfg.vocab_size, name="output_projection")
            if self.mode == "train":  # either "train" or "decode"
                # for training
                target_emb = input_project(target_emb)
                train_helper = TrainingHelper(target_emb, sequence_length=self.dec_seq_len, name="train_helper")
                train_decoder = BasicDecoder(self.dec_cells, helper=train_helper, output_layer=self.dense_layer,
                                             initial_state=self.dec_init_states)
                self.dec_output, _, _ = dynamic_decode(train_decoder, impute_finished=True,
                                                       maximum_iterations=self.max_dec_seq_len)
                print("decoder output shape: {} (vocab size)".format(self.dec_output.rnn_output.get_shape().as_list()))

                # for decode
                start_token = tf.ones(shape=[self.batch_size, ], dtype=tf.int32) * self.cfg.target_dict[GO]
                end_token = self.cfg.target_dict[EOS]

                def inputs_project(inputs):
                    return input_project(tf.nn.embedding_lookup(self.target_embs, inputs))

                dec_helper = GreedyEmbeddingHelper(embedding=inputs_project, start_tokens=start_token,
                                                   end_token=end_token)
                infer_decoder = BasicDecoder(self.dec_cells, helper=dec_helper, initial_state=self.dec_init_states,
                                             output_layer=self.dense_layer)
                infer_dec_output, _, _ = dynamic_decode(infer_decoder, maximum_iterations=self.cfg.maximum_iterations)
                self.dec_predicts = infer_dec_output.sample_id 
開發者ID:IsaacChanghau,項目名稱:AmusingPythonCodes,代碼行數:61,代碼來源:seq2seq_model.py


注:本文中的tensorflow.python.ops.rnn_cell.LSTMCell方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。