΢ Ͷ ^ ھ

cba新赛季201 :\ՄTensorflow ӑBpRNNݔ}

cba㶫 www.axwwg.com  •rg2020-01-26 11:00:51   ߣ   ҪuՓ(0)

tf.nn.bidirectional_dynamic_rnn()



def bidirectional_dynamic_rnn(
cell_fw, # ǰRNN
cell_bw, # RNN
inputs, # ݔ
sequence_length=No

tf.nn.bidirectional_dynamic_rnn()

def bidirectional_dynamic_rnn(
  cell_fw, # ǰRNN
  cell_bw, # RNN
  inputs, # ݔ
  sequence_length=None,# ݔеČHLȣxĬJݔеLȣ
  initial_state_fw=None, # ǰijʼB??  initial_state_bw=None, # ijʼB??  dtype=None, # ʼݔĔͣ??  parallel_iterations=None,
  swap_memory=False,
  time_major=False,
  # Qݔݔtensorĸʽtrue, Π횞 `[max_time, batch_size, depth]`.
  # false, tensorΠ횞`[batch_size, max_time, depth]`.
  scope=None
)



outputs(output_fw, output_bw)һǰcellݔtensorͺcellݔtensorMɵԪMO

time_major=false,tensorshape[batch_size, max_time, depth]ʹtf.concat(outputs, 2)ƴ

output_states(output_state_fw, output_state_bw)ǰͺ[ؠBĽMɵԪM

output_state_fwoutput_state_bw͞LSTMStateTuple

LSTMStateTupleɣchMքememory cellhidden state

ֵ

ԪM(outputs, output_states)

@߀һС}output_statesһԪMԪM̎c_fw,h_fw = output_state_fwc_bw,h_bw = output_state_bwٷքechBconcattf.contrib.rnn.LSTMStateTuple()decoder˵ijʼB

def encoding_layer(rnn_size,sequence_length,num_layers,rnn_inputs,keep_prob):
  # rnn_size: rnn[ӹc
  # sequence_length: L
  # num_layers:ѯBrnn cell
  # rnn_inputs: ݔtensor
  # keep_prob:
  '''Create the encoding layer'''
  for layer in range(num_layers):
    with tf.variable_scope('encode_{}'.format(layer)):
      cell_fw = tf.contrib.rnn.LSTMCell(rnn_size,initializer=tf.random_uniform_initializer(-0.1,0.1,seed=2))
      cell_fw = tf.contrib.rnn.DropoutWrapper(cell_fw,input_keep_prob=keep_prob)
 
      cell_bw = tf.contrib.rnn.LSTMCell(rnn_size,initializer=tf.random_uniform_initializer(-0.1,0.1,seed=2))
      cell_bw = tf.contrib.rnn.DropoutWrapper(cell_bw,input_keep_prob = keep_prob)
 
      enc_output,enc_state = tf.nn.bidirectional_dynamic_rnn(cell_fw,cell_bw,
                                  rnn_inputs,sequence_length,dtype=tf.float32)
 
  # join outputs since we are using a bidirectional RNN
  enc_output = tf.concat(enc_output,2) 
  return enc_output,enc_state

tf.nn.dynamic_rnn()

tf.nn.dynamic_rnnķֵЃɂoutputsstate

ݔΠȽBׂ׃batch_sizeݔ@Ĕmax_time@еLLݔmax_timeľLӵĆ~cell.output_size䌍rnn cellԪĂ

Ӂf÷ORNNݔinput[2,20,128]2batch_size20ıL128embedding_sizeԿЃɂexample҂OڶıLֻ13ʣµ7ʹ0-paddingdynamicصǃɂoutputs,stateoutputs[2,20,128]Ҳÿһ[Bݔstate(c,h)Mɵtuple[batch,128]

outputs. outputsһtensor

time_major==TrueoutputsΠ [max_time, batch_size, cell.output_size ]ҪrnnݔcrnnݔΠһ£

time_major==FalseĬJoutputsΠ [ batch_size, max_time, cell.output_size ]

state. stateһtensorstateKĠBҲһcellݔĠBһrstateΠ [batch_size, cell.output_size ]ݔcellBasicLSTMCellrstateΠ[2batch_size, cell.output_size ]2ҲLSTMеcell statehidden state

@PLSTMĽY}

@ƪ\ՄTensorflow ӑBpRNNݔ}СoҵȫϣܽoһҲϣҶ֧_֮

ܸdȤ:

  • ӖõtensorflowģдӡӖ׃
  • tensorflowFӡckptģͱµ׃Q׃ֵ
  • Python Tensor FLowʹ÷Ԕ
  • TensorFlowFӡÿһӵݔ

P

  • pythonCWxgboostʹ

    pythonCWxgboostʹ

    1.xȡ ԭxgboostxȡlibsvm import xgboost as xgb data = xgb.DMatrix(libsvmļ) ʹsklearnxȡlibsvm from sklearn.
    2020-01-26
  • \ՄTensorflow ӑBpRNNݔ}

    \ՄTensorflow ӑBpRNNݔ}

    tf.nn.bidirectional_dynamic_rnn() def bidirectional_dynamic_rnn( cell_fw, # ǰRNN cell_bw, # RNN inputs, # ݔ sequence_length=No
    2020-01-26
  • pythonȡվӕϢČFa

    pythonȡվӕϢČFa

    TxֻץȡQϢdַ惦 칤DBUtil.py import pymysql class DBUtils(object): def connDB(self):
    2020-01-26
  • TFRecordʽ惦cxȡ

    TFRecordʽ惦cxȡ

    Tensor FlowٷWվṩNxȡķ 1. AdTensor FlowDжx׃Д,ֱǶDӖ^r
    2020-01-26
  • ʹ tf.nn.dynamic_rnn չ_rgSȷʽ

    ʹ tf.nn.dynamic_rnn չ_rgSȷʽ

    چ΂ RNNCell  ʹɫ call M\r ֻЕrgǰMһ  ʹ x1 ho õh1 ͨ^ x2  h1 õ h2  tf.nn.dynamic_r
    2020-01-26
  • tensorflow ckptģͺpbģͫ@ȡcQ,ckptDpbģ͌

    tensorflow ckptģͺpbģͫ@ȡcQ,ckptDpbģ͌

    ckpt from tensorflow.python import pywrap_tensorflow checkpoint_path = 'model.ckpt-8000' reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_pa
    2020-01-26
  • tensorflowģ^mӖ fineturn

    tensorflowģ^mӖ fineturn

    QtensoflowӖģ^mӖfineturnĆ} Ӗa ΄ x = 3.0, y = 100.0 \㹫ʽ xW+b = y Wb # -*- coding: u
    2020-01-26
  • PythonFFLVҕlƴӹ

    PythonFFLVҕlƴӹ

    ժҪ ĺfFLVļĸʽԴ˞lcʹ Python FFLVҕlƴ һ.FLVļʽ PFLVļʽĽWT@ͺνBһ
    2020-01-26
  • TensorFlow dataset.shufflebatchrepeatʹԔ

    TensorFlow dataset.shufflebatchrepeatʹԔ

    ֱӿaԔע?? import tensorflow as tf import numpy as np d = np.arange(0,60).reshape([6, 10]) # arrayDtensor data = tf.data.
    2020-01-26
  • PythonFSC┵܇̖

    PythonFSC┵܇̖

    ֮ǰnOĕrҪ500w܇̖Ć}ұ㌑һSC܇̖ijϣλɼ{ עPythonF import random def chepai
    2020-01-26