के साथ seq2seq मॉडल का निर्माण करते समय त्रुटि मैं tensorflow में seq2seq.py में परिभाषित seq2seq मॉडल को समझने की कोशिश कर रहा हूं। मैं कोड के बिट्स का उपयोग करता हूं जो मैं translate.py उदाहरण से कॉपी करता हूं जो tensorflow के साथ आता है। मैं वही त्रुटि प्राप्त करता रहता हूं और वास्तव में यह नहीं समझता कि यह कहां से आता है।tensorflow
एक न्यूनतम कोड उदाहरण त्रुटि पुन: पेश करने:
import tensorflow as tf
from tensorflow.models.rnn import rnn_cell
from tensorflow.models.rnn import seq2seq
encoder_inputs = []
decoder_inputs = []
for i in xrange(350):
encoder_inputs.append(tf.placeholder(tf.int32, shape=[None],
name="encoder{0}".format(i)))
for i in xrange(45):
decoder_inputs.append(tf.placeholder(tf.int32, shape=[None],
name="decoder{0}".format(i)))
model = seq2seq.basic_rnn_seq2seq(encoder_inputs,
decoder_inputs,rnn_cell.BasicLSTMCell(512))
त्रुटि मैं जब अंतिम पंक्ति का मूल्यांकन मिल (मैं इसे का मूल्यांकन सहभागी अजगर दुभाषिया में):
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/py1053173el", line 12, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/models/rnn/seq2seq.py", line 82, in basic_rnn_seq2seq
_, enc_states = rnn.rnn(cell, encoder_inputs, dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/models/rnn/rnn.py", line 85, in rnn
output_state = cell(input_, state)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/models/rnn/rnn_cell.py", line 161, in __call__
concat = linear.linear([inputs, h], 4 * self._num_units, True)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/models/rnn/linear.py", line 32, in linear
raise ValueError("Linear is expecting 2D arguments: %s" % str(shapes))
ValueError: Linear is expecting 2D arguments: [[None], [None, 512]]
मुझे लगता है त्रुटि मेरी तरफ से आता है :) एक sidenote पर। प्रलेखन और ट्यूटोरियल वास्तव में महान हैं लेकिन अनुक्रम के अनुक्रम के लिए उदाहरण कोड (अंग्रेजी से फ्रेंच अनुवाद उदाहरण) काफी घना है। क्या हो रहा है यह समझने के लिए आपको फाइलों के बीच बहुत कुछ कूदना होगा। मुझे कम से कम कोड में कई बार खो गया है।
बुनियादी seq2seq मॉडल का निर्माण और प्रशिक्षण करने का एक न्यूनतम उदाहरण (शायद कुछ खिलौने डेटा पर) वास्तव में यहां सहायक होगा। किसी को पता है कि यह पहले से कहीं मौजूद है?
संपादित मैं @Ishamael सुझाव अनुसार उपरोक्त कोड (अर्थ, कोई त्रुटि रिटर्न) (नीचे देखें) तय कर दी है, लेकिन अभी भी कुछ बातें इस निश्चित संस्करण में स्पष्ट नहीं हैं। मेरा इनपुट असली मूल्यवान मूल्यों की लंबाई 2 के वैक्टरों का अनुक्रम है। और मेरा आउटपुट लंबाई 22 के द्विआधारी वैक्टरों का अनुक्रम है। क्या मेरा tf.placeholder कोड निम्न जैसा दिखता नहीं है? (संपादित हाँ)
tf.placeholder(tf.float32, shape=[None,2],name="encoder{0}".format(i))
tf.placeholder(tf.float32, shape=[None,22],name="encoder{0}".format(i))
मैं भी ऊपर tf.float32 को tf.int32 बदलना पड़ा। चूंकि मेरा आउटपुट बाइनरी है। क्या यह मेरे डीकोडर के tf.placeholder के लिए tf.int32 नहीं होना चाहिए? लेकिन अगर मैं ऐसा करता हूं तो tensorflow फिर से शिकायत करता है। मुझे यकीन नहीं है कि इसके पीछे तर्क क्या है।
मेरी छिपी परत का आकार यहां 512 है।
पूरा तय कोड
import tensorflow as tf
from tensorflow.models.rnn import rnn_cell
from tensorflow.models.rnn import seq2seq
encoder_inputs = []
decoder_inputs = []
for i in xrange(350):
encoder_inputs.append(tf.placeholder(tf.float32, shape=[None,512],
name="encoder{0}".format(i)))
for i in xrange(45):
decoder_inputs.append(tf.placeholder(tf.float32, shape=[None,512],
name="decoder{0}".format(i)))
model = seq2seq.basic_rnn_seq2seq(encoder_inputs,
decoder_inputs,rnn_cell.BasicLSTMCell(512))
मैं अभी tf में seq2seq जानने की कोशिश कर रहा हूँ। 350 आपके एन्कोडर का vocab आकार और 45 आपके डिकोडर का vocab आकार है? – Soubriquet