accessing LSTM Weights tensors in tensorflow I'm trying the code from :
https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/recurrent_network.ipynb
and also looking at the architecture of the Basic LSTM Cell as described in:
https://r2rt.com/written-memories-understanding-deriving-and-extending-the-lstm.html
so I wish to access to the weights for Wi Wo Wf and Wo (as noted under section "The basic LSTM")
I'm running this 
    for v in tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES):
            print(v)

and I get 
   Tensor("Variable/read:0", shape=(128, 10), dtype=float32)
   Tensor("Variable_1/read:0", shape=(10,), dtype=float32)
   Tensor("rnn/basic_lstm_cell/weights/read:0", shape=(156, 512), dtype=float32)
   Tensor("rnn/basic_lstm_cell/biases/read:0", shape=(512,), dtype=float32)

So I seem to be doing something wrong since I can't get my hands on the Four W matrices...
Any help understanding what I missed please ?
 A: You can recover the LSTM weights from your tensorflow session "sess" as follows:
trainable_vars_dict = {}
for key in tvars:
    trainable_vars_dict[key.name] = sess.run(key)
    # Checking the names of the keys
    print(key) 

From this code you will get the key names. One key name corresponds to a matrix containing all weights of LSTM. The key in your case should have the name "LSTM/rnn/basic_lstm_cell/weights:0". Assuming the size of your input is input_size, you have to do:
lstm_weight_vals = trainable_vars_dict["LSTM/rnn/basic_lstm_cell/weights:0"]
w_i, w_C, w_f, w_o = np.split(lstm_weight_vals, 4, axis=1)

w_xi = w_i[:input_size, :]
w_hi = w_i[input_size:, :]

w_xC = w_C[:input_size, :]
w_hC = w_C[input_size:, :]

w_xf = w_f[:input_size, :]
w_hf = w_f[input_size:, :]

w_xo = w_o[:input_size, :]
w_ho = w_o[input_size:, :]

Where the matrices with "h" in them should be quadratic at the end (of size $128\times128$ in your case). I think for you the input size is $28$. 
A: The four W matrices are in the "rnn/basic_lstm_cell/weights/read:0". You can see the dimension of the weights. The 512 represents the four weithts*cell (4*128), and the 156 represents the 28 input features and 128 cells.Am I right?
