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


Python attention_decoder.attention_decoder方法代碼示例

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


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

示例1: _add_decoder

# 需要導入模塊: import attention_decoder [as 別名]
# 或者: from attention_decoder import attention_decoder [as 別名]
def _add_decoder(self, inputs):
        """Add attention decoder to the graph. In train or eval mode, you call this once to get output on ALL steps. In decode (beam search) mode, you call this once for EACH decoder step.

    Args:
      inputs: inputs to the decoder (word embeddings). A list of tensors shape (batch_size, emb_dim)

    Returns:
      outputs: List of tensors; the outputs of the decoder
      out_state: The final state of the decoder
      attn_dists: A list of tensors; the attention distributions
      p_gens: A list of scalar tensors; the generation probabilities
      coverage: A tensor, the current coverage vector
    """
        hps = self._hps
        cell = tf.contrib.rnn.LSTMCell(hps.hidden_dim, state_is_tuple=True, initializer=self.rand_unif_init)

        prev_coverage = self.prev_coverage if hps.mode == "decode" and hps.coverage else None  # In decode mode, we run attention_decoder one step at a time and so need to pass in the previous step's coverage vector each time

        outputs, out_state, attn_dists, p_gens, coverage = attention_decoder(inputs, self._dec_in_state,
                                                                             self._enc_states, self._enc_padding_mask,
                                                                             cell, initial_state_attention=(
                    hps.mode == "decode"), pointer_gen=hps.pointer_gen, use_coverage=hps.coverage,
                                                                             prev_coverage=prev_coverage)

        return outputs, out_state, attn_dists, p_gens, coverage 
開發者ID:IBM,項目名稱:MAX-Text-Summarizer,代碼行數:27,代碼來源:model.py

示例2: _add_decoder

# 需要導入模塊: import attention_decoder [as 別名]
# 或者: from attention_decoder import attention_decoder [as 別名]
def _add_decoder(self, inputs):
    """Add attention decoder to the graph. In train or eval mode, you call this once to get output on ALL steps. In decode (beam search) mode, you call this once for EACH decoder step.

    Args:
      inputs: inputs to the decoder (word embeddings). A list of tensors shape (batch_size, emb_dim)

    Returns:
      outputs: List of tensors; the outputs of the decoder
      out_state: The final state of the decoder
      attn_dists: A list of tensors; the attention distributions
      p_gens: A list of tensors shape (batch_size, 1); the generation probabilities
      coverage: A tensor, the current coverage vector
    """
    hps = self._hps
    cell = tf.contrib.rnn.LSTMCell(hps.hidden_dim, state_is_tuple=True, initializer=self.rand_unif_init)

    prev_coverage = self.prev_coverage if hps.mode=="decode" and hps.coverage else None # In decode mode, we run attention_decoder one step at a time and so need to pass in the previous step's coverage vector each time

    outputs, out_state, attn_dists, p_gens, coverage = attention_decoder(inputs, self._dec_in_state, self._enc_states, self._enc_padding_mask, cell, initial_state_attention=(hps.mode=="decode"), pointer_gen=hps.pointer_gen, use_coverage=hps.coverage, prev_coverage=prev_coverage)

    return outputs, out_state, attn_dists, p_gens, coverage 
開發者ID:abisee,項目名稱:pointer-generator,代碼行數:23,代碼來源:model.py

示例3: _add_decoder

# 需要導入模塊: import attention_decoder [as 別名]
# 或者: from attention_decoder import attention_decoder [as 別名]
def _add_decoder(self, emb_dec_inputs, embedding):
    """Add attention decoder to the graph. In train or eval mode, you call this once to get output on ALL steps. In decode (beam search) mode, you call this once for EACH decoder step.

    Args:
      emb_dec_inputs: inputs to the decoder (word embeddings). A list of tensors shape (batch_size, emb_dim)
      embedding: embedding matrix (vocab_size, emb_dim)
    Returns:
      outputs: List of tensors; the outputs of the decoder
      out_state: The final state of the decoder
      attn_dists: A list of tensors; the attention distributions
      p_gens: A list of tensors shape (batch_size, 1); the generation probabilities
      coverage: A tensor, the current coverage vector
    """
    hps = self._hps
    cell = tf.contrib.rnn.LSTMCell(hps.dec_hidden_dim, state_is_tuple=True, initializer=self.rand_unif_init)

    prev_coverage = self.prev_coverage if (hps.mode=="decode" and hps.coverage) else None # In decode mode, we run attention_decoder one step at a time and so need to pass in the previous step's coverage vector each time
    prev_decoder_outputs = self.prev_decoder_outputs if (hps.intradecoder and hps.mode=="decode") else tf.stack([],axis=0)
    prev_encoder_es = self.prev_encoder_es if (hps.use_temporal_attention and hps.mode=="decode") else tf.stack([],axis=0)
    return attention_decoder(_hps=hps,
      v_size=self._vocab.size(),
      _max_art_oovs=self._max_art_oovs,
      _enc_batch_extend_vocab=self._enc_batch_extend_vocab,
      emb_dec_inputs=emb_dec_inputs,
      target_batch=self._target_batch,
      _dec_in_state=self._dec_in_state,
      _enc_states=self._enc_states,
      enc_padding_mask=self._enc_padding_mask,
      dec_padding_mask=self._dec_padding_mask,
      cell=cell,
      embedding=embedding,
      sampling_probability=self._sampling_probability if FLAGS.scheduled_sampling else 0,
      alpha=self._alpha if FLAGS.E2EBackProp else 0,
      unk_id=self._vocab.word2id(data.UNKNOWN_TOKEN),
      initial_state_attention=(hps.mode=="decode"),
      pointer_gen=hps.pointer_gen,
      use_coverage=hps.coverage,
      prev_coverage=prev_coverage,
      prev_decoder_outputs=prev_decoder_outputs,
      prev_encoder_es = prev_encoder_es) 
