๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์์ธ์ง ํ์คํ์ง ์์ต๋๋ค.
ValueError: RNNCell ์ฌ์ฌ์ฉ ์๋
์ฝ๋ ์กฐ๊ฐ์ผ๋ก:
import tensorflow as tf
from tensorflow.contrib import rnn
hidden_size = 100
batch_size = 100
num_steps = 100
num_layers = 100
is_training = True
keep_prob = 0.4
input_data = tf.placeholder(tf.float32, [batch_size, num_steps])
lstm_cell = rnn.BasicLSTMCell(hidden_size, forget_bias=0.0, state_is_tuple=True)
if is_training and keep_prob < 1:
lstm_cell = rnn.DropoutWrapper(lstm_cell)
cell = rnn.MultiRNNCell([lstm_cell for _ in range(num_layers)], state_is_tuple=True)
_initial_state = cell.zero_state(batch_size, tf.float32)
iw = tf.get_variable("input_w", [1, hidden_size])
ib = tf.get_variable("input_b", [hidden_size])
inputs = [tf.nn.xw_plus_b(i_, iw, ib) for i_ in tf.split(input_data, num_steps, 1)]
if is_training and keep_prob < 1:
inputs = [tf.nn.dropout(input_, keep_prob) for input_ in inputs]
outputs, states = rnn.static_rnn(cell, inputs, initial_state=_initial_state)
๋๋ ์ด์ด ์์์ต๋๋ค. ์๋ฌด๋ ๋์๊ฒ ํ์ถ๊ตฌ๋ฅผ ๋ณด์ฌ์ค ์ ์์ต๋๊น?
https://github.com/tensorflow/models/tree/master/tutorials/rnn/translate ์์ ์ฐพ์ ์ ์๋ ๋ฒ์ญ ์์ (์์ ์์ฒด ํ ์คํธ๋ฅผ ์ํํ๋ ๊ฒฝ์ฐ์๋)๋ฅผ ์คํํ๋ ค๊ณ ํ ๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๋๋ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๋ง๋ฌ๋ค. ๋ง์คํฐ ๋ธ๋์น์์ ๋ชจ๋ ์ปดํ์ผ๋ ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ๊ณ์๋ค๋ฉด ์ต๊ทผ commit ์ผ๋ก ์ธํด ๋ฐ์ํ๋ ๋์ผํ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์ปค๋ฐ ๋ฉ์์ง๋ ๋ค์๊ณผ ๊ฐ์ด ๋งํฉ๋๋ค.
tf.contrib.rnn์ ๋ชจ๋ RNNCell์ด tf.layers Layers์ฒ๋ผ ์๋ํ๋๋ก ํ์ญ์์ค.
์ฌ:
__call__์ ์ฒ์ ์ฌ์ฉํ๋ฉด ์ฌ์ฉํ ๋ฒ์๊ฐ ์ ์ ์ ์ฅ๋ฉ๋๋ค. RNNCell์ ํด๋น ๋ฒ์์์ ๊ฐ์ค์น๋ฅผ ์์ฑํ๋ ค๊ณ ์๋ํ์ง๋ง ์ผ๋ถ๊ฐ ์ด๋ฏธ ์ค์ ๋ ๊ฒฝ์ฐ RNNCell์ด ์ธ์ ์ฌ์ฌ์ฉ=True๋ก ๊ตฌ์ฑ๋์ง ์์ ๊ฒฝ์ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๋์ผํ ์ ์ธ์คํด์ค์ __call__์ ํ์ ์ฌ์ฉ์ ๋์ผํ ๋ฒ์์ ์์ด์ผ ํฉ๋๋ค.
๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
ptb tutorial ์ ์คํํ๋ ์ ๊ฒฝ์ฐ์๋ 112๋ฒ์งธ ์ค์ reuse
๋ผ๋ ์ด๋ฆ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
def lstm_cell():
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True, reuse=tf.get_variable_scope().reuse)
๊ทธ๋ฌ๋ฉด ์๋ํฉ๋๋ค.
@ebrevdo ์ด๊ฑฐ ์ข ๋ด์ฃผ์๊ฒ ์ด์ ?
Shakespeare RNN Repo ์์ Windows/GPU ๋น๋ 105๋ฅผ ์ฌ์ฉํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ๋ณต๋ฉ๋๋ค.
Win 1.0.0/GPU ๋ฆด๋ฆฌ์ค๋ก ์ฝ๋๋ฅผ ์คํํ ๋๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๊ทธ ์ ์ฅ์๋ ์ค๊ฐ ๋ฆด๋ฆฌ์ค๊ฐ ์๋ tf 1.0์ ๋์์ผ๋ก ํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ ๋๋ค.
2017๋ 3์ 8์ผ ์คํ 3์ 56๋ถ์ "Tom Wanzek" [email protected] ์ด ์์ฑํ์ต๋๋ค.
์ ฐ์ต์คํผ์ด์์ Windows/GPU ๋น๋ 105๋ฅผ ์ฌ์ฉํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ๋ณต๋ฉ๋๋ค.
RNN ๋ ํฌ https://github.com/martin-gorner/tensorflow-rnn-shakespeare .Win 1.0.0/GPU ๋ฆด๋ฆฌ์ค๋ก ์ฝ๋๋ฅผ ์คํํ ๋๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-285209555 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim5ansaL1KN51T4nCaqLnqw2QHN4Wks5rj0BBgaJpZM4MWl4f
.
@tongda , ์ ๋ CPU ๋ชจ๋์ MacOS์์ ์๋ํ๋ Tensorflow 1.0 ๋ฆด๋ฆฌ์ค ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. "์ฌ์ฌ์ฉ" ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ์ฌ ์๋ํ๋์ง ํ์ธํ๊ธฐ ์ํด ๋ง์คํฐ ๋ถ๊ธฐ๋ก ์ ํํ๊ฒ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
doncat99: ๊ทธ๋ ๊ฒ ํ๋ ๊ฒฝ์ฐ ์ฝ๋๊ฐ tensorflow ๋ฒ์ ์ ์ฟผ๋ฆฌํ๋์ง ํ์ธํ์ญ์์ค.
๋ฒ์ ์ด ๋ง์คํฐ ๋ถ๊ธฐ ๋ฒ์ ๋ณด๋ค ๋ฎ์ผ๋ฉด ํ๋๊ทธ๋ฅผ ๋ฐ์์ํต๋๋ค.
๋ค์์ ๋ํด ํ์ธํด์ผ ํ ์๋ ์์ต๋๋ค.
tensorflow.core ๊ฐ์ ธ์ค๊ธฐ ๋ฒ์ ์์
๋ฒ์ .GIT_VERSION
2017๋ 3์ 8์ผ ์์์ผ ์คํ 6์ 58๋ถ์ doncat99 [email protected] ์์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
@tongda https://github.com/tongda , ๋ฆด๋ฆฌ์ค ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
Tensorflow 1.0, CPU ๋ชจ๋์ MacOS์์ ์๋ํฉ๋๋ค. ๋ง์คํฐ๋ก ๊ฐ์ํ๊ฒ ์ต๋๋ค
๋ถ๊ธฐ์ "์ฌ์ฌ์ฉ" ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ์ฌ ์๋ํ๋์ง ํ์ธํ์ธ์. ๊ฐ์ฌํฉ๋๋ค.โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-285240438 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim66cU9e16lgD-2D0QLGcQCiHbV0zks5rj2rbgaJpZM4MWl4f
.
@ebrevdo ๊ทธ๋ ๋ค๋ฉด ์ ฐ์ตํผ์ด RNN์ด ์ค๊ฐ ์์ ๋ฆด๋ฆฌ์ค์ ํจ๊ป ์๋ํ ์ ์๋๋ก ํ๊ธฐ ์ํด ์ ์๋ ๋ณ๊ฒฝ ์ฌํญ์ ๋ฌด์์ ๋๊น?
๋ค์์ ๋น๋#105์์ ์คํจํ๋ ์ฝ๋์ ์ฃผ์ ์ํคํ ์ฒ ์น์ ์ ๋๋ค.
#
# the model (see FAQ in README.md)
#
lr = tf.placeholder(tf.float32, name='lr') # learning rate
pkeep = tf.placeholder(tf.float32, name='pkeep') # dropout parameter
batchsize = tf.placeholder(tf.int32, name='batchsize')
# inputs
X = tf.placeholder(tf.uint8, [None, None], name='X') # [ BATCHSIZE, SEQLEN ]
Xo = tf.one_hot(X, ALPHASIZE, 1.0, 0.0) # [ BATCHSIZE, SEQLEN, ALPHASIZE ]
# expected outputs = same sequence shifted by 1 since we are trying to predict the next character
Y_ = tf.placeholder(tf.uint8, [None, None], name='Y_') # [ BATCHSIZE, SEQLEN ]
Yo_ = tf.one_hot(Y_, ALPHASIZE, 1.0, 0.0) # [ BATCHSIZE, SEQLEN, ALPHASIZE ]
# input state
Hin = tf.placeholder(tf.float32, [None, INTERNALSIZE*NLAYERS], name='Hin') # [ BATCHSIZE, INTERNALSIZE * NLAYERS]
# using a NLAYERS=3 layers of GRU cells, unrolled SEQLEN=30 times
# dynamic_rnn infers SEQLEN from the size of the inputs Xo
onecell = rnn.GRUCell(INTERNALSIZE)
dropcell = rnn.DropoutWrapper(onecell, input_keep_prob=pkeep)
multicell = rnn.MultiRNNCell([dropcell for _ in range(NLAYERS)], state_is_tuple=False)
multicell = rnn.DropoutWrapper(multicell, output_keep_prob=pkeep)
Yr, H = tf.nn.dynamic_rnn(multicell, Xo, dtype=tf.float32, initial_state=Hin)
# Yr: [ BATCHSIZE, SEQLEN, INTERNALSIZE ]
# H: [ BATCHSIZE, INTERNALSIZE*NLAYERS ] # this is the last state in the sequence
reuse
ํ๋๊ทธ์ ๊ดํ ๋ฌธ์๋ฅผ ์ฐพ์ง ๋ชปํ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์ฌ์ฉ:
๋ค์ค ์
= rnn.MultiRNNCell([rnn.DropoutWrapper(rnn.GRUCell(INTERNALSIZE),
input_keep_prob=pkeep) for _ in range(NLAYERS)], state_is_tuple=False)
๊ฐ ๋ ์ด์ด์ ๋ํด ๋ณ๋์ ๊ทธ๋ฃจ์ ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค.
2017๋ 3์ 10์ผ ์ค์ 7์ 44๋ถ์ "Tom Wanzek" [email protected] ์ด ์์ฑํ์ต๋๋ค.
@ebrevdo https://github.com/ebrevdo ๊ทธ๋์ ์ ์๋๋ ๊ฒ์ ๋ฌด์์ ๋๊น
์ ฐ์ตํผ์ด RNN์ด ์ค๊ฐ์ฒด์ ์๋ํ ์ ์๋๋ก ๋ณ๊ฒฝ
์์ ์ ์ธ ์ถ์?๋ค์์ ์ฝ๋์ ์ฃผ์ ์ํคํ ์ฒ ์น์ ์ ๋๋ค. ์ด์ ๋ค์๊ณผ ๊ฐ์ด ์คํจํฉ๋๋ค.
๋น๋#105:๋ชจ๋ธ(README.md์ FAQ ์ฐธ์กฐ)
lr = tf.placeholder(tf.float32, name='lr') # ํ์ต๋ฅ
pkeep = tf.placeholder(tf.float32, name='pkeep') # ๋๋กญ์์ ๋งค๊ฐ๋ณ์
๋ฐฐ์น ํฌ๊ธฐ = tf.placeholder(tf.int32, ์ด๋ฆ='๋ฐฐ์น ํฌ๊ธฐ')์ ๋ ฅ
X = tf.placeholder(tf.uint8, [์์, ์์], ์ด๋ฆ='X') # [ BATCHSIZE, SEQLEN ]
Xo = tf.one_hot(X, ALPHASIZE, 1.0, 0.0) # [ BATCHSIZE, SEQLEN, ALPHASIZE ]# ์์ ์ถ๋ ฅ = ๋ค์ ๋ฌธ์๋ฅผ ์์ธกํ๋ ค๊ณ ํ๊ธฐ ๋๋ฌธ์ ๋์ผํ ์ํ์ค๊ฐ โโ1๋งํผ ์ด๋๋จ
Y_ = tf.placeholder(tf.uint8, [์์, ์์], ์ด๋ฆ='Y_') # [ BATCHSIZE, SEQLEN ]
Yo_ = tf.one_hot(Y_, ALPHASIZE, 1.0, 0.0) # [ BATCHSIZE, SEQLEN, ALPHASIZE ]# ์ ๋ ฅ ์ํ
Hin = tf.placeholder(tf.float32, [None, INTERNALSIZE*NLAYERS], name='Hin') # [ BATCHSIZE, INTERNALSIZE * NLAYERS]NLAYERS=3๊ฐ์ GRU ์ ๋ ์ด์ด๋ฅผ ์ฌ์ฉํ์ฌ ์ ๊ฐ๋ SEQLEN=30ํ# dynamic_rnn์ ์ ๋ ฅ Xo์ ํฌ๊ธฐ์์ SEQLEN์ ์ถ๋ก ํฉ๋๋ค.
onecell = rnn.GRUCell(INTERNALSIZE)
dropcell = rnn.DropoutWrapper(onecell, input_keep_prob=pkeep)
multicell = rnn.MultiRNNCell([๋ฒ์ ๋ด _์ ๋ํ ๋๋กญ์ (NLAYERS)], state_is_tuple=False)
multicell = rnn.DropoutWrapper(๋ค์ค ์ , output_keep_prob=pkeep)
Yr, H = tf.nn.dynamic_rnn(multicell, Xo, dtype=tf.float32, initial_state=Hin)# Yr: [ BATCHSIZE, SEQLEN, INTERNALSIZE ]# H: [ BATCHSIZE, INTERNALSIZE*NLAYERS ] # ๋ง์ง๋ง ์ํ์ ๋๋ค. ์์๋๋ก์ฌ์ฌ์ฉ ํ๋๊ทธ์ ๊ดํ ๋ฌธ์๋ฅผ ์ฐพ์ง ๋ชปํ ๊ฒ ๊ฐ์ต๋๊น?
๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-285702372 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim6MOOCbx3RJEJe8PQBDXGVIXTGPmks5rkW_jgaJpZM4MWl4f
.
seq2seq ์์ต์ ๋ชจ๋ธ ์์ ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ์ด์ ๋ฅผ ์ดํดํ ์ ์์ต๋๋ค.
cell = tf.contrib.rnn.MultiRNNCell([single_cell() for _ in range(num_layers)])
์ ์ด ์์ฑ๋๋ ๊ณณ
def single_cell():
return tf.contrib.rnn.GRUCell(size)
@ebrevdo ์ด ๋ฌธ์ ์ ๋ํด ๋ค์ ์๋ ค์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๋ถํํ๋ ์ ์ ๋ ๋ณ๊ฒฝ ์ฌํญ์ ์์ ์ธ๊ธ ํ ์ค๋ฅ์ ํจ๊ป ๋ฌธ์ ๋ฅผ ๊ทธ๋๋ก ๋ก๋๋ค. seq2seq ํํ ๋ฆฌ์ผ ์ ๋ํ ์์ ์ค๋ช ์ ๊ฐ์ํ ๋ ์ฐ๋ฆฌ๋ ๋ชจ๋ ๊ฐ์ ๋ณดํธ์ ์๋ค๊ณ ์๊ฐํฉ๋๊น?
์ ํํ ๊ฐ์ ์ค๋ฅ๋ผ๊ณ ํ์ ํ์ญ๋๊น? ์ฌ๊ธฐ์ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ผ์ญ์์ค.
๋ด ๋์, ๋๋ ๋ฐฉ๊ธ ๊ด๋ จ ์ฝ๋์ ๋ํ ๋ณ๊ฒฝ ํ๋ก์ธ์ค๋ฅผ ๋ค์ (์ฒ์๋ถํฐ) ๊ฑฐ์ณค๊ณ ์ ์๋ ๋๋ก ๋ค์ ์คํํ์ต๋๋ค. ์ค๋ฅ๊ฐ ์ ๋ง ์ ๊ฑฐ๋์๊ณ ์ด์ ์ฌ๋ ๋ฐ๋๊ฐ ํ๊ฐ์ ํ๊ณ ์์ต๋๋ค ๐
๊ทธ๋์, thx, ๋ด๊ฐ ์ด์ ์ด๋์ ์๋ชปํ๋์ง ํ์คํ์ง ์์ง๋ง ๊ทธ๊ฒ์ ๋ถ๋ช ํ ๋์๊ฒ ์์์ต๋๋ค.
Tensorflow 1.0 ๋ฆด๋ฆฌ์ค ๋ฒ์ ์ ์ฌ์ฉํ๊ณ MacOS์์ CPU ๋ชจ๋๋ก ์์ ํ ๋๋ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. "reuse" ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ๋๋ผ๋
def cell():
return tf.contrib.rnn.BasicLSTMCell(rnn_size,state_is_tuple=True,reuse=tf.get_variable_scope().reuse)
muticell = tf.contrib.rnn.MultiRNNCell([cell for _ in range(num_layers)], state_is_tuple=True)
๋ค์ค ์
์ด ์๋ชป๋ ๊ฒ ๊ฐ์ต๋๋ค... "cell() for _ in
๋ฒ์(...)"
2017๋ 3์ 16์ผ ๋ชฉ์์ผ ์คํ 8์ 29๋ถ์ cuiming [email protected] ์์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
Tensorflow 1.0 ๋ฆด๋ฆฌ์ค ๋ฒ์ ์ ์ฌ์ฉํ ๋๋ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
MacOS์์ CPU ๋ชจ๋๋ก ์์ ํฉ๋๋ค. "์ฌ์ฌ์ฉ" ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ๋๋ผ๋def ์ ():
๋ฐํ tf.contrib.rnn.BasicLSTMCell(rnn_size,state_is_tuple=True,reuse=tf.get_variable_scope().reuse)muticell = tf.contrib.rnn.MultiRNNCell([๋ฒ์ ๋ด _์ ๋ํ ์ (num_layers)], state_is_tuple=True)
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-287257629 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim3A6JQr8ptRKrdiDW_kgNRIFkHGlks5rmf4WgaJpZM4MWl4f
.
๋ฒ์ญ ์์ ๋ฅผ ์คํํ๋ ค๊ณ ํ์ต๋๋ค. python2.7 translate.py --data_dir data/ --train_dir train/ --size=256 --num_layers=2 --steps_per_checkpoint=50
MultiRNNCell์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ด ์ฌ๋ฐ๋ฅธ ๊ฒ ๊ฐ์ต๋๋ค.
cell = tf.contrib.rnn.MultiRNNCell([single_cell() for _ in range(num_layers)])
ํ์ง๋ง ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
ValueError: RNNCell ์ฌ์ฌ์ฉ ์๋
@bowu - ์ด์ด ์ข์์ต๋๊น? ์์ง ์๋ํ์ง ์์๋ค๋ฉด ์ต์ ์์ค์์ tensorflow๋ฅผ ๋ค์ ์ค์นํ์ญ์์ค. core_rnn ํ์ผ ์ค ์ผ๋ถ๊ฐ ์ผ๋ถ ๋ณ๊ฒฝ๋์์ต๋๋ค. ์ง๊ธ ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค.
@robmsylvester ์ต์ ์์ค์์ tensorflow๋ฅผ ๋ค์ ์ค์นํ์ง๋ง ์ฌ์ ํ ๋์ผํ ์ค๋ฅ์
๋๋ค. ๋๋ ์ง์ ๋ง์คํฐ์ ์์๊ณ ์ต์ ์ปค๋ฐ์ commit 2a4811054a9e6b83e1f5a2705a92aab50e151b13
์
๋๋ค. ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ๊ตฌ์ถํ ๋ ๊ฐ์ฅ ์ต๊ทผ์ ์ปค๋ฐํ ๋ด์ฉ์ ๋ฌด์์
๋๊น?
์๋ ํ์ธ์, ์ ๋ ์์ค๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ GPU๋ฅผ ์ฌ์ฉํ์ฌ Tensorflow r1.0์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์์ ๋์ง ์์ Seq2Seq ๋ฒ์ญ ์์ต์๋ฅผ ๋ฐ๋ฅด๋ ค๊ณ ํ์ง๋ง ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ฆ
ValueError: RNNCell ์ฌ์ฌ์ฉ ์๋
์ฒซ ๋ฒ์งธ ์ฌ์ฉ๊ณผ ๋ค๋ฅธ ๋ณ์ ๋ฒ์๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์ ์ ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์ ๋ฒ์ 'embedding_attention_seq2seq/embedding_attention_decoder/attention_decoder/multi_rnn_cell/cell_0/gru_cell'์ด์๊ณ , ์ด ์๋๋ ๋ฒ์ 'embedding_attention_seq2seq/rnn/multi_rnn_cell/cell_0/gru_cell'.....
๋ด seq2seq_model.py์ ์๋ ์ฝ๋์ ๊ด๋ จ ๋ถ๋ถ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
# Create the internal multi-layer cell for our RNN.
def single_cell():
return tf.contrib.rnn.GRUCell(size)
if use_lstm:
def single_cell():
return tf.contrib.rnn.BasicLSTMCell(size)
cell = single_cell()
if num_layers > 1:
cell = tf.contrib.rnn.MultiRNNCell([single_cell() for _ in range(num_layers)])
๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํฉ๋๊น?
GRUCell์ด ์์ฑ๋๋ ํธ์ถ์ "reuse=tf.get_variable_scope().reuse"๋ฅผ ์ถ๊ฐํด๋ ๋์์ด ๋์ง ์์ต๋๋ค.
์์ฒญ ๊ณ ๋ง์!
@prashantserai - ์์์ MultiRNNCell ๋ผ์ธ์ ์ ๊ฑฐํ์ฌ ๋คํธ์ํฌ๋ฅผ ํ๋์ ๋ ์ด์ด๋ก ํจ๊ณผ์ ์ผ๋ก ๋ง๋๋ ๊ฒฝ์ฐ ์ด๋ค ์ผ์ด ๋ฐ์ํ๋์ง ํ์ธํ์ญ์์ค. ๊ทธ๋ฌ๋ฉด ์๋ํฉ๋๊น? MultiRNNCell์ ์ด๋๊ฐ์ ๋ฒ๊ทธ๊ฐ ์์ ์ ์์ต๋๋ค. ๋๋ ์ต๊ทผ ์ด๋๊ฐ์์ ์๋ง๋ ์คํ ์ค๋ฒํ๋ก์ ๋ํด ์ฝ์์ต๋๋ค.
์คํํ lstm/gru๋ฅผ ์ง์ ๊ตฌํํ๋ฉด ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์๊ณ ๋์ผํ ๊ธฐ๋ฅ์ ๊ตฌํํ ์ ์์ต๋๋ค(์ค์ ๋ก ๋ ๋ง์ด, ์๋ฐฉํฅ ์ํคํ ์ฒ, ์ด์ํ ์์ฌ ๋ฐ ๊ฑด๋๋ฐ๊ธฐ ์ฐ๊ฒฐ ๋ฑ์ผ๋ก ์ํ๋ ๋ชจ๋ ์์ ์ ์์ ๋กญ๊ฒ ์ํํ ์ ์๊ธฐ ๋๋ฌธ์). .)
@robmsylvester num_layers=1๋ก ์๋ํ๋๋ฐ๋ ๋์ผํ ์ค๋ฅ๊ฐ ์ง์๋์ด ํด๋น ์ค์ ํจ๊ณผ์ ์ผ๋ก ๊ฑด๋๋ธ ์ ์์์ต๋๋ค. ๋ค๋ฅธ ์์ด๋์ด๊ฐ ์์ต๋๊น? ์ ๋ ฅํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
ํ . ๋์๊ฒ ๋์ ๋๋ ํ ๊ฐ์ง๋ ์ฐธ์กฐ๋ ๋ ๊ฑฐ์ seq2seq ํ์ผ์ ์์ต๋๋ค.
encoder_cell = copy.deepcopy(cell)
์ธ์ฝ๋ ์ธก๊ณผ ๋์ฝ๋ ์ธก ๋ชจ๋์์ ๋์ผํ ์ํคํ ์ฒ๊ฐ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ์ด ๋ผ์ธ์ด ์ฌ์ฉ๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. ๊ทธ๋ค์ ์ ์ ๋ณต์ฌ๋ณธ์ ๋ง๋ ๋ค์ ์ ์ธ์๋ฅผ ์ดํ ์ ๋์ฝ๋ ์๋ฒ ๋ฉ ํจ์์ ํจ๊ป ์ ๋ฌํ ๋ค์ ์ดํ ์ ๋์ฝ๋ ์์ฒด๋ก ์ ๋ฌํฉ๋๋ค.
seq2seq ๋ชจ๋ธ ํ์ผ์ ์ธ์ฝ๋ ์ ๊ณผ ๋์ฝ๋ ์ ์ ๋ช ์์ ์ผ๋ก ์์ฑํ๊ณ ๋ ๋ค ๋ ๊ฑฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ์ ์ ๋ฌํ์ฌ ํจ์์ ํด๋น ์ธ์๋ฅผ ์ฝ๊ฐ ์กฐ์ ํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
@robmsylvester ๊ฐ ์๋ํ๋ ์ ๋ฒ์๋ฅผ ๋ณ๊ฒฝํด์๋ ์ ๋ฉ๋๊น? ๋ค๋ฅธ ๋ ๊ฐ์ง ์์์๋ ์๋ํฉ๋๋ค. ์ ์๊ฐ์๋ ์ด๊ฒ์ ๋งค์ฐ ์ถ์ ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ๋ ๊ฒ์ ๋๋ค. ๋ ๊นจ๋ํ ์๋ฃจ์ ์ด ์์ด์ผ ํฉ๋๋ค. ์ด์ฉ๋ฉด ์ฐ๋ฆฌ๊ฐ ๋ญ๊ฐ๋ฅผ ๋์น๊ณ ์์ต๋๊น? ( seq2seq ํํ ๋ฆฌ์ผ์์๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ฌ ์์ ๋ชจ๋ ์๋ฃจ์ ์ ์๋ํ์ต๋๋ค.)
@iamgroot42 - ์, ๊ทธ 'ํด๊ฒฐ์ฑ '์ ๋ถ๋ช ํ ๋งค์ฐ ์ถ์ ํ์ง๋ง ๋ฌธ์ ๊ฐ ์์ ์ ์๋ ์์น๋ฅผ ์ฐพ์ผ๋ ค๊ณ ํ๋ ๊ฒ์ด ๋ ๊ทธ๋ ์ต๋๋ค. ๋๋ ๋ช ์๊ฐ ํ์ ๊ทธ๊ฒ์ ๊ฐ์ง๊ณ ๋๊ณ ๋ด๊ฐ ๋ฌด์ธ๊ฐ๋ฅผ ์ถ์ ํ ์ ์๋์ง ๋ณผ ๊ฒ์ ๋๋ค.
์ฌ์ค copy.deepcopy๋ ๋ ๊ฑฐ์ ํจ์์ด๊ธฐ ๋๋ฌธ์ ์กด์ฌํฉ๋๋ค.
์ ์ง/์
๋ฐ์ดํธํ ๋ฆฌ์์ค๊ฐ ์์ต๋๋ค. ์ํ๋ ๊ฒฝ์ฐ
์ฌ์ฉ์๊ฐ ์ ๊ณตํ ์ ์๋ ์ด์ ๋ฒ์ ๊ณผ ํธํ๋๋ ๋ณ๊ฒฝ์ ๋์
๋์ฝ๋ฉ ๋จ๊ณ๋ฅผ ์ํ ๋ ๋ฒ์งธ ์
, ๊ทธ๋ฆฌ๊ณ None์ด๋ฉด ๋์ฒด
deepcopy, ๊ทธ๋ฌ๋ฉด PR์ ๊ฒํ ํ๊ฒ ๋์ด ๊ธฐ์ฉ๋๋ค. ํ ๊ฒ์ด๋ผ๋ ๊ฒ์ ๋ช
์ฌํ์ญ์์ค
์ด์ ๋ฒ์ ๊ณผ ํธํ๋๋ ๋ณ๊ฒฝ ์ฌํญ์ด์ด์ผ ํฉ๋๋ค.
2017๋
4์ 4์ผ ํ์์ผ ์ค์ 11:38, Rob Sylvester [email protected]
์ผ๋ค:
@iamgroot42 https://github.com/iamgroot42 - ๋ค, ๊ทธ 'ํด๊ฒฐ์ฑ '์
๋ถ๋ช ํ ๋งค์ฐ ์ถ์ ํ์ง๋ง ๋ฌธ์ ๊ฐ ์๋ ์์น๋ฅผ ์ฐพ์ผ๋ ค๊ณ ํ๋ ๊ฒฝ์ฐ์๋ ๋์ฑ ๊ทธ๋ ์ต๋๋ค.
์๋ง๋. ๋๋ ๋ช ์๊ฐ ํ์ ๊ทธ๊ฒ์ ๊ฐ์ง๊ณ ๋๊ณ ๋ด๊ฐ ๋ญ๊ฐ๋ฅผ ์ถ์ ํ ์ ์๋์ง ๋ณผ ๊ฒ์ ๋๋ค
์๋์.โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-291593289 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim1QHTDhOC_zT6cKtmUFPOit5Yjn7ks5rso5CgaJpZM4MWl4f
.
@ebrevdo - ์๊ฐํด๋ณผ๊ฒ์. ๋๋ ์ด๊ฒ๊ณผ ๋งค์ฐ ์ ์ฌํ๊ฒ ์๋ํ์ง๋ง ์ํ๋ ๊ณณ์ ์๋ฐฉํฅ ๋ ์ด์ด๋ฅผ ์ฝ์ ํ ์ ์๋ ๋ณ๋์ ํด๋์ค๋ฅผ ํตํด ์ ์ ์์ฑํ๊ณ , ์ํ๋ ๊ณณ์ ์์ฐจ๋ฅผ ์ฝ์ ํ๊ณ , ์ ๋ ฅ์ concat ๋ ํฉ๊ณ๋ก ๋ณํฉํ๋ ๋ฑ์ ๋ช ๊ฐ์ง ๋ค๋ฅธ ๋ฒ์ญ๊ธฐ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์ ์ RNN์ ์ฌ์ฉํ์ฌ ์ด ํํ ๋ฆฌ์ผ๋ก ๋ด ํด๋์ค๋ฅผ ์์ฃผ ์ฝ๊ฒ ๋ง์ด๊ทธ๋ ์ด์ ํ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ด๊ฐ ์๋ ค ์ฃผ๋ง.
@ebrevdo ์ ๋ Red Hat์์ Tensorflow r1.0(tensorflow-1.0.1-cp36-cp36m-linux_x86_64)์ ์คํ ์ค์ด๋ฉฐ Github์์ ์ต์ ๋ฒ์ ์ ๋ฒ์ญ ํํ ๋ฆฌ์ผ์ ๊ฐ์ง๊ณ ์์ต๋๋ค. ํ์ฌ ์ด ์์ ์ ์ํํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๋ฒ์ญ ํํ ๋ฆฌ์ผ์ด TF 1.0์์ ์๋ํ์ง ์๋ ๊ฒ์ ์ ๊ฐ์ ๋๋ค. ์ฐ๋ฆฌ๋ ๊ทธ๊ฒ์ ์์ ํด์ผํฉ๋๋ค. @lukaszkaiser ์ข ๋ด์ฃผ์๊ฒ ์ด์ ? ์ฐ๋ฆฌ๋ ์๋ก์ด ํํ ๋ฆฌ์ผ์ ์์ ์ค์ด์ง๋ง ์์ง ๋ช ์ฃผ ๋จ์๊ณ ์๋ํ๋ ค๋ฉด ์ผ๊ฐ ๋ฒ์ ์ TensorFlow(๋๋ TF 1.1 ๋๋ 1.2)๊ฐ ํ์ํฉ๋๋ค.
(lukasz; TF 1.0์์ ํํ ๋ฆฌ์ผ์ ์ด๋ ๋ถ๋ถ์ ๊ฒฐํจ์ด ์๋์ง ๋ค์ํ ์๊ฒฌ์์ ์๋ณํ๊ธฐ๊ฐ ์ด๋ ต์ต๋๋ค. ๋ผ์ธ์ ์๋ณํ ์ ์๊ณ ์๋ํ๋๋ก ๋์ธ ์ ์๋ ๊ธฐํ๊ฐ ์์ต๋๊น?)
@iamgroot42 ํ์ํ ๋ณ๊ฒฝ ์ฌํญ์ผ๋ก ํ๋ณดํ์๊ฒ ์ต๋๊น? ๊ทธ๊ฒ์ ์ข์ ๊ฒ์ ๋๋ค. ๋๋ ํ์ฌ ์ค์ค๋ก ๊ทธ๊ฒ์ ํ ์ ์๋ ์ฃผ๊ธฐ๊ฐ ์์ต๋๋ค. ๊ฐ์ฌ ํด์!
๋๋ TF 1.0์ด remotes/origin/r1.0 ๋ธ๋์น์ ์์ค์์ ์ปดํ์ผ๋ ๊ฒฝ์ฐ ์ต์ ๋ฒ์ ์ ๋ฒ์ญ ํํ ๋ฆฌ์ผ์์ ์ ์๋ํ๋ค๋ ๊ฒ์ ์์์ฐจ๋ ธ์ต๋๋ค.
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout remotes/origin/r1.0
๊ทธ๋ฐ ๋ค์ TensorFlow๋ฅผ ๋น๋ํ๊ณ ์ค์นํ๋ฉด ์ ์๋ํฉ๋๋ค.
remotes/origin/r1.1 ๋ถ๊ธฐ์๋ "๋ค๋ฅธ ๋ณ์ ๋ฒ์" ์ค๋ฅ๊ฐ ์์ต๋๋ค.
@robmsylvester ๊ฐ ์ ์ํ ๋๋ก ์ฝ๋๋ฅผ ์์ ํ์ต๋๋ค.
seq2seq ๋ชจ๋ธ ํ์ผ์ ์ธ์ฝ๋ ์ ๊ณผ ๋์ฝ๋ ์ ์ ๋ช ์์ ์ผ๋ก ์์ฑํ๊ณ ๋ ๋ค ๋ ๊ฑฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ์ ์ ๋ฌํ์ฌ ํจ์์ ํด๋น ์ธ์๋ฅผ ์ฝ๊ฐ ์กฐ์ ํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ ์ง๊ธ ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค.
@oxwsds ๋ด๊ฐ ์ฌ์ฉํ๋ Tensorflow๋ 1.0.1์ด๋ฏ๋ก ์ค๋ฅ๊ฐ ์์ ์ ์์ต๋๋ค.
@robmsylvester ๊ฐ ์ค์ ๋ก ์ ์ํ ๊ฒ์ ์๋ํ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ต์ก์ด ์์๋์์ต๋๋ค(2์ผ 13์๊ฐ ์๋ฃ).. ๋์ฝ๋ฉํ๋ ๋์ ์ค๋ฅ์ ํจ๊ป ์คํจํฉ๋๋ค.
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 883, in embedding_attention_seq2seq
initial_state_attention=initial_state_attention)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 787, in embedding_attention_decoder
initial_state_attention=initial_state_attention)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 686, in attention_decoder
cell_output, state = cell(x, state)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 796, in __call__
% (len(self.state_size), state))
ValueError: Expected state to be a tuple of length 3, but received: Tensor("model_with_buckets/embedding_attention_seq2seq/rnn/gru_cell_4/add:0", shape=(?, 1024), dtype=float32)
๋์ฝ๋ฉ์ ์๋ ํ์ต๋๊น?
@prashantserai ์ ํํ๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง ๋ง๋๋ณธ ๋ด์ฉ์ ๋ค๋ฅธ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
@prashantserai ๋์ฝ๋ฉํ ๋๋ง ์คํจํ๋ฉด ๋ฐฐ์น ํฌ๊ธฐ 1์ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ๊ด๋ จ์ด ์์ต๋๊น? ํ๋ จ ์ค์ ๋ฐฐ์น ํฌ๊ธฐ๋ฅผ 1๋ก ๋ฎ์ถ๋ฉด ๋ชจ๋ธ์ด ๊ณ์ ํ๋ จ๋ฉ๋๊น?
@bowu ์ฌ๊ธฐ์ ๊ฐ์ ์ค๋ฅ๊ฐ ์์ต๋๋ค. Mac OX ์์๋ผ, TensorFlow 1.1.0-rc1, Python 2.7.10 ๋ฐ Python 3.6.1.
@robmsylvester ๊ทธ๊ฒ์ ๋ฐฐ์น ํฌ๊ธฐ๋ 1๋ก ์ฑ๊ณต์ ์ผ๋ก ํ๋ จํ์ง๋ง ๊ฐ์ ๋ฐฉ์์ด๋ ์ ์ฌํ ๋ฐฉ์์ผ๋ก ๋์ฝ๋ฉํ๋ ๋์ ์คํจํ์ต๋๋ค. ์ฌ๊ธฐ์ ์ ์ฒด ์ญ์ถ์ ์ด ์์ต๋๋ค.. ๋ด๊ฐ ์ด๊ฒ์ ์ฐ๊ฒฐ๋ ์ค๋ฅ๋ก ์๊ฐํ ์ด์ ๋ ์ ๋ํ ์ฐธ์กฐ ๋๋ฌธ์ด์์ต๋๋ค. seq2seq_f(์์ ๋ ํจ์ ์ค ํ๋)(์์ ๋ ์ค์ ๋ํ๋ด๋ #prashant ์ฃผ์์ ์ถ์ ์ ์ผ๋ถ์)
2017-04-10 11:32:27.447042: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties:
name: GeForce GTX 780 Ti
major: 3 minor: 5 memoryClockRate (GHz) 0.928
pciBusID 0000:42:00.0
Total memory: 2.95GiB
Free memory: 2.88GiB
2017-04-10 11:32:27.447094: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0
2017-04-10 11:32:27.447102: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0: Y
2017-04-10 11:32:27.447118: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 780 Ti, pci bus id: 0000:42:00.0)
Traceback (most recent call last):
File "translate.py", line 322, in <module>
tf.app.run()
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "translate.py", line 317, in main
decode()
File "translate.py", line 248, in decode
model = create_model(sess, True)
File "translate.py", line 136, in create_model
dtype=dtype)
File "/data/data6/scratch/serai/models/tutorials/rnn/translate/seq2seq_model.py", line 168, in __init__
softmax_loss_function=softmax_loss_function)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1203, in model_with_buckets
decoder_inputs[:bucket[1]])
File "/data/data6/scratch/serai/models/tutorials/rnn/translate/seq2seq_model.py", line 167, in <lambda>
self.target_weights, buckets, lambda x, y: seq2seq_f(x, y, True),
File "/data/data6/scratch/serai/models/tutorials/rnn/translate/seq2seq_model.py", line 144, in seq2seq_f
dtype=dtype) #prashant
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 883, in embedding_attention_seq2seq
initial_state_attention=initial_state_attention)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 787, in embedding_attention_decoder
initial_state_attention=initial_state_attention)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 686, in attention_decoder
cell_output, state = cell(x, state)
File "/homes/3/serai/.conda/envs/tensorflow_r1.0_gpu/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 796, in __call__
% (len(self.state_size), state))
ValueError: Expected state to be a tuple of length 3, but received: Tensor("model_with_buckets/embedding_attention_seq2seq/rnn/gru_cell_4/add:0", shape=(?, 1024), dtype=float32)
@oxwsds ์์ ์ ์ฒด ์ถ์ ์ ๊ธฐ๋ฐ์ผ๋ก ๊ทํ์ ์๊ฒฌ์ด ๋ณ๊ฒฝ๋ฉ๋๊น?
@prashantserai ๋์ฝ๋ฉ์ ์๋ํ๋๋ฐ ์ ์๋ํฉ๋๋ค. encoder_cell
arg ๋ฅผ tf.contrib.legacy_seq2seq.embedding_attention_seq2seq
ํจ์์ ์ถ๊ฐํ๊ณ $ translate/seq2seq_model.py
์์ ์
์ ๋ง๋ค๊ณ seq2seq_f
ํจ์์์ ํธ์ถ๋ ํจ์์ ์ ๋ฌํฉ๋๋ค. ์ฝ๋๋ฅผ ์ด๋ป๊ฒ ๋ณ๊ฒฝํ์ต๋๊น?
@ssssss @robmsylvester @ebrevdo
๋ง์นจ๋ด ์ง๊ธ ์๋ํ๋ ๊ฒ์ด ์์ต๋๋ค(์ ๋จ์ผ ๋ ์ด์ด 256 ๋จ์ ๋คํธ์ํฌ์ ๋ํ ๊ฒฐ๊ณผ๋ ์ผ์ข
์ ๋์ฐํ์ง๋ง ๊ทธ๊ฒ์ ์๋ง๋ ๋คํธ์ํฌ๊ฐ ์ด๊ฒฝ๋์ด๊ณ ๋งค๊ฐ๋ณ์๋ฅผ ์ ํ ์กฐ์ ํ์ง ์์๊ธฐ ๋๋ฌธ์ผ ๊ฒ์
๋๋ค)
์ฌ๋ฌ๋ถ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค...!!!!!
_๋ง์ง๋ง์ ์ ์๊ฐ์ ์ด๋ ์ต๋๋ค._
@oxwsds ๋ Tensorflow๊ฐ remotes/origin/r1.0 ๋ธ๋์น์์ ์ปดํ์ผ๋ ๋ ์์ ์ด ํ์ ์์ด ํํ ๋ฆฌ์ผ(ํ์ฌ ํ์)์ด TRUE ๋ผ๊ณ ์ค๋ช ํฉ๋๋ค . ๊ทธ๋ฌ๋ ์ฌํ ๋นํธ๋ ๋ด๊ฐ ๊ฐ์ง๊ณ ์๋ Tensorflow ์ฝ๋ ๋ด์์ ์์ ์ด ํ์ํ Tensorflow ๋ฒ์ ๊ณผ remotes/origin/r1.0์ ๋ฒ์ ์ด ๋ชจ๋ ๋์ผํ๊ฒ ๋ ์ด๋ธ์ด ์ง์ ๋์๋ค๋ ๊ฒ์ ๋๋ค.
์ฃผ์์์ @robmsylvester ์ ์์ ์ฌํญ(์๋์ ๋ณต์ฌ๋จ)์ Tutorial์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์๋ํ์ง ์๋ ๋ด ๋ฒ์ ์ Tensorflow์์ ์๋ํ์ต๋๋ค(TF 1.1์์๋ ์๋ํด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค). ๊ตฌํํ๊ธฐ๊ฐ ์ฝ๊ฐ ์ง์ ๋ถํ์ง๋ง ํ ์ ์์ต๋๋ค. ์ฆ, ๋ญ๊ฐ๋ฅผ ๋งํ๊ณ ์์ต๋๋ค :-P
์ด ์ ์ ๋ด ๋ง์ง๋ง ๋ ๋๊ธ์ ์ค๋ฅ๋ ๋ด ์ค์๋ก ์ธํ ๊ฒ์
๋๋ค. ๋๋ฏธ์ฒ๋ผ ํ๋ จ ์ค์๋ง ๋ ์ด์ด์ ์๋ ์ ๋ ๋งค๊ฐ๋ณ์๋ฅผ ์ง์ ํ๊ณ ๋์ฝ๋ฉํ๋ ๋์ ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํ๋๋ก ์ฝ๋๋ฅผ ๊ทธ๋๋ก ๋์์ต๋๋ค. (ํํ ๋ฆฌ์ผ์ ์ด ๋ถ๋ถ์ ์ฝ๊ฐ ๋ ๋๋ฏธ ์ฆ๊ฑฐ๊ฐ ๋ ์ ์์ต๋๋ค: https://www.tensorflow.org/tutorials/seq2seq#lets_run_it )
ํ . ๋์๊ฒ ๋์ ๋๋ ํ ๊ฐ์ง๋ ์ฐธ์กฐ๋ ๋ ๊ฑฐ์ seq2seq ํ์ผ์ ์์ต๋๋ค.
์ธ์ฝ๋_์ = copy.deepcopy(์ )
์ธ์ฝ๋ ์ธก๊ณผ ๋์ฝ๋ ์ธก ๋ชจ๋์์ ๋์ผํ ์ํคํ ์ฒ๊ฐ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ์ด ๋ผ์ธ์ด ์ฌ์ฉ๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. ๊ทธ๋ค์ ์ ์ ๋ณต์ฌ๋ณธ์ ๋ง๋ ๋ค์ ์ ์ธ์๋ฅผ ์ดํ ์ ๋์ฝ๋ ์๋ฒ ๋ฉ ํจ์์ ํจ๊ป ์ ๋ฌํ ๋ค์ ์ดํ ์ ๋์ฝ๋ ์์ฒด๋ก ์ ๋ฌํฉ๋๋ค.
seq2seq ๋ชจ๋ธ ํ์ผ์ ์ธ์ฝ๋ ์ ๊ณผ ๋์ฝ๋ ์ ์ ๋ช ์์ ์ผ๋ก ์์ฑํ๊ณ ๋ ๋ค ๋ ๊ฑฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ์ ์ ๋ฌํ์ฌ ํจ์์ ํด๋น ์ธ์๋ฅผ ์ฝ๊ฐ ์กฐ์ ํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
ํผ๋๋ฐฑ ๊ฐ์ฌ๋๋ฆฝ๋๋ค! TF๋ง๋ค ๋ญ๊ฐ ๋ค๋ฅธ๊ฒ ๋ณด์ด๋ค์.
pypi์ ํด๋น ํ๊ทธ์์? ๊ฑดํ, ๊ทธ๊ฒ ๊ฐ๋ฅํด?
2017๋
4์ 10์ผ ์์์ผ ์คํ 9:05 prashantserai [email protected]
์ผ๋ค:
@oxwsds https://github.com/oxwsds @robmsylvester
https://github.com/robmsylvester @ebrevdo https://github.com/ebrevdo
๋๋ ๋ง์นจ๋ด ์ง๊ธ ์๋ํ๋ ๋ฌด์ธ๊ฐ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค (๋ด ๋ง์, ๋ด ์ฑ๊ธ์ ๋ํ ๊ฒฐ๊ณผ
๋ ์ด์ด 256 ๋จ์ ๋คํธ์ํฌ๋ ์ผ์ข ์ ๋์ฐํ์ง๋ง ์๋ง๋
๋คํธ์ํฌ๊ฐ ์ด๊ฒฝ๋์ด๊ณ ๋งค๊ฐ๋ณ์๋ฅผ ์ ํ ์กฐ์ ํ์ง ์์๊ธฐ ๋๋ฌธ์)๋ด ๊ฒฐ๋ก ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
@oxwsds https://github.com/oxwsds ๋ ํํ ๋ฆฌ์ผ์ดํ์ฌ ํ์) Tensorflow๊ฐ ์์ ๋ ์์ ํ ํ์ ์์ด ์๋ํฉ๋๋ค.remotes/origin/r1.0 ๋ธ๋์น์์ ์ปดํ์ผ๋ ๊ฒ์ TRUE ์ ๋๋ค. ์ฌํ ๋นํธ
๋ด๊ฐ ์์ ํ Tensorflow ๋ฒ์ ์ด์ง๋ง
Tensorflow ์ฝ๋ ๋ด์์ ํ์ํ์ผ๋ฉฐ remotes/origin/r1.0์ ๋ฒ์
๋ ๋ค ๋์ผํ๊ฒ ํ์๋์์ต๋๋ค.@robmsylvester https://github.com/robmsylvester ์ ๋๊ธ ์์
(์๋์ ๋ณต์ฌ) ์์ต์๊ฐ ์๋ Tensorflow ๋ฒ์ ์์ ์๋ํ์ต๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ์๋ํ์ง ์์์ต๋๋ค(TF 1.1์์๋ ์๋ํด์ผ ํฉ๋๋ค). ๊ทธ๊ฒ์
๊ตฌํํ๊ธฐ๊ฐ ์ฝ๊ฐ ์ง์ ๋ถํ์ง๋ง ํ ์ ์์ต๋๋ค.
:-ํผ
์ด ์ ์ ๋ด ๋ง์ง๋ง ๋ ๋๊ธ์ ์ค๋ฅ๋ ๋ด ์ค์๋ก ์ธํ ๊ฒ์ ๋๋ค. ์ข๋ค
๋๋ฏธ, ๋๋ ๋ ์ด์ด์ ์๋ ์ ๋ ๋งค๊ฐ๋ณ์๋ง ์ง์ ํ๊ณ ์์์ต๋๋ค.
ํ๋ จ ์ค์ ๋์ฝ๋ฉํ๋ ๋์ ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํ๋๋ก ์ฝ๋๋ฅผ ๊ทธ๋๋ก ๋์์ต๋๋ค. (์ด๊ฒํํ ๋ฆฌ์ผ์ ์ผ๋ถ๋ ์ฝ๊ฐ ๋ ๋๋ฏธ ์ฆ๊ฑฐ๊ฐ ๋ ์ ์์ต๋๋ค.https://www.tensorflow.org/tutorials/seq2seq#lets_run_ithttps://www.tensorflow.org/tutorials/seq2seq#lets_run_it )ํ . ๋์๊ฒ ๋์ ๋๋ ํ ๊ฐ์ง๋ ์ฐธ์กฐ๋ ๋ ๊ฑฐ์ seq2seq
ํ์ผ:์ธ์ฝ๋_์ = copy.deepcopy(์ )
๋์ผํ ์ํคํ ์ฒ๊ฐ ์์ชฝ ๋ชจ๋์์ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ์ด ๋ผ์ธ์ด ์ฌ์ฉ๋๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค.
์ธ์ฝ๋ ๋ฐ ๋์ฝ๋ ์ธก. ๊ทธ๋ค์ ์ ์ ์ฌ๋ณธ์ ๋ง๋ ๋ค์ ์ ๋ฌํฉ๋๋ค.
์ดํ ์ ๋์ฝ๋ ์๋ฒ ๋ฉ ๊ธฐ๋ฅ๊ณผ ํจ๊ป ์ ์ธ์, ๋ค์์ผ๋ก
์ฃผ์ ๋์ฝ๋ ์์ฒด.์ธ์ฝ๋ ์ ๊ณผ ๋์ฝ๋๋ฅผ ๋ช ์์ ์ผ๋ก ์์ฑํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
seq2seq ๋ชจ๋ธ ํ์ผ์ ์ ์ ๋ง๋ค๊ณ ๋ ๋ค ๋ ๊ฑฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ๋ฌํฉ๋๋ค.
ํ์ผ, ํจ์ ๋ฐ ํด๋น ์ธ์๋ฅผ ์ฝ๊ฐ ์กฐ์ ํฉ๋๊น?โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-293143828 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtimxvcfFnbWbpj7aUs3BUjwGEFj6p5ks5ruvvygaJpZM4MWl4f
.
์ ๋ณด๋ฅผ ์ํด LSTM ์
์ ์๋ ๋์ ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
๋ด ์๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(hidden_size, forget_bias=0.0, state_is_tuple=True)
if is_training and keep_prob < 1:
lstm_cell = tf.nn.rnn_cell.DropoutWrapper(
lstm_cell, output_keep_prob=keep_prob)
cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * num_layers, state_is_tuple=True)
๊ทธ๋ฐ ๋ค์ ๋ค์ ์ฝ๋๋ก ๋ชจ๋ธ์ ๋ง๋๋ ๊ฒ์ ๊ด์ฐฎ์์ง๋ง ๋ค๋ฅธ ๋ชจ๋ธ๊ณผ ๋ณ์๋ฅผ ๊ณต์ ํ ์ ์์์ต๋๋ค. (์๋ฅผ ๋ค์ด ํ ์๋ฅผ ๊ณต์ ํด์ผ ํ๋ train_model ๋ฐ valid_model์ ์์ฑํ๋ฉด ์คํจํฉ๋๋ค)
lstm_creator = lambda: tf.contrib.rnn.BasicLSTMCell(
hidden_size,
forget_bias=0.0, state_is_tuple=True)
if is_training and keep_prob < 1:
cell_creator = lambda:tf.contrib.rnn.DropoutWrapper(
lstm_creator(), output_keep_prob=keep_prob)
else:
cell_creator = lstm_creator
cell = tf.contrib.rnn.MultiRNNCell([cell_creator() for _ in range(num_layers)], state_is_tuple=True)
๊ทธ๋์ ๋ง์ง๋ง์ผ๋ก lstm_creator
๋ฅผ tensorflow/models/tutorials/rnn/ptb/ptb_word_lm.py#L112 ์์ lstm_cell
์ ๊ฐ์ ํจ์๋ก ์ฌ์ฉํ์ต๋๋ค. ๋๋ ์ง๊ธ ๊ฐ์ง๊ณ ์๋ค :
def lstm_cell():
# With the latest TensorFlow source code (as of Mar 27, 2017),
# the BasicLSTMCell will need a reuse parameter which is unfortunately not
# defined in TensorFlow 1.0. To maintain backwards compatibility, we add
# an argument check here:
if 'reuse' in inspect.getargspec(
tf.contrib.rnn.BasicLSTMCell.__init__).args:
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True,
reuse=tf.get_variable_scope().reuse)
else:
return tf.contrib.rnn.BasicLSTMCell(
size, forget_bias=0.0, state_is_tuple=True)
attn_cell = lstm_cell
lstm_creator = lstm_cell
if is_training and keep_prob < 1:
cell_creator = lambda:tf.contrib.rnn.DropoutWrapper(
lstm_creator(), output_keep_prob=keep_prob)
else:
cell_creator = lstm_creator
cell = tf.contrib.rnn.MultiRNNCell([cell_creator() for _ in range(num_layers)], state_is_tuple=True)
์ด์ ์์ ํ ์๋ํฉ๋๋ค.
์ด ์์ ์ ์คํํ๋ ค๊ณ ํ๋ฉด ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
https://gist.github.com/danijar/c7ec9a30052127c7a1ad169eeb83f159#file -blog_tensorflow_sequence_classification-py-L38
@pltrdy ์ ์๋ฃจ์ ์ ์ด์ํ๊ฒ ๋๋ฅผ ์ํด ๊ทธ๊ฒ์ํ์ง ์์์ต๋๋ค. ๋๋ ์ ์
ValueError: Variable rnn/multi_rnn_cell/cell_0/basic_lstm_cell/weights does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?
@aep ๋ https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb/ptb_word_lm.py#L112 ์ ๊ธฐ๋ฅ์ ์ฌ์ฉํ์ จ์ต๋๊น? ๋ด ๊ฒ์๋ฌผ ๋์์ ์ธ๊ธํ(์ด์ ๋ ๋ช ํํ๊ฒ ํธ์ง )
cells=[]
for _ in range(15):
cell = create_lstm_cell(config)
cells.append(cell)
lsmt_layers = rnn.MultiRNNCell(cells)
๊ทธ๊ฒ์ ๋ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค
์ด์ ๋ฒ์ ์ Tensorflow๋ฅผ ์ค์นํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.
pip install -Iv tensorflow==1.0
seq2seq ํํ ๋ฆฌ์ผ์ ์คํํ ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
@ebrevdo ๊ฐ ๋งํ ๊ฒ๊ณผ ๊ด๋ จํ์ฌ ์๋ฃจ์
์ ๋ ๊ฑฐ์ seq2seq ์ฝ๋๋ฅผ ์์ ํ๋ ๊ฒ์ด ์๋๋ผ ์ ๊ทน์ ์ผ๋ก ์ ์ง ๊ด๋ฆฌ๋๋ contrib.seq2seq
ํจํค์ง๋ฅผ ๋์ ์ฌ์ฉํ๋๋ก ์์ต์๋ฅผ ์
๋ฐ์ดํธํ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์ฒ์์ผ๋ก ์คํํ tensorflow ํ๋ก๊ทธ๋จ์ด ๋ง์ ์ค๋ฅ๋ฅผ ๋ฑ์ด๋ด๋ ๊ฒ์ ๋งค์ฐ ์ฌ๊ธฐ๋ฅผ ์ ํ์ํต๋๋ค. ์ด๋ฒ ์ฃผ์ ์๊ฐ์ด ๋๋ฉด PR์ ์ ์ถํ๊ฒ ์ต๋๋ค.
์ฐ๋ฆฌ๋ ์๋ก์ด seq2seq ํํ ๋ฆฌ์ผ์ ์งํ ์ค์
๋๋ค. ์ฐ๋ฆฌ๋ ๋ง๊น์ง ์ถ์๋๊ธฐ๋ฅผ ๋ฐ๋์ต๋๋ค.
์ง๋ ๋ฌ์ด์ง๋ง ์ง์ฐ๋๊ณ ์์ต๋๋ค. ์ API๋ฅผ ์ฌ์ฉํฉ๋๋ค.
2017๋ 5์ 1์ผ ์ค์ 8์ 7๋ถ์ "Kyle Teague" [email protected] ์ด ์์ฑํ์ต๋๋ค.
@ebrevdo https://github.com/ebrevdo ๊ฐ ๋งํ ๊ฒ๊ณผ ๊ด๋ จํ์ฌ ์ ์๊ฐ์๋
ํด๊ฒฐ์ฑ ์ ๋ ๊ฑฐ์ seq2seq ์ฝ๋๋ฅผ ์์ ํ๋ ๊ฒ์ด ์๋๋ผ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ ๋๋ค.
๋์ ์ ๊ทน์ ์ผ๋ก contrib.seq2seq ํจํค์ง๋ฅผ ์ฌ์ฉํ๋ ์์ต์
์ ์ง. ์ฒ์ tensorflow ํ๋ก๊ทธ๋จ์ ์์ํ ๋ ๋งค์ฐ ์ฌ๊ธฐ๋ฅผ ๋จ์ด๋จ๋ฆฝ๋๋ค.
์ด์ ๊น์ง ์คํํ๋ฉด ๋ง์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ด๋ฒ ์ฃผ์ ์๊ฐ์ด ๋๋ค๋ฉด
PR์ ์ ์ถํฉ๋๋ค.โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-298350307 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim587xZx9Gi4-yXmwccSum8_Trc1oks5r1fUogaJpZM4MWl4f
.
@ebrevdo tensorflow1.1 ์น์ฌ์ดํธ์์ sequence_to_sequence ๋ชจ๋ธ์ ์คํํ ๋๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ 'use' ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ์ง๋ง ์คํจํ์ต๋๋ค. ์๋ก์ด seq2seq ํํ ๋ฆฌ์ผ์ด ์ธ์ ์ถ์๋๋์ง ์๋ ค์ฃผ์๊ฒ ์ต๋๊น?
tf 1.2์ ๋์์ ๋ณด์
๋๋ค. ์๋ํ๋ฉด ์ฐ๋ฆฌ๋ ์๋ก์ด
ํด๋น ๋ฆด๋ฆฌ์ค์ ๊ธฐ๋ฅ.
2017๋ 5์ 4์ผ ์คํ 9์ 16๋ถ์ "njuzrs" [email protected] ์ด ์์ฑํ์ต๋๋ค.
@ebrevdo https://github.com/ebrevdo ์คํํ ๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค
tensorflow1.1 ์น์ฌ์ดํธ์ sequence_to_sequence ๋ชจ๋ธ. ๊ทธ๋ฆฌ๊ณ ๋๋ ์๋ํ๋ค
'์ฌ์ฌ์ฉ' ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํ์ง๋ง ์คํจํ์ต๋๋ค. ์๋ก์ด seq2seq๊ฐ ์ธ์ ์ธ์ง ์๋ ค์ฃผ์๊ฒ ์ต๋๊น?
ํํ ๋ฆฌ์ผ์ด ๊ณต๊ฐ๋๋์?โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-299366774 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim8_kFTM7-SsXQAA-Ar0dfhHMGT0Zks5r2qKngaJpZM4MWl4f
.
@ebrevdo ์ ๋ ๊ฐ์ ๋ฌธ์ ์ ์ง๋ฉดํด ์์ผ๋ฉฐ seq2seq๋ก ์งํํ ์ ์์ต๋๋ค. ์ ํํ ๋ฆฌ์ผ์ ๊ฐ๋ฅํ ๋ ์ง๋ฅผ ์๋ ค์ฃผ์๋ฉด ์ ๋ง ๋์์ด ๋ ๊ฒ์
๋๋ค.
๋์ ์ฃผ์
์ ์ ๋ง๋ก ๊ณ ๋ง์ต๋๋ค.
pip install tensorflow==1.0
(Tensorflow 1.0)์ ์ฌ์ฉํ์ฌ ์ค์นํ๋ ๊ฒ์ด ํจ๊ณผ์ ์
๋๋ค(ํํ ๋ฆฌ์ผ ๋ฒ์ญ).
๋ฒ์ 1.1.0-rc2๊ฐ ์์ต๋๋ค.
TF1.2๊ฐ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ๊น์? ๋ชจ๋ธ ๊ต์ก์ ๊ณ์ํ๋ ๋ฐฉ๋ฒ์ ์๋ ค์ฃผ์ธ์. TF 1.0์ ์๋ํ์ง๋ง ์ฌ๋ฌ GPU์ ๋ํ devicewrapper API๊ฐ ์์ต๋๋ค.
ํ ์ ํ๋ฆ 1.1๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ฌ์ ํ ์๋ฃจ์ ์์ ์ค
์ฌ๋ฌ ๊ฐ์ง๋ฅผ ์๋ํ์ง๋ง ๊ฒฐ๊ตญ tensorflow 1.1์ ์ฌ์ฉํ ์ ์์์ง๋ง ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํด์ผ ํ์ต๋๋ค. (์์ Tshzzz ๊ธฐ๋ฐ)
์ด๊ฒ์ ์ ๊ฑฐํ์ญ์์ค:
multicell = rnn.MultiRNNCell([dropcell]*NLAYERS, state_is_tuple=False)
๊ทธ๋ฆฌ๊ณ ์ด๊ฒ์ ์ถ๊ฐํ์ญ์์ค:
์
=[]
_ ๋ฒ์ ๋ด(NLAYERS):
์
= rnn.DropoutWrapper(tf.contrib.rnn.GRUCell(INTERNALSIZE), input_keep_prob=pkeep)
cells.append(์
)
multicell = rnn.MultiRNNCell(์
, state_is_tuple=False)
@ebrevdo ์ถํํฉ๋๋ค. TF 1.2๊ฐ ๋ฐฉ๊ธ ์ถ์๋์์ต๋๋ค. ์ ํํ ๋ฆฌ์ผ๋ ์ด๋๊ฐ์ ์ถ์๋์๋์? ์๋๋ฉด ๊ณง ์ถ์๋ ์์ ์ธ๊ฐ์?
๊ฐ์ฌ ํด์
์ถ์๋๋ฉด ๊ณต์งํ ์์ ์ ๋๋ค. ์์ ์ค์ ๋๋ค.
2017๋ 5์ 19์ผ ์คํ 7์ 2๋ถ์ "prashantserai" [email protected] ์ด ์์ฑํ์ต๋๋ค.
@ebrevdo https://github.com/ebrevdo ์ถํํฉ๋๋ค. TF 1.2๊ฐ ๋์์ต๋๋ค.
์ถ์๋จ - ์ ํํ ๋ฆฌ์ผ๋ ์ด๋๊ฐ์ ์ถ์๋์์ต๋๊น?
๊ณง ์ถ์?๊ฐ์ฌ ํด์
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-302844002 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim0RWDzNCXk-bIjKSyHLvgFxUvq2lks5r7km7gaJpZM4MWl4f
.
tensorflow-gpu==1.1.0์ ์ฌ์ฉํ๊ณ ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ์ฌ๋์ pip install tensorflow-gpu==1.0.0์ ํตํด 1.0.0์ผ๋ก ์ ํํด๋ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์ง ์์ต๋๋ค. ์ ์ด๋ ์ ์๊ฒ๋ ํจ๊ณผ๊ฐ ์์์ต๋๋ค.
๋๋ mac๊ณผ ubuntu ๋ชจ๋์์ ์ด ๋ฌธ์ ์ ๋ถ๋ช์ณค๊ณ ์์ค์์ ์ปดํ์ผํ๋ ๊ฒ์ด ๋ ๋ฒ ๋ชจ๋ ์๋ํ์ต๋๋ค. ๊ทธ๋์:
ํ ์ค์น https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp34-cp34m-linux_x86_64.whl
@ajaanbaahu ์ฌ์ ํ tf1.2 ์๋ก์ด seq2seq ํํ ๋ฆฌ์ผ์ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ต๋๋ค.
pip install tensorflow==1.0
์ ์ฌ์ฉํ์ฌ ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
tf r1.2์ ๊ฒฝ์ฐ deepcopy ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ชจ๋ธ ์ค๋ฅ #1050์ ์์ ๋๋ก ๋์ดํ ๋๋ก
์ ์ธ์ผ๋ก์ ์ ์๊ฒฌ์ ์ข ์ฌ๋ฆฝ๋๋ค.
๋ค์ ์ฝ๋๋ ์ด์ ์ ์ฌํ ์ค์๋ฅผ ๋ฐ์์ํต๋๋ค.
(๋ด ์ฝ๋์ ์ผ๋ถ)
lstm_cell = self.LSTMCell(self.num_hidden)
lstm_entity = tf.contrib.rnn.DropoutWrapper(lstm_cell, output_keep_prob=0.5)
layer = tf.contrib.rnn.MultiRNNCell([lstm_entity] * self.num_layer)
__, _ = tf.nn.dynamic_rnn(layer, self.data, dtype=tf.float64)
๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ ๋คํ:
Traceback (most recent call last):
File "IntentNet.py", line 71, in <module>
net = Net(data, target, 5, 1)
File "IntentNet.py", line 45, in __init__
__, _ = tf.nn.dynamic_rnn(layer, self.data, dtype=tf.float64)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 553, in dynamic_rnn
dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 720, in _dynamic_rnn_loop
swap_memory=swap_memory)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2623, in while_loop
result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2456, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2406, in _BuildLoop
body_result = body(*packed_vars_for_body)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 705, in _time_step
(output, new_state) = call_cell()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py", line 691, in <lambda>
call_cell = lambda: cell(input_t, state)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 953, in __call__
cur_inp, new_state = cell(cur_inp, cur_state)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 713, in __call__
output, new_state = self._cell(inputs, state, scope)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 235, in __call__
with _checked_scope(self, scope or "basic_lstm_cell", reuse=self._reuse):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 77, in _checked_scope
type(cell).__name__))
ValueError: Attempt to reuse RNNCell <tensorflow.contrib.rnn.python.ops.core_rnn_cell_impl.BasicLSTMCell object at 0x7fe4fc7bd150> with a different variable scope than its first use. First use of cell was with scope 'rnn/multi_rnn_cell/cell_0/basic_lstm_cell', this attempt is with scope 'rnn/multi_rnn_cell/cell_1/basic_lstm_cell'. Please create a new instance of the cell if you would like it to use a different set of weights. If before you were using: MultiRNNCell([BasicLSTMCell(...)] * num_layers), change to: MultiRNNCell([BasicLSTMCell(...) for _ in range(num_layers)]). If before you were using the same cell instance as both the forward and reverse cell of a bidirectional RNN, simply create two instances (one for forward, one for reverse). In May 2017, we will start transitioning this cell's behavior to use existing stored weights, if any, when it is called with scope=None (which can lead to silent model degradation, so this error will remain until then.)
๊ทธ๋ฌ๋ ์์ ์์ ์ ์ํํ ํ์๋ ์๋ํ ์ ์์ต๋๋ค.
"""
lstm_cell = self.LSTMCell(self.num_hidden)
lstm_entity = tf.contrib.rnn.DropoutWrapper(lstm_cell, output_keep_prob=0.5)
layer = tf.contrib.rnn.MultiRNNCell([lstm_entity] * self.num_layer)
"""
layer = []
for i in range(self.num_layer):
lstm_cell = self.LSTMCell(self.num_hidden)
lstm_entity = tf.contrib.rnn.DropoutWrapper(lstm_cell, output_keep_prob=0.5)
layer.append(lstm_entity)
layer = tf.contrib.rnn.MultiRNNCell(layer)
__, _ = tf.nn.dynamic_rnn(layer, self.data, dtype=tf.float64)
์ด๋ฌํ ํด๊ฒฐ ๋ฐฉ๋ฒ ์ค ์ด๋ ๊ฒ๋ Tensorflow 1.1์์ ์๋ํ์ง ์์์ต๋๋ค.
MultiRNNCell
์
์ด ์๋ seq2seq
๋ชจ๋ธ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
๋๋ 1.0.1๋ก ๋๋์๊ฐ์ผ ํ๋ค: pip3 install tensorflow==1.0
legacy_seq2seq.rnn_decoder()๋ก ์์ ํ ๋ ์ด๋ฌํ ๋ฌธ์ ๊ฐ ์๋ ์ฌ๋์ด ์์ต๋๊น?
@oxwsds ๋ง์ํ์ ๋๋ก tf.contrib.legacy_seq2seq.embedding_attention_seq2seq์ ์
๋ ฅ ์ธ์ ์
์ ๋ ๊ฐ์ ๋ค๋ฅธ ์
{encoder_cells, decoder_cells}๋ก ๋ณ๊ฒฝํฉ๋๋ค. ๋ง์ง๋ง์ผ๋ก seq2seq ๋ชจ๋ธ์ด ์๋ํฉ๋๋ค. 73200 setps ํ์ ๋นํน๋ 5.54๋ฅผ ์ป์ต๋๋ค.
๊ทธ๋ฐ ๋ค์ ๋์ฝ๋ฉ ๋ถ๋ถ์ ์คํํฉ๋๋ค.
๋ฏธ๊ตญ ๋ํต๋ น์ ๋๊ตฌ์ ๋๊น?
Qui est le prรฉsident des รtats-Unis?
๋ฌธ์ ํด๊ฒฐ๋จ. ๊ฐ์ฌ ํด์.
@doncat99
seq2seq.py
์ copy.deepcopy(cell)
$์ด(๊ฐ) ์ ์ฉ๋์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฐ๋ผ์ seq2seq_model.py
์ ๊ด๋ จ ๋ถ๋ถ์ ๋ค์์ผ๋ก ๋ณ๊ฒฝํฉ๋๋ค.
if num_layers > 1:
cell_enc = tf.contrib.rnn.MultiRNNCell([single_cell() for _ in range(num_layers)])
cell_dec = tf.contrib.rnn.MultiRNNCell([single_cell() for _ in range(num_layers)])
# The seq2seq function: we use embedding for the input and attention.
def seq2seq_f(encoder_inputs, decoder_inputs, do_decode):
return seq2seq.embedding_attention_seq2seq(
encoder_inputs,
decoder_inputs,
cell_enc,
cell_dec,
num_encoder_symbols=source_vocab_size,
num_decoder_symbols=target_vocab_size,
embedding_size=size,
output_projection=output_projection,
feed_previous=do_decode,
dtype=dtype)
@supermeatboy82 , ์ฝ๋๋ฅผ ๊ณต์ ํ ์ ์์ต๋๊น?
Tensorflow 1.2.0์ผ๋ก ์ ๊ทธ๋ ์ด๋ํ๊ณ ๋ชฉ๋ก ๊ณฑ์ ๋์ ๋ฃจํ์์ ์ ์ ์์ฑํ๋ฉด ์ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
translate.py๋ฅผ ์คํํ ๋ TF1.2์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ธ๋ถ ์ ๋ณด:
์ด๋ฆ: ์งํฌ์ค GTX 1080 Ti
๋ฉ์ด์ : 6 ๋ง์ด๋: 1 memoryClockRate(GHz) 1.582
pci๋ฒ์คID 0000:02:00.0
์ด ๋ฉ๋ชจ๋ฆฌ: 10.91GiB
์ฌ์ ๋ฉ๋ชจ๋ฆฌ: 10.76GiB
2017-06-22 09:15:04.485252: I tensorflow/core/common_runtime/gpu/gpu_device.cc:961] DMA: 0
2017-06-22 09:15:04.485256: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: Y
2017-06-22 09:15:04.485265: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] TensorFlow ์ฅ์น ์์ฑ(/gpu:0) -> (์ฅ์น: 0, ์ด๋ฆ: GeForce GTX 1080 Ti, pci ๋ฒ์ค ID: 0000:02:00.0)
1024 ์ ๋์ 3๊ฐ์ ๋ ์ด์ด๋ฅผ ์์ฑํฉ๋๋ค.
์ญ์ถ์ (๊ฐ์ฅ ์ต๊ทผ ํธ์ถ ๋ง์ง๋ง):
ํ์ผ "translate.py", 322ํ,
tf.app.run()
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", 48ํ, ์คํ ์ค
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
ํ์ผ "translate.py", 319ํ, ๋ฉ์ธ
๊ธฐ์ฐจ()
๊ธฐ์ฐจ์์ ํ์ผ "translate.py", 178ํ
๋ชจ๋ธ = create_model(sess, False)
create_model์ ํ์ผ "translate.py", 136ํ
dtype=dtype)
ํ์ผ "/data/research/github/dl/tensorflow/tensorflow/models/tutorials/rnn/translate/seq2seq_model.py", 179ํ, __init__
softmax_loss_function=softmax_loss_function)
model_with_buckets์ ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", 1206ํ
๋์ฝ๋_์
๋ ฅ[:๋ฒํท[1]])
ํ์ผ "/data/research/github/dl/tensorflow/tensorflow/models/tutorials/rnn/translate/seq2seq_model.py", ๋ผ์ธ 178, in
๋๋ค x, y: seq2seq_f(x, y, False),
ํ์ผ "/data/research/github/dl/tensorflow/tensorflow/models/tutorials/rnn/translate/seq2seq_model.py", 142ํ, seq2seq_f
dtype=dtype)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", 848ํ, embedding_attention_seq2seq
์ธ์ฝ๋_์
= copy.deepcopy(์
)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 174ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/base.py", 476ํ, __deepcopy__
setattr(๊ฒฐ๊ณผ, k, copy.deepcopy(v, ๋ฉ๋ชจ))
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 230ํ, _deepcopy_list
y.append(deepcopy(a, ๋ฉ๋ชจ))
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 230ํ, _deepcopy_list
y.append(deepcopy(a, ๋ฉ๋ชจ))
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 230ํ, _deepcopy_list
y.append(deepcopy(a, ๋ฉ๋ชจ))
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 237ํ, _deepcopy_tuple
y.append(deepcopy(a, ๋ฉ๋ชจ))
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 334ํ, _reconstruct
์ํ = deepcopy(์ํ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 163ํ, deepcopy
y = ๋ณต์ฌ๊ธฐ(x, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 257ํ, _deepcopy_dict
y[deepcopy(ํค, ๋ฉ๋ชจ)] = deepcopy(๊ฐ, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 190ํ, deepcopy
y = _reconstruct(x, rv, 1, ๋ฉ๋ชจ)
ํ์ผ "/home/lscm/opt/anaconda2/lib/python2.7/copy.py", 343ํ, _reconstruct
y.__dict__.update(์ํ)
AttributeError: 'NoneType' ๊ฐ์ฒด์ '์
๋ฐ์ดํธ' ์์ฑ์ด ์์ต๋๋ค.
ํํ ๋ฆฌ์ผ์ ๋ฒ์ญ ๋ชจ๋ธ์์ self_test()
๋ฅผ ์คํํ ๋ embedding_attention_seq2seq()
copy.deepcopy(cell)
๋ก ์ธํ ์ค๋ฅ๋ ๋ง๋ฌ์ต๋๋ค.
Seq2SeqModel
seq2seq_f()
์ ์ฝ๋๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํ๋ ค๊ณ ํ์ต๋๋ค.
def seq2seq_f(encoder_inputs, decoder_inputs, do_decode=False):
tmp_cell = copy.deepcopy(cell) #new
return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
encoder_inputs,
decoder_inputs,
tmp_cell, #new
num_encoder_symbols=source_vocab_size,
num_decoder_symbols=target_vocab_size,
embedding_size=size,
output_projection=output_projection,
feed_previous=do_decode,
dtype=dtype)
๊ทธ๋ฌ๋ฉด ์ด์ ์ค๋ฅ๊ฐ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ ์ธ์ผ๋ก์ ์ฌ๊ธฐ ์ฝ๋๊ฐ ์ด์ ๊ณผ ๊ฐ์ด ์๋ํ๋์ง ์ฌ๋ถ๋ฅผ ์์ง ๋ชปํ๋ฉฐ ๋ณ๊ฒฝ ์ฌํญ์ผ๋ก ์ธํด ๋ชจ๋ธ์ด ๋๋ฆฌ๊ฒ ์คํ๋๋ ๊ฒ ๊ฐ์ต๋๋ค.
tensorflow๋ฅผ 1.0.0(tensorflow-GPU)์ผ๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ์ผ๋ฉฐ ์ ์๊ฒ ํจ๊ณผ์ ์ด๋ผ๋ ์ฌ์ค์ ๋ชจ๋ ์ฌ๋์๊ฒ ์
๋ฐ์ดํธํ๊ณ ์ถ์ต๋๋ค. ๋ชจ๋ธ์ด ์์๋๋ก ์๋ํ๊ณ ์์ต๋๋ค. 1.0.0์ CPU ๋ฒ์ ์ด ์์๋๋ก ์๋ํด์ผ ํ๋ค๊ณ ๊ฐ์ ํฉ๋๊น? ๋๋?.
๊ฐ์ฌ ํด์ :)
์๋
ํ์ธ์ ์ฌ๋ฌ๋ถ, ์ฌ์ ํ ๊ด์ฌ์ด ์๋์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง embedding_attention_seq2seq
ํจ์์ ๋งค๊ฐ๋ณ์๋ก ์ ๋ฌ๋ ์
์ ๋ณต์ฌํ๋ ์์
๊ณผ ๊ด๋ จ๋ ๋ฌธ์ ๋ผ๋ ๊ฒ์ ์์์ต๋๋ค. ์ธ์ฝ๋์ ๋์ฝ๋ ๋ชจ๋์ ๋์ผํ ์
์ ์๊ฐ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด ํํ ๋ฆฌ์ผ์ ๋์ seq2seq์ ๋์กฐ์ ์ผ๋ก ๋ฒํทํ
์ด ์๋ seq2seq ๋ชจ๋ธ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๋ ์ด์ ์ฌ์ฉ๋์ง ์๋๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๋ฌ๋ ์๋ํ๋ ์์ ๋ ๊ธฐ๋ฅ์ ๋ถ์ฌ๋ฃ๊ณ ์์ต๋๋ค. ํจ์๋ tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py
ํ์ผ์์ ์
๋ฐ์ดํธ๋ฉ๋๋ค.
๊ฐ์ฌ,
ํ๋น์ค
```!ํ์ด์ฌ
def embedding_attention_seq2seq(encoder_inputs,
๋์ฝ๋_์
๋ ฅ,
enc_cell,
dec_cell,
num_encoder_symbols,
num_decoder_symbols,
์๋ฒ ๋ฉ_ํฌ๊ธฐ,
num_heads=1,
output_projection=์์,
feed_previous=๊ฑฐ์ง,
dtype=์์,
๋ฒ์=์์,
initial_state_attention=๊ฑฐ์ง):
"""์ฃผ์๋ฅผ ๊ธฐ์ธ์ฌ sequence-to-sequence ๋ชจ๋ธ์ ํฌํจํฉ๋๋ค.
์ด ๋ชจ๋ธ์ ๋จผ์ ์๋ก ์์ฑ๋ ์๋ฒ ๋ฉ(๋ชจ์
[num_encoder_symbols x input_size]). ๊ทธ๋ฐ ๋ค์ RNN์ ์คํํ์ฌ ์ธ์ฝ๋ฉํฉ๋๋ค.
์๋ฒ ๋๋ ์ธ์ฝ๋_์
๋ ฅ์ ์ํ ๋ฒกํฐ์ ๋ฃ์ต๋๋ค. ์ด ์ถ๋ ฅ์ ์ ์งํฉ๋๋ค.
๋์ค์ ์ฃผ์๋ฅผ ๋๊ธฐ ์ํด ๋ชจ๋ ๋จ๊ณ์์ RNN์ ์ฌ์ฉํฉ๋๋ค. ๋ค์์ผ๋ก ๋์ฝ๋_์
๋ ฅ์ ํฌํจํฉ๋๋ค.
์๋ก ์์ฑ๋ ๋ค๋ฅธ ์๋ฒ ๋ฉ(๋ชจ์ [num_decoder_symbols x
input_size]). ๊ทธ๋ฐ ๋ค์ ๋ง์ง๋ง์ผ๋ก ์ด๊ธฐํ๋ ์ฃผ์ ๋์ฝ๋๋ฅผ ์คํํฉ๋๋ค.
์ธ์ฝ๋ ์ํ, ์๋ฒ ๋๋ ๋์ฝ๋_์
๋ ฅ ๋ฐ ์ธ์ฝ๋ ์ถ๋ ฅ์ ์ฃผ์.
๊ฒฝ๊ณ : output_projection์ด None์ด๋ฉด ์ฃผ์ ๋ฒกํฐ์ ํฌ๊ธฐ
๋ณ์๋ num_decoder_symbols์ ๋น๋กํ์ฌ ๋ง๋ค์ด์ง๋ฉฐ ํด ์ ์์ต๋๋ค.
์ธ์:
์ธ์ฝ๋_์
๋ ฅ: [batch_size] ๋ชจ์์ 1D int32 ํ
์ ๋ชฉ๋ก์
๋๋ค.
๋์ฝ๋_์
๋ ฅ: ๋ชจ์์ด [batch_size]์ธ 1D int32 ํ
์์ ๋ชฉ๋ก์
๋๋ค.
cell: tf.nn.rnn_cell.RNNCell ์
๊ธฐ๋ฅ ๋ฐ ํฌ๊ธฐ๋ฅผ ์ ์ํฉ๋๋ค.
num_encoder_symbols: ์ ์; ์ธ์ฝ๋ ์ธก์ ๊ธฐํธ ์.
num_decoder_symbols: ์ ์; ๋์ฝ๋ ์ธก์ ์ฌ๋ณผ ์.
Embedding_size: ์ ์, ๊ฐ ์ฌ๋ณผ์ ๋ํ ์๋ฒ ๋ฉ ๋ฒกํฐ์ ๊ธธ์ด.
num_heads: Attention_states์์ ์ฝ์ ์ฃผ์ ํค๋์ ์์
๋๋ค.
output_projection: ์์ ๋๋ ์ถ๋ ฅ ํฌ์ ๊ฐ์ค์น ์(W, B) ๋ฐ
ํธ๊ฒฌ; W์ ๋ชจ์์ [output_size x num_decoder_symbols]์ด๊ณ B๋
๋ชจ์ [num_decoder_symbols]; ์ ๊ณต๋๊ณ feed_previous=True์ธ ๊ฒฝ์ฐ ๊ฐ๊ฐ
๊ณต๊ธ๋ ์ด์ ์ถ๋ ฅ์ ๋จผ์ W๋ฅผ ๊ณฑํ๊ณ B๋ฅผ ๋ํฉ๋๋ค.
feed_previous: ๋ถ์ธ ๋๋ ์ค์นผ๋ผ ๋ถ์ธ ํ
์ ์ฐธ์ด๋ฉด ์ฒซ ๋ฒ์งธ
Decoder_inputs("GO" ๊ธฐํธ)๊ฐ ์ฌ์ฉ๋๊ณ ๋ค๋ฅธ ๋ชจ๋ ๋์ฝ๋
์
๋ ฅ์ ์ด์ ์ถ๋ ฅ์์ โโ๊ฐ์ ธ์ต๋๋ค(embedding_rnn_decoder์์์ ๊ฐ์ด).
False์ธ ๊ฒฝ์ฐ Decoder_inputs๋ ์ฃผ์ด์ง ๋๋ก ์ฌ์ฉ๋ฉ๋๋ค(ํ์ค ๋์ฝ๋ ๊ฒฝ์ฐ).
dtype: ์ด๊ธฐ RNN ์ํ์ dtype(๊ธฐ๋ณธ๊ฐ: tf.float32).
๋ฒ์: ์์ฑ๋ ํ์ ๊ทธ๋ํ์ ๋ํ VariableScope; ๊ธฐ๋ณธ๊ฐ์
"embedding_attention_seq2seq".
initial_state_attention: False(๊ธฐ๋ณธ๊ฐ)์ธ ๊ฒฝ์ฐ ์ด๊ธฐ ์ฃผ์๋ 0์
๋๋ค.
True์ด๋ฉด ์ด๊ธฐ ์ํ์์ ์ฃผ์ ์ด๊ธฐํ ๋ฐ ์ฃผ์
์ํ.
๋ณด๊ณ :
(์ถ๋ ฅ, ์ํ) ํ์์ ํํ, ์ฌ๊ธฐ์:
output: 2D Tensor์ Decoder_inputs์ ๋์ผํ ๊ธธ์ด์ ๋ชฉ๋ก
์์ฑ๋ ๋ชจ์์ ํฌํจํ๋ [batch_size x num_decoder_symbols]
์ถ๋ ฅ.
state: ์ต์ข
์๊ฐ ๋จ๊ณ์์ ๊ฐ ๋์ฝ๋ ์
์ ์ํ.
[batch_size x cell.state_size] ๋ชจ์์ 2D Tensor์
๋๋ค.
""
variable_scope.variable_scope(
๋ฒ์ ๋๋ "embedding_attention_seq2seq", dtype=dtype) ๋ฒ์๋ก:
dtype = ๋ฒ์.dtype
# ์ธ์ฝ๋.
encoder_cell = enc_cell
encoder_cell = core_rnn_cell.EmbeddingWrapper(
encoder_cell,
embedding_classes=num_encoder_symbols,
embedding_size=embedding_size)
encoder_outputs, encoder_state = rnn.static_rnn(
encoder_cell, encoder_inputs, dtype=dtype)
# First calculate a concatenation of encoder outputs to put attention on.
top_states = [
array_ops.reshape(e, [-1, 1, encoder_cell.output_size]) for e in encoder_outputs
]
attention_states = array_ops.concat(top_states, 1)
# Decoder.
output_size = None
if output_projection is None:
dec_cell = core_rnn_cell.OutputProjectionWrapper(dec_cell, num_decoder_symbols)
output_size = num_decoder_symbols
if isinstance(feed_previous, bool):
return embedding_attention_decoder(
decoder_inputs,
encoder_state,
attention_states,
dec_cell,
num_decoder_symbols,
embedding_size,
num_heads=num_heads,
output_size=output_size,
output_projection=output_projection,
feed_previous=feed_previous,
initial_state_attention=initial_state_attention)
# If feed_previous is a Tensor, we construct 2 graphs and use cond.
def decoder(feed_previous_bool):
reuse = None if feed_previous_bool else True
with variable_scope.variable_scope(
variable_scope.get_variable_scope(), reuse=reuse):
outputs, state = embedding_attention_decoder(
decoder_inputs,
encoder_state,
attention_states,
dec_cell,
num_decoder_symbols,
embedding_size,
num_heads=num_heads,
output_size=output_size,
output_projection=output_projection,
feed_previous=feed_previous_bool,
update_embedding_for_previous=False,
initial_state_attention=initial_state_attention)
state_list = [state]
if nest.is_sequence(state):
state_list = nest.flatten(state)
return outputs + state_list
outputs_and_state = control_flow_ops.cond(feed_previous,
lambda: decoder(True),
lambda: decoder(False))
outputs_len = len(decoder_inputs) # Outputs length same as decoder inputs.
state_list = outputs_and_state[outputs_len:]
state = state_list[0]
if nest.is_sequence(encoder_state):
state = nest.pack_sequence_as(
structure=encoder_state, flat_sequence=state_list)
return outputs_and_state[:outputs_len], state
```
@fabiofumarola ๊ธฐ๋ฅ ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. ์ ๋ง ๋์์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋๋ ๋ํ ํํ ๋ฆฌ์ผ์ด ๋ ์ด์ ์ฌ์ฉ๋์ง ์๋ ๊ฒ์ ๋ณด์์ต๋๋ค. ๋๋ ์ฌ์ ํ ๊ณต์ ํํ ๋ฆฌ์ผ ๋ฆด๋ฆฌ์ค๋ฅผ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ต๋๋ค. ์๋ก์ด API๋ฅผ ์ฌ์ฉํ ๊ฒ ๊ฐ์ต๋๋ค. ์ API์์ ์ฝ๋ฉ์ ์์ํ๊ธฐ ์ํด ์กฐํํ ์ ์๋ ์ฝ๋๊ฐ ์์ต๋๊น?
๋์์ ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. ๋ค์ ํ๋ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค :)
@syw2014 ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ จ๋์?
@w268wang ์ ์์ง ๋ค๋ฅธ ์๋ฃจ์ ์ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ง๋ง @Miopas์ ์๊ฒฌ์ ์๋ํด ๋ณผ ์ ์์ผ๋ฉฐ @fabiofumarola ์ ์๋ฃจ์ ์ ์๋ํ๊ณ ์์ต๋๋ค.
TypeError: embedding_attention_seq2seq() missing 1 required positional argument: 'dec_cell'
๋ผ๊ณ ์ ํ์์ต๋๋ค.
@fabiofumarola ๊ฐ ๊ฒ์ํ ์
๋ฐ์ดํธ๋ฅผ ์ฌ์ฉํ ํ. ๋์์ฃผ์๊ฒ ์ด์?
์, ๋ด๊ฐ ์ ์ํ ์
๋ฐ์ดํธ๋ฅผ ๋ณ๊ฒฝํด์ผ ํ๊ธฐ ๋๋ฌธ์
embedding_attention_seq2seq ํจ์. ์์ ์ ์์ค ํ์ผ๋ก ์ด๋ํ๋ฉด
tensorflow ๋ฆด๋ฆฌ์ค์์๋ ์ค์ค๋ก ๋ฉ์๋ ์ ์๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
2017๋ 7์ 2์ผ ์ผ์์ผ 18:15, sachinh35 [email protected] trote
TypeError:embding_attention_seq2seq() ๋๋ฝ 1์ด ํ์ํ๋ค๊ณ ํ์๋ฉ๋๋ค.
์์น ์ธ์: 'dec_cell'โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-312500996 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABepUEc3W8m5CVDQGnCLu4dcJVFwwLDZks5sJ8IOgaJpZM4MWl4f
.>
Gmail ๋ชจ๋ฐ์ผ์์ ์ ์ก๋จ
์, ๋๋ ๊ฐ์ ์ผ์ํ์ต๋๋ค. tensorflow ๋ฆด๋ฆฌ์ค์์ seq2seq.py ํ์ผ์ ๊ธฐ๋ฅ์ ๋ณ๊ฒฝํ์ต๋๋ค. ์ฌ์ ํ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ํจ์์ ๋ํ ์ธ์๊ฐ ํ๋ ๋ ์์ต๋๊น?
์, ์ด์ ์ฝ๋์์ rnn_cells์ ์ง์ ํด์ผ ํฉ๋๋ค. ์ธ์ฝ๋์ฉ
๋์ฝ๋์ ๋ํ ๋ ๋ค๋ฅธ.
2017๋ 7์ 2์ผ ์ผ์์ผ 20:54 fabio fumarola [email protected] ์ด ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
๋ค
2017๋ 7์ 2์ผ ์ผ์์ผ 18:50์ sachinh35 [email protected] ์์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
์, ๋๋ ๊ฐ์ ์ผ์ํ์ต๋๋ค. seq2seq.py ํ์ผ์ ๊ธฐ๋ฅ์ ๋ณ๊ฒฝํ์ต๋๋ค.
ํ ์ํ๋ก ๋ฆด๋ฆฌ์ค. ์ฌ์ ํ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ํ๋ ์๋์
๊ธฐ๋ฅ์ ๋ํ ๋ ๋ง์ ์ธ์?โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-312503106 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABepUOXTQC_mzLuhcwW0iZRVkLmmr8yIks5sJ8pugaJpZM4MWl4f
.>
Gmail ๋ชจ๋ฐ์ผ์์ ์ ์ก๋จ
๋๋ ์ด๊ฒ์ ์์ ํ ์๋ก์ด ๊ฒ์ ๋๋ค. ์ด๊ฒ์ ์์ฃผ ๊ธฐ๋ณธ์ ์ธ ์ง๋ฌธ์ผ ์ ์์ง๋ง ์ด ์ฝ๋์์ ๋์ฝ๋ ์ ๋ก ์ ๋ฌํ ์ธ์๋ฅผ ๋งํ ์ ์์ต๋๊น? ์์ฒด ๋ฐ์ดํฐ ์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ tensorflow ์์ต์์ ํ์๋ ๋๋ก seq2seq๋ฅผ ๊ฐ๋ฐํ๋ ค๊ณ ํฉ๋๋ค.
`
__future__์์ import absolute_import
__future__ ์์
๋ถ๋ฌธ์์
__future__์์ print_function ๊ฐ์ ธ์ค๊ธฐ
๋ฌด์์๋ก ๊ฐ์ ธ์ค๊ธฐ
numpy๋ฅผ np๋ก ๊ฐ์ ธ์ค๊ธฐ
from Six.moves import xrange # pylint: disable=redefined-builtin
ํ
์ํ๋ก๋ฅผ tf๋ก ๊ฐ์ ธ์ค๊ธฐ
import data_utils
ํด๋์ค Seq2SeqModel(๊ฐ์ฒด):
def __init__(์์ ,
์์ค_์ดํ_ํฌ๊ธฐ,
target_vocab_size,
์๋์ด,
ํฌ๊ธฐ,
num_layers,
max_gradient_norm,
๋ฐฐ์น ํฌ๊ธฐ,
ํ์ต ์๋,
learning_rate_decay_factor,
use_lstm=๊ฑฐ์ง,
num_samples=512,
forward_only=๊ฑฐ์ง,
dtype=tf.float32):
self.source_vocab_size = source_vocab_size
self.target_vocab_size = target_vocab_size
self.buckets = buckets
self.batch_size = batch_size
self.learning_rate = tf.Variable(
float(learning_rate), trainable=False, dtype=dtype)
self.learning_rate_decay_op = self.learning_rate.assign(
self.learning_rate * learning_rate_decay_factor)
self.global_step = tf.Variable(0, trainable=False)
output_projection = None
softmax_loss_function = None
if num_samples > 0 and num_samples < self.target_vocab_size:
w_t = tf.get_variable("proj_w", [self.target_vocab_size, size], dtype=dtype)
w = tf.transpose(w_t)
b = tf.get_variable("proj_b", [self.target_vocab_size], dtype=dtype)
output_projection = (w, b)
def sampled_loss(labels, inputs):
labels = tf.reshape(labels, [-1, 1])
local_w_t = tf.cast(w_t, tf.float32)
local_b = tf.cast(b, tf.float32)
local_inputs = tf.cast(inputs, tf.float32)
return tf.cast(
tf.nn.sampled_softmax_loss(local_w_t, local_b, local_inputs, labels,
num_samples, self.target_vocab_size),
dtype)
softmax_loss_function = sampled_loss
def single_cell():
return tf.nn.rnn_cell.GRUCell(size)
if use_lstm:
def single_cell():
return tf.nn.rnn_cell.BasicLSTMCell(size)
cell = single_cell()
if num_layers > 1:
cell = tf.nn.rnn_cell.MultiRNNCell([single_cell() for _ in range(num_layers)])
def seq2seq_f(encoder_inputs, decoder_inputs, do_decode):
return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
encoder_inputs,
decoder_inputs,
cell,
num_encoder_symbols=source_vocab_size,
num_decoder_symbols=target_vocab_size,
embedding_size=size,
output_projection=output_projection,
feed_previous=do_decode,
dtype=dtype)
self.encoder_inputs = []
self.decoder_inputs = []
self.target_weights = []
for i in xrange(buckets[-1][0]): # Last bucket is the biggest one.
self.encoder_inputs.append(tf.placeholder(tf.int32, shape=[None],
name="encoder{0}".format(i)))
for i in xrange(buckets[-1][1] + 1):
self.decoder_inputs.append(tf.placeholder(tf.int32, shape=[None],
name="decoder{0}".format(i)))
self.target_weights.append(tf.placeholder(dtype, shape=[None],
name="weight{0}".format(i)))
# Our targets are decoder inputs shifted by one.
targets = [self.decoder_inputs[i + 1]
for i in xrange(len(self.decoder_inputs) - 1)]
# Training outputs and losses.
if forward_only:
self.outputs, self.losses = tf.contrib.legacy_seq2seq.model_with_buckets(
self.encoder_inputs, self.decoder_inputs, targets,
self.target_weights, buckets, lambda x, y: seq2seq_f(x, y, True),
softmax_loss_function=softmax_loss_function)
# If we use output projection, we need to project outputs for decoding.
if output_projection is not None:
for b in xrange(len(buckets)):
self.outputs[b] = [
tf.matmul(output, output_projection[0]) + output_projection[1]
for output in self.outputs[b]
]
else:
self.outputs, self.losses = tf.contrib.legacy_seq2seq.model_with_buckets(
self.encoder_inputs, self.decoder_inputs, targets,
self.target_weights, buckets,
lambda x, y: seq2seq_f(x, y, False),
softmax_loss_function=softmax_loss_function)
# Gradients and SGD update operation for training the model.
params = tf.trainable_variables()
if not forward_only:
self.gradient_norms = []
self.updates = []
opt = tf.train.GradientDescentOptimizer(self.learning_rate)
for b in xrange(len(buckets)):
gradients = tf.gradients(self.losses[b], params)
clipped_gradients, norm = tf.clip_by_global_norm(gradients,
max_gradient_norm)
self.gradient_norms.append(norm)
self.updates.append(opt.apply_gradients(
zip(clipped_gradients, params), global_step=self.global_step))
self.saver = tf.train.Saver(tf.global_variables())
def ๋จ๊ณ(์์ฒด, ์ธ์
, ์ธ์ฝ๋_์
๋ ฅ, ๋์ฝ๋_์
๋ ฅ, ๋์_๊ฐ์ค์น,
๋ฒํท ID, forward_only):
# Check if the sizes match.
encoder_size, decoder_size = self.buckets[bucket_id]
if len(encoder_inputs) != encoder_size:
raise ValueError("Encoder length must be equal to the one in bucket,"
" %d != %d." % (len(encoder_inputs), encoder_size))
if len(decoder_inputs) != decoder_size:
raise ValueError("Decoder length must be equal to the one in bucket,"
" %d != %d." % (len(decoder_inputs), decoder_size))
if len(target_weights) != decoder_size:
raise ValueError("Weights length must be equal to the one in bucket,"
" %d != %d." % (len(target_weights), decoder_size))
# Input feed: encoder inputs, decoder inputs, target_weights, as provided.
input_feed = {}
for l in xrange(encoder_size):
input_feed[self.encoder_inputs[l].name] = encoder_inputs[l]
for l in xrange(decoder_size):
input_feed[self.decoder_inputs[l].name] = decoder_inputs[l]
input_feed[self.target_weights[l].name] = target_weights[l]
# Since our targets are decoder inputs shifted by one, we need one more.
last_target = self.decoder_inputs[decoder_size].name
input_feed[last_target] = np.zeros([self.batch_size], dtype=np.int32)
# Output feed: depends on whether we do a backward step or not.
if not forward_only:
output_feed = [self.updates[bucket_id], # Update Op that does SGD.
self.gradient_norms[bucket_id], # Gradient norm.
self.losses[bucket_id]] # Loss for this batch.
else:
output_feed = [self.losses[bucket_id]] # Loss for this batch.
for l in xrange(decoder_size): # Output logits.
output_feed.append(self.outputs[bucket_id][l])
outputs = session.run(output_feed, input_feed)
if not forward_only:
return outputs[1], outputs[2], None # Gradient norm, loss, no outputs.
else:
return None, outputs[0], outputs[1:] # No gradient norm, loss, outputs.
def get_batch(์์ , ๋ฐ์ดํฐ, ๋ฒํท ID):
encoder_size, decoder_size = self.buckets[bucket_id]
encoder_inputs, decoder_inputs = [], []
# Get a random batch of encoder and decoder inputs from data,
# pad them if needed, reverse encoder inputs and add GO to decoder.
for _ in xrange(self.batch_size):
encoder_input, decoder_input = random.choice(data[bucket_id])
# Encoder inputs are padded and then reversed.
encoder_pad = [data_utils.PAD_ID] * (encoder_size - len(encoder_input))
encoder_inputs.append(list(reversed(encoder_input + encoder_pad)))
# Decoder inputs get an extra "GO" symbol, and are padded then.
decoder_pad_size = decoder_size - len(decoder_input) - 1
decoder_inputs.append([data_utils.GO_ID] + decoder_input +
[data_utils.PAD_ID] * decoder_pad_size)
# Now we create batch-major vectors from the data selected above.
batch_encoder_inputs, batch_decoder_inputs, batch_weights = [], [], []
# Batch encoder inputs are just re-indexed encoder_inputs.
for length_idx in xrange(encoder_size):
batch_encoder_inputs.append(
np.array([encoder_inputs[batch_idx][length_idx]
for batch_idx in xrange(self.batch_size)], dtype=np.int32))
# Batch decoder inputs are re-indexed decoder_inputs, we create weights.
for length_idx in xrange(decoder_size):
batch_decoder_inputs.append(
np.array([decoder_inputs[batch_idx][length_idx]
for batch_idx in xrange(self.batch_size)], dtype=np.int32))
# Create target_weights to be 0 for targets that are padding.
batch_weight = np.ones(self.batch_size, dtype=np.float32)
for batch_idx in xrange(self.batch_size):
# We set weight to 0 if the corresponding target is a PAD symbol.
# The corresponding target is decoder_input shifted by 1 forward.
if length_idx < decoder_size - 1:
target = decoder_inputs[batch_idx][length_idx + 1]
if length_idx == decoder_size - 1 or target == data_utils.PAD_ID:
batch_weight[batch_idx] = 0.0
batch_weights.append(batch_weight)
return batch_encoder_inputs, batch_decoder_inputs, batch_weights`
์ด๊ฒ์ ์คํ ์ค๋ฒํ๋ก์ ๋ํ ์ข์ ์ง๋ฌธ์ ๋๋ค.
2017๋ 7์ 3์ผ ์ค์ 8์ 46๋ถ์ "sachinh35" [email protected] ์ด ์์ฑํ์ต๋๋ค.
๋๋ ์ด๊ฒ์ ์์ ํ ์๋ก์ด ๊ฒ์ ๋๋ค. ์ด์ฉ๋ฉด ์ด๊ฒ์ ์์ฃผ ๊ธฐ๋ณธ์ ์ธ ์ง๋ฌธ์ผ ์๋ ์์ง๋ง
์ด ์ฝ๋์์ ๋์ฝ๋ ์ ๋ก ์ ๋ฌํ ์ธ์๋ฅผ ์๋ ค์ฃผ์ธ์. ๊ทธ๋์
์์ ์ ์ฌ์ฉํ์ฌ tensorflow ์์ต์์ ํ์๋ ๋๋ก seq2seq๋ฅผ ๊ฐ๋ฐํ๋ ค๊ณ ์๋ํฉ๋๋ค.
๋ฐ์ดํฐ ์ธํธ.
`# Copyright 2015 TensorFlow ์์ฑ์. ํ๊ถ ์์ .
Apache ๋ผ์ด์ ์ค ๋ฒ์ 2.0("๋ผ์ด์ ์ค")์ ๋ฐ๋ผ ๋ผ์ด์ ์ค๊ฐ ๋ถ์ฌ๋ฉ๋๋ค. ๋น์ ์ ํ ์์๋ค
๋ผ์ด์ ์ค๋ฅผ ์ค์ํ์ง ์๋ ํ ์ด ํ์ผ์ ์ฌ์ฉํ์ง ๋ง์ญ์์ค. ๋น์ ์ ์ป์ ์ ์์ต๋๋ค
http://www.apache.org/licenses/LICENSE-2.0 ์ ์๋ ๋ผ์ด์ ์ค ์ฌ๋ณธ
๊ด๋ จ ๋ฒ๋ฅ ์์ ์๊ตฌํ๊ฑฐ๋ ์๋ฉด์ผ๋ก ๋์ํ ์ํํธ์จ์ด ๋ฐฐํฌ
๋ผ์ด์ผ์ค์ ๋ฐ๋ผ ๋ณด์ฆ ์์ด "์๋ ๊ทธ๋๋ก" ๋ฐฐํฌ๋ฉ๋๋ค.
๋๋ ๋ช ์์ ์ด๋ ๋ฌต์์ ์ด๋ ๋ชจ๋ ์ข ๋ฅ์ ์กฐ๊ฑด. ๋ผ์ด์ ์ค ์ฐธ์กฐ
์๋์ ๊ถํ ๋ฐ ์ ํ ์ฌํญ์ ๊ด๋ฆฌํ๋ ํน์ ์ธ์ดํนํ. ==================================================== ===========
"""์ฃผ์ ๋ฉ์ปค๋์ฆ์ด ์๋ ์ํ์ค ๋ ์ํ์ค ๋ชจ๋ธ์ ๋๋ค."""
ํฅํ ๊ฐ์ ธ์ค๊ธฐ absolute_import์์
๋ฏธ๋ ์์ ๋ถ์์์
ํฅํ ๊ฐ์ ธ์ค๊ธฐ์์ print_function๋ฌด์์๋ก ๊ฐ์ ธ์ค๊ธฐ
numpy๋ฅผ np๋ก ๊ฐ์ ธ์ค๊ธฐ
from Six.moves import xrange # pylint: disable=redefined-builtin
ํ ์ํ๋ก๋ฅผ tf๋ก ๊ฐ์ ธ์ค๊ธฐimport data_utils
ํด๋์ค Seq2SeqModel(๊ฐ์ฒด):
"""์ฃผ์๊ฐ ์๊ณ ์ฌ๋ฌ ๋ฒํท์ ๋ํ ์ํ์ค ๋ ์ํ์ค ๋ชจ๋ธ์ ๋๋ค.์ด ํด๋์ค๋ ์ธ์ฝ๋๋ก ๋ค์ธต ์ํ ์ ๊ฒฝ๋ง์ ๊ตฌํํฉ๋๋ค.
๋ฐ ์ฃผ์ ๊ธฐ๋ฐ ๋์ฝ๋. ์ ์ค๋ช ๋ ๋ชจ๋ธ๊ณผ ๋์ผํฉ๋๋ค.
์ด ๋ฌธ์: http://arxiv.org/abs/1412.7449 - ๊ฑฐ๊ธฐ์์ ์ฐพ์๋ณด์ญ์์ค.
์ธ๋ถ,
๋๋ ์์ ํ ๋ชจ๋ธ ๊ตฌํ์ ์ํด seq2seq ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฃ์ต๋๋ค.
์ด ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ฉด LSTM ์ ์ธ์ GRU ์ ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
ํฐ ์ถ๋ ฅ ์ดํ ํฌ๊ธฐ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด ์ํ๋ง๋ softmax. ๋จ์ธต
์ด ๋ชจ๋ธ์ ๋ฒ์ ์ด์ง๋ง ์๋ฐฉํฅ ์ธ์ฝ๋๊ฐ ์๋
http://arxiv.org/abs/1409.0473
์ํ๋ง๋ softmax๋ ๋ค์ ๋ฌธ์์ ์น์ 3์ ์ค๋ช ๋์ด ์์ต๋๋ค.
http://arxiv.org/abs/1412.2007
""def ์ด๊ธฐํ (์์ ,
์์ค_์ดํ_ํฌ๊ธฐ,
target_vocab_size,
์๋์ด,
ํฌ๊ธฐ,
num_layers,
max_gradient_norm,
๋ฐฐ์น ํฌ๊ธฐ,
ํ์ต ์๋,
learning_rate_decay_factor,
use_lstm=๊ฑฐ์ง,
num_samples=512,
forward_only=๊ฑฐ์ง,
dtype=tf.float32):
"""๋ชจ๋ธ์ ๋ง๋ญ๋๋ค.์ธ์:
source_vocab_size: ์์ค ์ดํ์ ํฌ๊ธฐ.
target_vocab_size: ๋์ ์ดํ์ ํฌ๊ธฐ.
๋ฒํท: ์(I, O)์ ๋ชฉ๋ก, ์ฌ๊ธฐ์ I์ ์ต๋ ์ ๋ ฅ ๊ธธ์ด๋ฅผ ์ง์ ํฉ๋๋ค.
ํด๋น ๋ฒํท์์ ์ฒ๋ฆฌ๋๊ณ O๋ ์ต๋ ์ถ๋ ฅ์ ์ง์ ํฉ๋๋ค.
๊ธธ์ด. I ๋๋ ์ถ๋ ฅ๋ณด๋ค ์ ๋ ฅ์ด ๊ธด ํ๋ จ ์ธ์คํด์ค
O๋ณด๋ค ๊ธธ๋ฉด ๋ค์ ๋ฒํท์ผ๋ก ํธ์๋๊ณ ๊ทธ์ ๋ฐ๋ผ ์ฑ์์ง๋๋ค.
๋ชฉ๋ก์ด ์ ๋ ฌ๋์ด ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค(์: [(2, 4), (8, 16)].
ํฌ๊ธฐ: ๋ชจ๋ธ์ ๊ฐ ๋ ์ด์ด์ ์๋ ๋จ์ ์์ ๋๋ค.
num_layers: ๋ชจ๋ธ์ ๋ ์ด์ด ์.
max_gradient_norm: ๊ทธ๋ผ๋์ธํธ๊ฐ ์ต๋๋ก ์ด ํ์ค์ผ๋ก ์๋ฆฝ๋๋ค.
batch_size: ํ๋ จ ์ค์ ์ฌ์ฉ๋ ๋ฐฐ์น์ ํฌ๊ธฐ.
๋ชจ๋ธ ๊ตฌ์ฑ์ batch_size์ ๋ฌด๊ดํ๋ฏ๋ก
์๋ฅผ ๋ค์ด ๋์ฝ๋ฉ์ ์ํด ์ด๊ฒ์ด ํธ๋ฆฌํ ๊ฒฝ์ฐ ์ด๊ธฐํ ํ์ ๋ณ๊ฒฝ๋ฉ๋๋ค.
learning_rate: ์์ํ ํ์ต๋ฅ ์ ๋๋ค.
learning_rate_decay_factor: ํ์ํ ๋ ์ด๋งํผ ํ์ต๋ฅ ์ ๊ฐ์์ํต๋๋ค.
use_lstm: true์ด๋ฉด GRU ์ ๋์ LSTM ์ ์ ์ฌ์ฉํฉ๋๋ค.
num_samples: ์ํ๋ง๋ softmax์ ์ํ ์์ ๋๋ค.
forward_only: ์ค์ ๋ ๊ฒฝ์ฐ ๋ชจ๋ธ์์ ์ญ๋ฐฉํฅ ํจ์ค๋ฅผ ๊ตฌ์ฑํ์ง ์์ต๋๋ค.
dtype: ๋ด๋ถ ๋ณ์๋ฅผ ์ ์ฅํ๋ ๋ฐ ์ฌ์ฉํ ๋ฐ์ดํฐ ์ ํ์ ๋๋ค.
""
self.source_vocab_size = source_vocab_size
self.target_vocab_size = target_vocab_size
self.buckets = ๋ฒํท
self.batch_size = ๋ฐฐ์น_ํฌ๊ธฐ
self.learning_rate = tf.Variable(
float(learning_rate), ํ๋ จ ๊ฐ๋ฅ=๊ฑฐ์ง, dtype=dtype)
self.learning_rate_decay_op = self.learning_rate.assign(
self.learning_rate * learning_rate_decay_factor)
self.global_step = tf.Variable(0, ํ๋ จ ๊ฐ๋ฅ=๊ฑฐ์ง)์ํ๋ง๋ softmax๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ถ๋ ฅ ํฌ์์ด ํ์ํฉ๋๋ค.
output_projection = ์์
softmax_loss_function = ์์์ํ๋ง๋ ์ํํธ๋งฅ์ค๋ ์ดํ ํฌ๊ธฐ๋ณด๋ค ์ ์ ์ํ๋ง์ ํ๋ ๊ฒฝ์ฐ์๋ง ์๋ฏธ๊ฐ ์์ต๋๋ค.
num_samples > 0 ๋ฐ num_samples < self.target_vocab_size:
w_t = tf.get_variable("proj_w", [self.target_vocab_size, ํฌ๊ธฐ], dtype=dtype)
w = tf.transpose(w_t)
b = tf.get_variable("proj_b", [self.target_vocab_size], dtype=dtype)
output_projection = (w, b)def sampled_loss(๋ ์ด๋ธ, ์ ๋ ฅ):
๋ ์ด๋ธ = tf.reshape(๋ ์ด๋ธ, [-1, 1])
# 32๋นํธ ๋ถ๋ ์์์ ์ ์ฌ์ฉํ์ฌ sampled_softmax_loss๋ฅผ ๊ณ์ฐํด์ผ ํฉ๋๋ค.
# ์์น์ ๋ถ์์ ์ฑ์ ํผํ์ญ์์ค.
local_w_t = tf.cast(w_t, tf.float32)
local_b = tf.cast(b, tf.float32)
local_inputs = tf.cast(์ ๋ ฅ, tf.float32)
๋ฐํ tf.cast(
tf.nn.sampled_softmax_loss(local_w_t, local_b, local_inputs, ๋ ์ด๋ธ,
num_samples, self.target_vocab_size),
dtype)
softmax_loss_function = ์ํ๋ง๋ ์์คRNN์ ์ํ ๋ด๋ถ ๋ค์ธต ์ ์ ๋ง๋ญ๋๋ค.
def single_cell():
๋ฐํ tf.nn.rnn_cell.GRUCell(ํฌ๊ธฐ)
use_lstm์ธ ๊ฒฝ์ฐ:
def single_cell():
๋ฐํ tf.nn.rnn_cell.BasicLSTMCell(ํฌ๊ธฐ)
์ = single_cell()
num_layers > 1์ธ ๊ฒฝ์ฐ:
cell = tf.nn.rnn_cell.MultiRNNCell([single_cell() for _ in range(num_layers)])seq2seq ํจ์: ์ ๋ ฅ๊ณผ ์ฃผ์๋ฅผ ์ํด ์๋ฒ ๋ฉ์ ์ฌ์ฉํฉ๋๋ค.
def seq2seq_f(encoder_inputs, ๋์ฝ๋_์ ๋ ฅ, do_decode):
๋ฐํ tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
์ธ์ฝ๋_์ ๋ ฅ,
๋์ฝ๋_์ ๋ ฅ,
์ ,
num_encoder_symbols=source_vocab_size,
num_decoder_symbols=target_vocab_size,
embedding_size=ํฌ๊ธฐ,
output_projection=์ถ๋ ฅ_ํฌ์,
feed_previous=do_decode,
dtype=dtype)์ ๋ ฅ์ ๋ํ ํผ๋.
self.encoder_inputs = []
self.decoder_inputs = []
self.target_weights = []
for i in xrange(buckets[-1][0]): # ๋ง์ง๋ง ๋ฒํท์ด ๊ฐ์ฅ ํฐ ๋ฒํท์ ๋๋ค.
self.encoder_inputs.append(tf.placeholder(tf.int32, ๋ชจ์=[์์],
์ด๋ฆ="์ธ์ฝ๋{0}".format(i)))
xrange(buckets[-1][1] + 1)์ i์ ๋ํด:
self.decoder_inputs.append(tf.placeholder(tf.int32, ๋ชจ์=[์์],
์ด๋ฆ="๋์ฝ๋{0}".format(i)))
self.target_weights.append(tf.placeholder(dtype, shape=[์์],
์ด๋ฆ="๋ฌด๊ฒ{0}".ํ์(i)))์ฐ๋ฆฌ์ ๋ชฉํ๋ 1๋งํผ ์ด๋๋ ๋์ฝ๋ ์ ๋ ฅ์ ๋๋ค.
๋์ = [self.decoder_inputs[i + 1]
for i in xrange(len(self.decoder_inputs) - 1)]ํ๋ จ ๊ฒฐ๊ณผ ๋ฐ ์์ค.
forward_only์ธ ๊ฒฝ์ฐ:
self.outputs, self.losses = tf.contrib.legacy_seq2seq.model_with_buckets(
self.encoder_inputs, self.decoder_inputs, ๋์,
self.target_weights, ๋ฒํท, ๋๋ค x, y: seq2seq_f(x, y, True),
softmax_loss_function=softmax_loss_function)
# ์ถ๋ ฅ ํฌ์์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋์ฝ๋ฉ์ ์ํด ์ถ๋ ฅ์ ํฌ์ํด์ผ ํฉ๋๋ค.
output_projection์ด None์ด ์๋ ๊ฒฝ์ฐ:
xrange(len(buckets))์ b์ ๋ํด:
self.outputs[b] = [
tf.matmul(์ถ๋ ฅ, output_projection[0]) + output_projection[1]
self.outputs[b]์ ์ถ๋ ฅ์ฉ
]
๋ ๋ค๋ฅธ:
self.outputs, self.losses = tf.contrib.legacy_seq2seq.model_with_buckets(
self.encoder_inputs, self.decoder_inputs, ๋์,
self.target_weights, ๋ฒํท,
๋๋ค x, y: seq2seq_f(x, y, False),
softmax_loss_function=softmax_loss_function)๋ชจ๋ธ ํ๋ จ์ ์ํ ๊ทธ๋ผ๋์ธํธ ๋ฐ SGD ์ ๋ฐ์ดํธ ์์ .
๋งค๊ฐ๋ณ์ = tf.trainable_variables()
forward_only๊ฐ ์๋ ๊ฒฝ์ฐ:
self.gradient_norms = []
self.updates = []
opt = tf.train.GradientDescentOptimizer(self.learning_rate)
xrange(len(buckets))์ b์ ๋ํด:
๊ทธ๋ผ๋์ธํธ = tf.gradients(self.losses[b], params)
clipped_gradients, norm = tf.clip_by_global_norm(๊ทธ๋ผ๋์ธํธ,
max_gradient_norm)
self.gradient_norms.append(ํ์ค)
self.updates.append(opt.apply_gradients(
zip(clipping_gradients, params), global_step=self.global_step))self.saver = tf.train.Saver(tf.global_variables())
def ๋จ๊ณ(์์ฒด, ์ธ์ , ์ธ์ฝ๋_์ ๋ ฅ, ๋์ฝ๋_์ ๋ ฅ, ๋์_๊ฐ์ค์น,
๋ฒํท ID, forward_only):
"""์ฃผ์ด์ง ์ ๋ ฅ์ ๊ณต๊ธํ๋ ๋ชจ๋ธ์ ๋จ๊ณ๋ฅผ ์คํํฉ๋๋ค.์ธ์:
session: ์ฌ์ฉํ tensorflow ์ธ์ ์ ๋๋ค.
์ธ์ฝ๋_์ ๋ ฅ: ์ธ์ฝ๋ ์ ๋ ฅ์ผ๋ก ๊ณต๊ธํ numpy int ๋ฒกํฐ ๋ชฉ๋ก์ ๋๋ค.
๋์ฝ๋_์ ๋ ฅ: ๋์ฝ๋ ์ ๋ ฅ์ผ๋ก ๊ณต๊ธํ numpy int ๋ฒกํฐ ๋ชฉ๋ก์ ๋๋ค.
target_weights: ๋์ ๊ฐ์ค์น๋ก ์ ๊ณตํ numpy float ๋ฒกํฐ ๋ชฉ๋ก์ ๋๋ค.
bucket_id: ์ฌ์ฉํ ๋ชจ๋ธ์ ๋ฒํท์ ๋๋ค.
forward_only: ๋ค๋ก ๋จ๊ณ๋ฅผ ์ํํ ์ง ์๋๋ฉด ์์ผ๋ก๋ง ์ํํ ์ง ์ฌ๋ถ.๋ณด๊ณ :
๊ทธ๋๋์ธํธ ๋์ผ๋ก ๊ตฌ์ฑ๋ ํธ๋ฆฌํ(๋๋ ๋ค๋ก ํ์ง ์์๋ค๋ฉด None),
ํ๊ท ๋นํน๋ ๋ฐ ์ถ๋ ฅ.๋ ์ด์ฆ:
ValueError: ์ธ์ฝ๋_์ ๋ ฅ, ๋์ฝ๋_์ ๋ ฅ ๋๋
target_weights๊ฐ ์ง์ ๋ bucket_id์ ๋ฒํท ํฌ๊ธฐ์ ์ผ์นํ์ง ์์ต๋๋ค.
""ํฌ๊ธฐ๊ฐ ์ผ์นํ๋์ง ํ์ธํ์ญ์์ค.
์ธ์ฝ๋_ํฌ๊ธฐ, ๋์ฝ๋_ํฌ๊ธฐ โโ= self.buckets[bucket_id]
len(encoder_inputs) != ์ธ์ฝ๋_ํฌ๊ธฐ์ธ ๊ฒฝ์ฐ:
raise ValueError("์ธ์ฝ๋ ๊ธธ์ด๋ ๋ฒํท์ ๊ธธ์ด์ ๊ฐ์์ผ ํฉ๋๋ค."
" %d != %d." % (len(encoder_inputs), ์ธ์ฝ๋_ํฌ๊ธฐ))
len(decoder_inputs) != ๋์ฝ๋ ํฌ๊ธฐ์ธ ๊ฒฝ์ฐ:
raise ValueError("๋์ฝ๋ ๊ธธ์ด๋ ๋ฒํท์ ๊ธธ์ด์ ๊ฐ์์ผ ํฉ๋๋ค."
" %d != %d." % (len(decoder_inputs), ๋์ฝ๋_ํฌ๊ธฐ))
len(target_weights) != ๋์ฝ๋ ํฌ๊ธฐ:
raise ValueError("๋ฌด๊ฒ ๊ธธ์ด๋ ๋ฒํท์ ๊ธธ์ด์ ๊ฐ์์ผ ํฉ๋๋ค."
" %d != %d." % (len(target_weights), ๋์ฝ๋_ํฌ๊ธฐ))์ ๋ ฅ ํผ๋: ์ธ์ฝ๋ ์ ๋ ฅ, ๋์ฝ๋ ์ ๋ ฅ, ์ ๊ณต๋๋ target_weights.
input_feed = {}
xrange(encoder_size)์ l:
input_feed[self.encoder_inputs[l].name] = ์ธ์ฝ๋_์ ๋ ฅ[l]
xrange(decoder_size)์ l:
input_feed[self.decoder_inputs[l].name] = ๋์ฝ๋_์ ๋ ฅ[l]
input_feed[self.target_weights[l].name] = target_weights[l]์ฐ๋ฆฌ์ ๋ชฉํ๋ 1๋งํผ ์ด๋๋ ๋์ฝ๋ ์ ๋ ฅ์ด๋ฏ๋ก ํ๋ ๋ ํ์ํฉ๋๋ค.
last_target = self.decoder_inputs[decoder_size].name
input_feed[last_target] = np.zeros([self.batch_size], dtype=np.int32)์ถ๋ ฅ ํผ๋: ํ์ง ๋จ๊ณ๋ฅผ ์ํํ๋์ง ์ฌ๋ถ์ ๋ฐ๋ผ ๋ค๋ฆ ๋๋ค.
forward_only๊ฐ ์๋ ๊ฒฝ์ฐ:
output_feed = [self.updates[bucket_id], # SGD๋ฅผ ์ํํ๋ ์ ๋ฐ์ดํธ ์์ .
self.gradient_norms[bucket_id], # ๊ธฐ์ธ๊ธฐ ๋ ธ๋ฆ.
self.losses[bucket_id]] # ์ด ๋ฐฐ์น์ ์์ค์ ๋๋ค.
๋ ๋ค๋ฅธ:
output_feed = [self.losses[bucket_id]] # ์ด ๋ฐฐ์น์ ์์ค์ ๋๋ค.
for l in xrange(decoder_size): # ์ถ๋ ฅ ๋ก๊ทธ.
output_feed.append(self.outputs[bucket_id][l])์ถ๋ ฅ = session.run(์ถ๋ ฅ_ํผ๋, ์ ๋ ฅ_ํผ๋)
forward_only๊ฐ ์๋ ๊ฒฝ์ฐ:
return output[1], output[2], None # ๊ธฐ์ธ๊ธฐ ๋ ธ๋ฆ, ์์ค, ์ถ๋ ฅ ์์.
๋ ๋ค๋ฅธ:
return None, output[0], output[1:] # ๊ธฐ์ธ๊ธฐ ๋ ธ๋ฆ, ์์ค, ์ถ๋ ฅ์ด ์์ต๋๋ค.def get_batch(์์ , ๋ฐ์ดํฐ, ๋ฒํท ID):
"""์ง์ ๋ ๋ฒํท์์ ๋ฐ์ดํฐ์ ๋ฌด์์ ๋ฐฐ์น๋ฅผ ๊ฐ์ ธ์ค๊ณ ๋จ๊ณ๋ฅผ ์ค๋นํ์ญ์์ค.๋จ๊ณ(..)์์ ๋ฐ์ดํฐ๋ฅผ ๊ณต๊ธํ๋ ค๋ฉด ์ผ๊ด ์ฒ๋ฆฌ ์ค์ฌ ๋ฒกํฐ ๋ชฉ๋ก์ด์ด์ผ ํ์ง๋ง
์ฌ๊ธฐ์ ์๋ ๋ฐ์ดํฐ๋ ๋จ์ผ ๊ธธ์ด ์ฃผ์ ์ฌ๋ก๋ฅผ ํฌํจํฉ๋๋ค. ๊ทธ๋์ ์ด๊ฒ์ ์ฃผ์ ๋ ผ๋ฆฌ๋
๊ธฐ๋ฅ์ ๋ฐ์ดํฐ ์ผ์ด์ค๋ฅผ ํผ๋์ ์ ํฉํ ํ์์ผ๋ก ๋ค์ ์ธ๋ฑ์ฑํ๋ ๊ฒ์ ๋๋ค.์ธ์:
data: ๊ฐ ์์๊ฐ ํฌํจํ๋ len(self.buckets) ํฌ๊ธฐ์ ํํ
๋ฐฐ์น๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉํ๋ ์ ๋ ฅ ๋ฐ ์ถ๋ ฅ ๋ฐ์ดํฐ ์์ ๋ชฉ๋ก์ ๋๋ค.
bucket_id: ๋ฐฐ์น๋ฅผ ๊ฐ์ ธ์ฌ ๋ฒํท์ ์ ์์ ๋๋ค.๋ณด๊ณ :
ํธ๋ฆฌํ(encoder_inputs, decoder_inputs, target_weights)
๋์ค์ step(...)์ ํธ์ถํ๊ธฐ์ ์ ์ ํ ํ์์ ๊ฐ์ง ๊ตฌ์ฑ๋ ๋ฐฐ์น์ ๋๋ค.
""
์ธ์ฝ๋_ํฌ๊ธฐ, ๋์ฝ๋_ํฌ๊ธฐ โโ= self.buckets[bucket_id]
์ธ์ฝ๋_์ ๋ ฅ, ๋์ฝ๋_์ ๋ ฅ = [], []๋ฐ์ดํฐ์์ ์ธ์ฝ๋ ๋ฐ ๋์ฝ๋ ์ ๋ ฅ์ ๋ฌด์์ ๋ฐฐ์น๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
ํ์ํ ๊ฒฝ์ฐ ํจ๋๋ฅผ ์ฑ์ฐ๊ณ ์ธ์ฝ๋ ์ ๋ ฅ์ ์ญ์ ์ํค๊ณ ๋์ฝ๋์ GO๋ฅผ ์ถ๊ฐํฉ๋๋ค.
xrange(self.batch_size)์ _์ ๋ํด:
์ธ์ฝ๋_์ ๋ ฅ, ๋์ฝ๋_์ ๋ ฅ = random.choice(๋ฐ์ดํฐ[๋ฒํท_ID])# ์ธ์ฝ๋ ์ ๋ ฅ์ ํจ๋ฉ๋ ๋ค์ ๋ฐ์ ๋ฉ๋๋ค.
์ธ์ฝ๋_ํจ๋ = [data_utils.PAD_ID] * (encoder_size - len(encoder_input))
encoder_inputs.append(list(reversed(encoder_input + encoder_pad)))# ๋์ฝ๋ ์ ๋ ฅ์ ์ถ๊ฐ "GO" ๊ธฐํธ๋ฅผ ์ป๊ณ ํจ๋ฉ๋ฉ๋๋ค.
๋์ฝ๋_ํจ๋_ํฌ๊ธฐ = ๋์ฝ๋_ํฌ๊ธฐ โโ- len(decoder_input) - 1
Decoder_inputs.append([data_utils.GO_ID] + ๋์ฝ๋_์ ๋ ฅ +
[data_utils.PAD_ID] * ๋์ฝ๋_ํจ๋_ํฌ๊ธฐ)์ด์ ์์์ ์ ํํ ๋ฐ์ดํฐ์์ ๋ฐฐ์น ์ฃผ์ ๋ฒกํฐ๋ฅผ ์์ฑํฉ๋๋ค.
batch_encoder_inputs, batch_decoder_inputs, batch_weights = [], [], []
๋ฐฐ์น ์ธ์ฝ๋ ์ ๋ ฅ์ ๋ค์ ์ธ๋ฑ์ฑ๋ ์ธ์ฝ๋_์ ๋ ฅ์ ๋๋ค.
xrange(encoder_size)์ length_idx:
batch_encoder_inputs.append(
np.array([์ธ์ฝ๋_์ ๋ ฅ[๋ฐฐ์น_idx][๊ธธ์ด_idx]
xrange(self.batch_size)]์ batch_idx์ฉ], dtype=np.int32))๋ฐฐ์น ๋์ฝ๋ ์ ๋ ฅ์ ๋ค์ ์ธ๋ฑ์ฑ๋ ๋์ฝ๋_์ ๋ ฅ์ด๋ฉฐ ๊ฐ์ค์น๋ฅผ ์์ฑํฉ๋๋ค.
xrange(decoder_size)์ length_idx:
batch_decoder_inputs.append(
np.array([๋์ฝ๋_์ ๋ ฅ[๋ฐฐ์น_idx][๊ธธ์ด_idx]
xrange(self.batch_size)]์ batch_idx์ฉ], dtype=np.int32))# ํจ๋ฉ ๋์์ ๋ํด target_weights๋ฅผ 0์ผ๋ก ๋ง๋ญ๋๋ค.
batch_weight = np.ones(self.batch_size, dtype=np.float32)
xrange(self.batch_size)์ batch_idx:
# ํด๋น target์ด PAD symbol์ด๋ฉด weight๋ฅผ 0์ผ๋ก ์ค์ ํ๋ค.
# ํด๋น ๋์์ 1 ์์ผ๋ก ์ด๋ํ ๋์ฝ๋_์ ๋ ฅ์ ๋๋ค.
length_idx < ๋์ฝ๋ ํฌ๊ธฐ - 1์ธ ๊ฒฝ์ฐ:
๋์ = ๋์ฝ๋_์ ๋ ฅ[๋ฐฐ์น_idx][๊ธธ์ด_idx + 1]
length_idx == ๋์ฝ๋_ํฌ๊ธฐ โโ- 1 ๋๋ ๋์ == data_utils.PAD_ID์ธ ๊ฒฝ์ฐ:
๋ฐฐ์น ๋ฌด๊ฒ[๋ฐฐ์น_idx] = 0.0
batch_weights.append(batch_weight)
๋ฐํ batch_encoder_inputs, batch_decoder_inputs, batch_weights`โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-312679587 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim0l5UMHHtbL1sz7meXserV8NVS7cks5sKQzXgaJpZM4MWl4f
.
๊ด์ฐฎ์! ๊ทธ๋๋ ๊ณ ๋ง์! :)
@ebrevdo ์ API๋ฅผ ์ฌ์ฉํ๋ seq2seq์ ์ ํํ ๋ฆฌ์ผ์ด ์ธ์ ๋์ฌ์ง์ ๋ํ ์
๋ฐ์ดํธ๊ฐ ์์ต๋๊น?
๊ฐ์ฌํฉ๋๋ค. ๋๋ผ์ด ์ํ!.
์, ์๋ก์ด ํํ ๋ฆฌ์ผ์ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ต๋๋ค... ์กฐ๋ง๊ฐ ์ถ์๋ ์์ ์ธ์ง ์๊ณ ์ถ์ต๋๋ค.. @ebrevdo
์ปค๋ ํ ์คํธ์์ ์ฝ๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ๊ธฐ์กด seq2seq๋ก ๋น ๊ฒ์์ ๊ฐ์กฐํ๋ ค๊ณ ์๋ํ์ง๋ง ๋์ ์ ์ด์์ต๋๋ค...
์ด๋ฒ์ฃผ๊ฐ ๊ธฐ๋ค๋ ค์ง๋๋ค!
2017๋ 7์ 3์ผ ์ค์ 10์ 16๋ถ์ "prashantserai" [email protected] ์ด ์์ฑํ์ต๋๋ค.
๋ค, ์๋ก์ด ํํ ๋ฆฌ์ผ์ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ต๋๋ค...
์กฐ๋ง๊ฐ ์ถ์ ์์ .. @ebrevdo
https://github.com/ebrevdo์ปค๋ ํ ์คํธ์์ ์ฝ๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ๋ค์์ผ๋ก ๋น ๊ฒ์์ ๊ฐ์กฐํ๋ ค๊ณ ํ์ต๋๋ค.
๋ ๊ฑฐ์ seq2seq์ด์ง๋ง ๋์ ์ ์ธ ๊ฒ์ฒ๋ผ ๋ณด์์ต๋๋ค ...โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-312697274 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtim45-HTuQrIRDhphqqHjqkKOKTe53ks5sKSHYgaJpZM4MWl4f
.
์๋ ํ์ธ์ ์ฌ๋ฌ๋ถ,
์ด ๋ฌธ์ ์ ๋ํ ์ ๋ฐ์ดํธ๋ Mac os x์ฉ tensorflow 1.1-gpu์์๋ ๋์ผํ๊ฒ ๋ฐ์ํฉ๋๋ค.
@tshi1983
์ฐ๋ถํฌ์ฉ tensorflow 1.1-gpu์์๋ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
tf 1.2๋ก ์
๊ทธ๋ ์ด๋ํฉ๋๋ค. ์ฌ์ ํ ์๋ํ์ง ์์ต๋๋ค.
๊ทธ๋ฐ ๋ค์ ํ์ผ์์ embedding_attention_seq2seq ํจ์๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py
์์์ ์ ์ํ @fabiofumarola ๋ก.
์ด์ ํ๋ จ์ ์์ํฉ๋๋ค. ์์ง ๋์ฝ๋ฉ์ ํ
์คํธํ์ง ์์์ต๋๋ค.
์ ์ ์์ ์ฝ๋๋ฅผ seq2seq_f๋ก ์ด๋ํฉ๋๋ค.
def seq2seq_f(encoder_inputs, decoder_inputs, do_decode):
def single_cell():
return tf.contrib.rnn.GRUCell(size)
if use_lstm:
def single_cell():
return tf.contrib.rnn.BasicLSTMCell(size)
cell = single_cell()
if num_layers > 1:
cell = tf.contrib.rnn.MultiRNNCell([single_cell() for _ in range(num_layers)])
return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
...
)
๊ทธ๋ฐ ๋ค์ "python translate.py --data_dir data/ --train_dir checkpoint/ --size=256 --num_layers=2 --steps_per_checkpoint=50"์ด ์๋ํ ์ ์์ต๋๋ค.
@huxuanlai ์๋ํฉ๋๋ค! ์ ์ด๋ ์ง๊ธ์ ํ๋ จ ์ค์ด์ผ, thx!
@huxuanlai ์ ์๊ฒ๋ ํจ๊ณผ์ ์ ๋๋ค.
๋์ผํ AttributeError: 'NoneType' object has no attribute 'update'
๋ฅผ ๋ฐ๊ณ ์์ง๋ง tf.contrib.legacy_seq2seq.model_with_buckets
์
๋๋ค. ์ฐ๋ถํฌ 16.04 lts์์ tf 1.2.1(GPU)์ ์คํ ์ค์
๋๋ค.
์ด๊ฒ์ ๋ฒํท์ด 1๊ฐ ์ด์์ธ ๊ฒฝ์ฐ์๋ง ๋ฐ์ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ ์ฒด ์ญ์ถ์ :
Traceback (most recent call last):
File "chatbot.py", line 262, in <module>
main()
File "chatbot.py", line 257, in main
train()
File "chatbot.py", line 138, in train
model.build_graph()
File "/home/jkarimi91/Projects/cs20/code/hw/a3/model.py", line 134, in build_graph
self._create_loss()
File "/home/jkarimi91/Projects/cs20/code/hw/a3/model.py", line 102, in _create_loss
softmax_loss_function=self.softmax_loss_function)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1206, in model_with_buckets
decoder_inputs[:bucket[1]])
File "/home/jkarimi91/Projects/cs20/code/hw/a3/model.py", line 101, in <lambda>
lambda x, y: _seq2seq_f(x, y, False),
File "/home/jkarimi91/Projects/cs20/code/hw/a3/model.py", line 76, in _seq2seq_f
feed_previous=do_decode)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 848, in embedding_attention_seq2seq
encoder_cell = copy.deepcopy(cell)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 174, in deepcopy
y = copier(memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 476, in __deepcopy__
setattr(result, k, copy.deepcopy(v, memo))
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
y.append(deepcopy(a, memo))
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/jkarimi91/Apps/anaconda2/envs/tf/lib/python2.7/copy.py", line 343, in _reconstruct
y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update'
@Tshzzz @jtubert
thx, ๊ทํ์ ์๋ฃจ์
์ด ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค. ๋ด tf ๋ฒ์ ์ 1.1.0์
๋๋ค.
๋๋ ๋ค์์์ ๋ณ๊ฒฝํ๋ค:
lstm_cell = tf.contrib.rnn.BasicLSTMCell(HIDDEN_SIZE, state_is_tuple=True)
cell = tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(NUM_LAYERS)])
output, _ = tf.nn.dynamic_rnn(cell, X, dtype=tf.float32)
์๊ฒ:
cells=[]
for _ in range(NUM_LAYERS):
cell = tf.contrib.rnn.BasicLSTMCell(HIDDEN_SIZE, state_is_tuple=True)
cells.append(cell)
multicell = tf.contrib.rnn.MultiRNNCell(cells, state_is_tuple=True)
output, _ = tf.nn.dynamic_rnn(multicell, X, dtype=tf.float32)
์ด๊ฒ์ ์ฌ์ ํ โโ๊ณ ์ ๋์ง ์์์ผ๋ฉฐ ๊ฐ๋ฅํ ๋ชจ๋ ์๋ฃจ์ ์ ์๋ํ์ง๋ง ์ด ์ค๋ ๋์ stackoverflow์์ ์ธ๊ธํ ์๋ฃจ์ ์ tensorflow 1.3 ๋๋ 1.2 ๋๋ 1.1์์ ์๋ํ์ง ์์ต๋๋ค.
์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
TypeError: embedding_attention_seq2seq() missing 1 required positional argument: 'dec_cell'
์ค๋ฅ๋ seq2seq_model.py์ 142ํ์ธ seq2seq_model.py์ ์ด ํจ์๋ฅผ ๊ฐ๋ฆฌํต๋๋ค.
def seq2seq_f(encoder_inputs, decoder_inputs, do_decode):
return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
encoder_inputs,
decoder_inputs,
cell,
num_encoder_symbols=source_vocab_size,
num_decoder_symbols=target_vocab_size,
embedding_size=size,
output_projection=output_projection,
feed_previous=do_decode,
dtype=dtype)
์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ฌ๋์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋๋ก ๋์์ฃผ์ธ์.
ValueError: RNNCell ์ฌ์ฌ์ฉ ์๋
์์ฐ์ง ์ฝ๋:
tensorflow.contrib์์ ๊ฐ์ ธ์ค๊ธฐ rnn
์
๋ ฅ = tf.placeholder(dtype=tf.int32, ๋ชจ์=[์์, ์์], ์ด๋ฆ="์
๋ ฅ")
keep_prob = tf.placeholder(dtype=tf.float32, name="keep_prob")
์
= rnn.GRUCell(10)
cell = rnn.DropoutWrapper(cell=cell, input_keep_prob=keep_prob)
cell = rnn.MultiRNNCell([๋ฒ์(5)์ ์๋ _์ ๋ํ ์
], state_is_tuple=True)
์ถ๋ ฅ, ์ํ = tf.nn.dynamic_rnn(์
=์
, ์
๋ ฅ=look_up, dtype=tf.float32)
ํด๊ฒฐ์ฑ
:
์
๋ ฅ = tf.placeholder(dtype=tf.int32, ๋ชจ์=[์์, ์์], ์ด๋ฆ="์
๋ ฅ")
keep_prob = tf.placeholder(dtype=tf.float32, name="keep_prob")
cell = rnn.MultiRNNCell([rnn.DropoutWrapper(rnn.GRUCell(10), input_keep_prob=keep_prob) for _ in range(5)], state_is_tuple=True)
tf nightlies์ ์ด ๋ฌธ์ ๊ฐ ์์ต๋๊น?
2017๋ 10์ 1์ผ ์ค์ 8์ 34๋ถ์ "Baohua Zhou" ์๋ฆผ @github.com์ด ์์ฑํ์ต๋๋ค.
ios์ ํจ๊ป CPU์์ tensorflow 1.1์ ์ฌ์ฉํ ๋๋ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/tensorflow/tensorflow/issues/8191#issuecomment-333384725 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABtimwOv7vf5vvFXBllbZryjCFwmJcU6ks5sn7DxgaJpZM4MWl4f
.
AttributeError: 'NoneType' ๊ฐ์ฒด์ '์ ๋ฐ์ดํธ' ์์ฑ์ด ์์ต๋๋ค.
tf=1.3์์
ValueError: RNNCell ์ฌ์ฌ์ฉ ์๋
14์ผ ๋์ ํ๋์ด ์์์ผ๋ฉฐ awaiting tensorflower
๋ ์ด๋ธ์ด ์ง์ ๋์์ต๋๋ค. ๊ทธ์ ๋ฐ๋ผ ๋ ์ด๋ธ ๋ฐ/๋๋ ์ํ๋ฅผ ์
๋ฐ์ดํธํ์ญ์์ค.
TensorFlower๋ฅผ ๊ธฐ๋ค๋ฆฌ๋ ์์๋ฆฌ: 14์ผ ๋์ ํ๋์ด ์์์ผ๋ฉฐ awaiting tensorflower
๋ ์ด๋ธ์ด ํ ๋น๋์์ต๋๋ค. ๊ทธ์ ๋ฐ๋ผ ๋ ์ด๋ธ ๋ฐ/๋๋ ์ํ๋ฅผ ์
๋ฐ์ดํธํ์ญ์์ค.
ํด๊ฒฐ์ฑ ์ ์ต์ ๋ฒ์ ์ TF๋ก ์ด๋ํ๋ ๊ฒ์ ๋๋ค. ์ด ์ค๋ ๋๋ ์๋ ๋ฌธ์ ์์ ํฌ๊ฒ ๋ฒ์ด๋ฌ์ต๋๋ค. ํ์.
์ฆ๊ฐ์ ์ธ ์๋ฃจ์ ์ ์ํ๋ค๋ฉด ๋ด๊ฐ ์๋ํ ๊ฒ์ ์๋ ํ ์ ์์ต๋๋ค.
pip install tensorflow==1.0
๋ฌธ์ ๋ tenorflow 1.1 ๋ฒ์ ์ ์์ต๋๋ค. ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๋ง๋ฌ๋ค. ๋ง์คํฐ ๋ธ๋์น์์ ๋ชจ๋ ์ปดํ์ผ๋ ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ๊ณ์๋ค๋ฉด ์ต๊ทผ commit ์ผ๋ก ์ธํด ๋ฐ์ํ๋ ๋์ผํ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์ปค๋ฐ ๋ฉ์์ง๋ ๋ค์๊ณผ ๊ฐ์ด ๋งํฉ๋๋ค.
ptb tutorial ์ ์คํํ๋ ์ ๊ฒฝ์ฐ์๋ 112๋ฒ์งธ ์ค์
reuse
๋ผ๋ ์ด๋ฆ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.๊ทธ๋ฌ๋ฉด ์๋ํฉ๋๋ค.