{"action":"opened","issue":{"url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/1026","repository_url":"https://api.github.com/repos/PaddlePaddle/Paddle","labels_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/1026/labels{/name}","comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/1026/comments","events_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/1026/events","html_url":"https://github.com/PaddlePaddle/Paddle/issues/1026","id":197796071,"number":1026,"title":"seqToseq with reconstruction net 出现 dynamic_cast<CpuIVector*>(&label) error ","user":{"login":"alvations","id":1050316,"avatar_url":"https://avatars.githubusercontent.com/u/1050316?v=3","gravatar_id":"","url":"https://api.github.com/users/alvations","html_url":"https://github.com/alvations","followers_url":"https://api.github.com/users/alvations/followers","following_url":"https://api.github.com/users/alvations/following{/other_user}","gists_url":"https://api.github.com/users/alvations/gists{/gist_id}","starred_url":"https://api.github.com/users/alvations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alvations/subscriptions","organizations_url":"https://api.github.com/users/alvations/orgs","repos_url":"https://api.github.com/users/alvations/repos","events_url":"https://api.github.com/users/alvations/events{/privacy}","received_events_url":"https://api.github.com/users/alvations/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-28T04:57:14Z","updated_at":"2016-12-28T04:57:14Z","closed_at":null,"body":"[Tu et al. (2016)](https://arxiv.org/pdf/1611.01874v2.pdf) 创造一个“Reconstruction”网络。我 seqToseq 的demo稍微改了一点，\r\n\r\ndataprovider.py里把`src_ids`重复一遍 https://github.com/PaddlePaddle/Paddle/blob/develop/demo/seqToseq/dataprovider.py#L88\r\n\r\n```\r\n                yield {\r\n                    'source_language_word': src_ids,\r\n                    'target_language_word': trg_ids,\r\n                    'target_language_next_word': trg_ids_next\r\n                    'source_language_word_2': src_ids,\r\n                }\r\n```\r\n\r\n然后在seqToseq_net.py加了：\r\n\r\n```python\r\ndef gru_encoder_decoder(data_conf, is_generating, word_vector_dim=512,\r\n                            encoder_size=512, decoder_size=512,\r\n                            beam_size=3, max_length=250):\r\n    \"\"\"\r\n    A wrapper for an attention version of GRU Encoder-Decoder network\r\n    is_generating: whether this config is used for generating\r\n    encoder_size: dimension of hidden unit in GRU Encoder network\r\n    decoder_size: dimension of hidden unit in GRU Decoder network\r\n    word_vector_dim: dimension of word vector\r\n    beam_size: expand width in beam search\r\n    max_length: a stop condition of sequence generation\r\n    \"\"\"\r\n    for k, v in data_conf.iteritems():\r\n        globals()[k] = v\r\n    source_dict_dim = get_file_len(src_dict_path)\r\n    target_dict_dim = get_file_len(trg_dict_path)\r\n    gen_trans_file = gen_result\r\n\r\n    # Input layer.\r\n    src_word_id = data_layer(name='source_language_word', size=source_dict_dim)\r\n    # Embedding layer.\r\n    src_embedding = embedding_layer(\r\n                        input=src_word_id,\r\n                        size=word_vector_dim,\r\n                        param_attr=ParamAttr(name='_source_language_embedding'))\r\n    # Forward GRU layer.\r\n    src_forward = simple_gru(input=src_embedding, size=encoder_size)\r\n    # Backward GRU layer.\r\n    src_backward = simple_gru(input=src_embedding, size=encoder_size, reverse=True)\r\n    # Concatenated Layer = [Forword  Backward]\r\n    encoded_vector = concat_layer(input=[src_forward, src_backward])\r\n\r\n    with mixed_layer(size=decoder_size) as encoded_proj:\r\n        encoded_proj += full_matrix_projection(encoded_vector)\r\n\r\n    backward_first = first_seq(input=src_backward)\r\n    with mixed_layer(size=decoder_size,\r\n                     act=TanhActivation(), ) as decoder_boot:\r\n        decoder_boot += full_matrix_projection(backward_first)\r\n\r\n\r\n    def gru_decoder_wth_attention(enc_vec, enc_proj, current_word):\r\n        decoder_mem = memory(name='gru_decoder',\r\n                             size=decoder_size,\r\n                             boot_layer=decoder_boot)\r\n\r\n        context = simple_attention(encoded_sequence=enc_vec,\r\n                                   encoded_proj=enc_proj,\r\n                                   decoder_state=decoder_mem, )\r\n\r\n        with mixed_layer(size=decoder_size * 3) as decoder_inputs:\r\n            decoder_inputs += full_matrix_projection(context)\r\n            decoder_inputs += full_matrix_projection(current_word)\r\n\r\n        gru_or_lstm_step = gru_step_layer(name='gru_decoder',\r\n                                          input=decoder_inputs,\r\n                                          output_mem=decoder_mem,\r\n                                          size=decoder_size)\r\n\r\n        with mixed_layer(size=target_dict_dim,\r\n                         bias_attr=True,\r\n                         act=SoftmaxActivation()) as out:\r\n            out += full_matrix_projection(input=gru_or_lstm_step)\r\n        return out, gru_or_lstm_step\r\n\r\n    def gru_reconstructor_wth_attention(enc_vec, enc_proj, current_word):\r\n        decoder_mem = memory(name='gru_reconstructor',\r\n                             size=decoder_size,\r\n                             boot_layer=decoder_boot)\r\n\r\n        context = simple_attention(encoded_sequence=enc_vec,\r\n                                   encoded_proj=enc_proj,\r\n                                   decoder_state=decoder_mem, )\r\n\r\n        with mixed_layer(size=decoder_size * 3) as decoder_inputs:\r\n            decoder_inputs += full_matrix_projection(context)\r\n            decoder_inputs += full_matrix_projection(current_word)\r\n\r\n        gru_or_lstm_step = gru_step_layer(name='gru_reconstructor',\r\n                                          input=decoder_inputs,\r\n                                          output_mem=decoder_mem,\r\n                                          size=decoder_size)\r\n\r\n        with mixed_layer(size=source_dict_dim,\r\n                         bias_attr=True,\r\n                         act=SoftmaxActivation()) as out:\r\n            out += full_matrix_projection(input=gru_or_lstm_step)\r\n        return out, gru_or_lstm_step\r\n\r\n    decoder_group_name = \"decoder_group\"\r\n    decode_group_inputs=[StaticInput(input=encoded_vector,is_seq=True),\r\n                  StaticInput(input=encoded_proj,is_seq=True)]\r\n\r\n    if not is_generating:\r\n        trg_embedding = embedding_layer(\r\n            input=data_layer(name='target_language_word',\r\n                             size=target_dict_dim),\r\n            size=word_vector_dim,\r\n            param_attr=ParamAttr(name='_target_language_embedding'))\r\n        decode_group_inputs.append(trg_embedding)\r\n\r\n        decoder, decoder_vec = recurrent_group(name=decoder_group_name,\r\n                                  step=gru_decoder_wth_attention,\r\n                                  input=decode_group_inputs)\r\n        lbl = data_layer(name='target_language_next_word',\r\n                         size=target_dict_dim)\r\n        decode_cost = classification_cost(input=decoder, label=lbl, )\r\n\r\n        with mixed_layer(size=decoder_size) as decoder_proj:\r\n            decoder_proj += full_matrix_projection(decoder_vec)\r\n\r\n\r\n        reconstructor_group_name = \"reconstructor_group\"\r\n        recon_group_inputs = [StaticInput(input=decoder_vec,is_seq=True),\r\n                              StaticInput(input=decoder_proj,is_seq=True)]\r\n        recon_group_inputs.append(src_embedding)\r\n\r\n        reconstructor, _ = recurrent_group(name=reconstructor_group_name,\r\n                                        step=gru_reconstructor_wth_attention,\r\n                                        input=recon_group_inputs)\r\n\r\n        src_word_id_2 = data_layer(name='target_language_next_word_2',\r\n                                    size=source_dict_dim)\r\n        recon_cost = classification_cost(input=reconstructor, label=src_word_id_2)\r\n\r\n        outputs(decode_cost)\r\n\r\n\r\n    else:\r\n\r\n        trg_embedding = GeneratedInput(\r\n            size=target_dict_dim,\r\n            embedding_name='_target_language_embedding',\r\n            embedding_size=word_vector_dim)\r\n        group_inputs.append(trg_embedding)\r\n\r\n        beam_gen = beam_search(name=decoder_group_name,\r\n                               step=gru_decoder_wth_attention,\r\n                               input=group_inputs,\r\n                               bos_id=0,\r\n                               eos_id=1,\r\n                               beam_size=beam_size,\r\n                               max_length=max_length)\r\n\r\n        seqtext_printer_evaluator(input=beam_gen,\r\n                                  id_input=data_layer(name=\"sent_id\", size=1),\r\n                                  dict_file=trg_dict_path,\r\n                                  result_file=gen_trans_file)\r\n        outputs(beam_gen)\r\n```\r\n\r\n但是在运行时，Paddle回这个error：\r\n\r\n```\r\n$ bash train.sh \r\nI1228 12:49:41.714779 27295 Util.cpp:155] commandline: /usr/local/bin/../opt/paddle/bin/paddle_trainer --config=train.conf --save_dir=/home/ltan/Ibot-Recon/model-test --use_gpu=false --num_passes=3 --show_parameter_stats_period=1000 --trainer_count=4 --log_period=10 --dot_period=5 \r\nI1228 12:49:41.714972 27295 Util.cpp:130] Calling runInitFunctions\r\nI1228 12:49:41.715245 27295 Util.cpp:143] Call runInitFunctions done.\r\nTraceback (most recent call last):\r\n  File \"<string>\", line 13, in <module>\r\nNameError: name 'GLOG_logtostderr' is not defined\r\n[INFO 2016-12-28 12:49:42,055 networks.py:1466] The input order is [source_language_word, target_language_word, target_language_next_word]\r\n[INFO 2016-12-28 12:49:42,055 networks.py:1472] The output order is [__cost_0__]\r\nI1228 12:49:42.072384 27295 Trainer.cpp:170] trainer mode: Normal\r\nI1228 12:49:42.497022 27295 PyDataProvider2.cpp:257] loading dataprovider dataprovider::process\r\n[INFO 2016-12-28 12:49:42,497 dataprovider.py:14] src dict len : 10000\r\n[INFO 2016-12-28 12:49:42,498 dataprovider.py:24] trg dict len : 7116\r\nI1228 12:49:42.509634 27295 PyDataProvider2.cpp:257] loading dataprovider dataprovider::process\r\n[INFO 2016-12-28 12:49:42,509 dataprovider.py:14] src dict len : 10000\r\n[INFO 2016-12-28 12:49:42,509 dataprovider.py:24] trg dict len : 7116\r\nI1228 12:49:42.510082 27295 GradientMachine.cpp:134] Initing parameters..\r\nI1228 12:49:44.382016 27295 GradientMachine.cpp:141] Init parameters done.\r\nI1228 12:49:44.685884 27360 ThreadLocal.cpp:37] thread use undeterministic rand seed:27361\r\nF1228 12:49:45.947146 27301 Matrix.cpp:3154] Check failed: dynamic_cast<CpuIVector*>(&label) \r\n*** Check failure stack trace: ***\r\n    @     0x7f8fde03edaa  (unknown)\r\n    @     0x7f8fde03ece4  (unknown)\r\n    @     0x7f8fde03e6e6  (unknown)\r\n    @     0x7f8fde041687  (unknown)\r\n    @           0x6dbd49  paddle::CpuMatrix::oneHotCrossEntropy()\r\n    @           0x5ff835  paddle::CostLayer::forward()\r\n    @           0x6714ce  paddle::NeuralNetwork::forward()\r\n    @           0x677997  paddle::TrainerThread::forward()\r\n    @           0x679cb5  paddle::TrainerThread::computeThread()\r\n    @     0x7f8fddbbba60  (unknown)\r\n    @     0x7f8fdee51184  start_thread\r\n    @     0x7f8fdd32337d  (unknown)\r\n    @              (nil)  (unknown)\r\n/usr/local/bin/paddle: line 109: 27295 Aborted                 (core dumped) ${DEBUGGER} $MYDIR/../opt/paddle/bin/paddle_trainer ${@:2}\r\n```\r\n\r\n这个error是不是我设的神经网络错误呢？"}}
{"actor":{"display_login":"alvations"}}