開發者ID:yaserkl,項目名稱:TransferRL,代碼行數:42,代碼來源:model.py

示例4: _add_decoder

# 需要導入模塊: import attention_decoder [as 別名]
# 或者: from attention_decoder import attention_decoder [as 別名]
def _add_decoder(self, emb_dec_inputs, embedding):
    """Add attention decoder to the graph. In train or eval mode, you call this once to get output on ALL steps. In decode (beam search) mode, you call this once for EACH decoder step.

    Args:
      emb_dec_inputs: inputs to the decoder (word embeddings). A list of tensors shape (batch_size, emb_dim)
      embedding: embedding matrix (vocab_size, emb_dim)
    Returns:
      outputs: List of tensors; the outputs of the decoder
      out_state: The final state of the decoder
      attn_dists: A list of tensors; the attention distributions
      p_gens: A list of tensors shape (batch_size, 1); the generation probabilities
      coverage: A tensor, the current coverage vector
    """
    hps = self._hps
    cell = tf.contrib.rnn.LSTMCell(hps.dec_hidden_dim, state_is_tuple=True, initializer=self.rand_unif_init)

    prev_coverage = self.prev_coverage if (hps.mode=="decode" and hps.coverage) else None # In decode mode, we run attention_decoder one step at a time and so need to pass in the previous step's coverage vector each time
    prev_decoder_outputs = self.prev_decoder_outputs if (hps.intradecoder and hps.mode=="decode") else tf.stack([],axis=0)
    prev_encoder_es = self.prev_encoder_es if (hps.use_temporal_attention and hps.mode=="decode") else tf.stack([],axis=0)
    return attention_decoder(hps,
      self._vocab.size(),
      self._max_art_oovs,
      self._enc_batch_extend_vocab,
      emb_dec_inputs,
      self._target_batch,
      self._dec_in_state,
      self._enc_states,
      self._enc_padding_mask,
      self._dec_padding_mask,
      cell,
      embedding,
      self._sampling_probability if FLAGS.scheduled_sampling else 0,
      self._alpha if FLAGS.E2EBackProp else 0,
      self._vocab.word2id(data.UNKNOWN_TOKEN),
      initial_state_attention=(hps.mode=="decode"),
      pointer_gen=hps.pointer_gen,
      use_coverage=hps.coverage,
      prev_coverage=prev_coverage,
      prev_decoder_outputs=prev_decoder_outputs,
      prev_encoder_es = prev_encoder_es) 
開發者ID:yaserkl,項目名稱:RLSeq2Seq,代碼行數:42,代碼來源:model.py

示例5: _add_decoder

# 需要導入模塊: import attention_decoder [as 別名]
# 或者: from attention_decoder import attention_decoder [as 別名]
def _add_decoder(self, inputs):
        """Add attention decoder to the graph. In train or eval mode, you call this once to get output on ALL steps. In decode (beam search) mode, you call this once for EACH decoder step.

        Args:
          inputs: inputs to the decoder (word embeddings). A list of tensors shape (batch_size, emb_dim)

        Returns:
          outputs: List of tensors; the outputs of the decoder
          out_state: The final state of the decoder
          attn_dists: A list of tensors; the attention distributions
          p_gens: A list of scalar tensors; the generation probabilities
          coverage: A tensor, the current coverage vector
        """
        hps = self._hps
        if self._isrum in ['all', 'dec']:
            cell = RUMCell(
                self._hps.hidden_dim,
                eta_=self._time_norm,
                lambda_=self._lambda,
                update_gate=self._update_gate,
                use_layer_norm=self._layer_norm,
                use_zoneout=self._zoneout
            )
        else:
            cell = tf.contrib.rnn.LSTMCell(
                hps.hidden_dim, state_is_tuple=True, initializer=self.rand_unif_init)

        # In decode mode, we run attention_decoder one step at a time and so
        # need to pass in the previous step's coverage vector each time
        prev_coverage = self.prev_coverage if hps.mode == "decode" and hps.coverage else None

        outputs, out_state, attn_dists, p_gens, coverage = attention_decoder(inputs, self._dec_in_state, self._enc_states, self._enc_padding_mask, cell, initial_state_attention=(
            hps.mode == "decode"), pointer_gen=hps.pointer_gen, use_coverage=hps.coverage, prev_coverage=prev_coverage, isrum=self._isrum, lambda_=self._lambda)

        if self._isgrad:
            if self._isrum in ['none', 'enc']:
                tf.summary.scalar('out_state_c', tf.norm(out_state.c))
                tf.summary.scalar('out_state_h', tf.norm(out_state.h))
            else:
                tf.summary.scalar('out_state', tf.norm(out_state))

        return outputs, out_state, attn_dists, p_gens, coverage 
開發者ID:rdangovs,項目名稱:rotational-unit-of-memory,代碼行數:44,代碼來源:model.py


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