lvapeab / nmt-keras

Neural Machine Translation with Keras

Home Page:http://nmt-keras.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error during decoding

VP007-py opened this issue · comments

After training the model,I tried decoding it with two iterations and i am getting the following error.

python sample_ensemble.py --models trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_1 trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_2 --dataset datasets/Dataset_EuTrans_esen.pkl --text examples/EuTrans/test.en 
[01/11/2018 12:49:07] Reading parameters from config.py
[01/11/2018 12:49:07] <<< Cupy not available. Using numpy. >>>
Using Theano backend.
[01/11/2018 12:49:08] <<< Cupy not available. Using numpy. >>>
[01/11/2018 12:49:08] Using an ensemble of 2 models
[01/11/2018 12:49:08] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_1_Model_Wrapper.pkl ... >>>
[01/11/2018 12:49:08] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_1.h5 ... >>>
[01/11/2018 12:49:12] <<< Loading optimized model... >>>
[01/11/2018 12:49:15] <<< Optimized model loaded. >>>
[01/11/2018 12:49:15] <<< Model loaded in 7.5578 seconds. >>>
[01/11/2018 12:49:15] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_2_Model_Wrapper.pkl ... >>>
[01/11/2018 12:49:15] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_2.h5 ... >>>
[01/11/2018 12:49:17] <<< Loading optimized model... >>>
[01/11/2018 12:49:21] <<< Optimized model loaded. >>>
[01/11/2018 12:49:21] <<< Model loaded in 5.2314 seconds. >>>
[01/11/2018 12:49:21] <<< Loading Dataset instance from datasets/Dataset_EuTrans_esen.pkl ... >>>
[01/11/2018 12:49:21] <<< Dataset instance loaded >>>
[01/11/2018 12:49:21] Removed "val" set outputs of type "text" with id "target_text.
[01/11/2018 12:49:21] 	Applying tokenization function: "tokenize_none".
[01/11/2018 12:49:21] Loaded "val" set inputs of data_type "text" with data_id "source_text" and length 2996.
[01/11/2018 12:49:21] Loaded "val" set inputs of data_type "ghost" with data_id "state_below" and length 2996.
[01/11/2018 12:49:21] Loaded "val" set inputs of type "file-name" with id "raw_source_text".
[01/11/2018 12:49:21] 
 <<< Predicting outputs of val set >>>
[01/11/2018 12:49:28] We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
[01/11/2018 12:49:29] We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
Traceback (most recent call last):
  File "sample_ensemble.py", line 61, in <module>
    sample_ensemble(args, params)
  File "/home/Vinay737/nmt-keras/nmt_keras/apply_model.py", line 94, in sample_ensemble
    predictions = beam_searcher.predictBeamSearchNet()[s]
  File "/home/Vinay737/nmt-keras/src/keras-wrapper/keras_wrapper/model_ensemble.py", line 249, in predictBeamSearchNet
    return_alphas=self.return_alphas, model_ensemble=True, n_models=len(self.models))
  File "/home/Vinay737/nmt-keras/src/keras-wrapper/keras_wrapper/search.py", line 135, in beam_search
    new_hyp_samples.append(hyp_samples[ti] + [wi])
IndexError: list index out of range

Any fixes ?

Hi @PVinay737 ,

in fact, you were doing nothing wrong. Through your problem I detected a recently introduced bug. I've just fixed it (lvapeab/multimodal_keras_wrapper@f6d87f7). You should update the keras_wrapper to the last version.

Cheers!

@lvapeab,that doesn't seem to be the fix

python sample_ensemble.py --models trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_1  trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_2 --dataset datasets/Dataset_EuTrans_esen.pkl --text examples/EuTrans/test.en 
[02/11/2018 17:13:05] Reading parameters from config.py
[02/11/2018 17:13:05] <<< Cupy not available. Using numpy. >>>
Using Theano backend.
[02/11/2018 17:13:06] <<< Cupy not available. Using numpy. >>>
[02/11/2018 17:13:06] Using an ensemble of 2 models
[02/11/2018 17:13:06] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_1_Model_Wrapper.pkl ... >>>
[02/11/2018 17:13:06] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_1.h5 ... >>>
[02/11/2018 17:13:10] <<< Loading optimized model... >>>
[02/11/2018 17:13:13] <<< Optimized model loaded. >>>
[02/11/2018 17:13:13] <<< Model loaded in 7.5471 seconds. >>>
[02/11/2018 17:13:13] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_2_Model_Wrapper.pkl ... >>>
[02/11/2018 17:13:13] <<< Loading model from trained_models/EuTrans_esen_AttentionRNNEncoderDecoder_src_emb_250_bidir_True_enc_LSTM_32_dec_ConditionalLSTM_32_deepout_linear_trg_emb_250_Adam_0.001/epoch_2.h5 ... >>>
[02/11/2018 17:13:15] <<< Loading optimized model... >>>
[02/11/2018 17:13:18] <<< Optimized model loaded. >>>
[02/11/2018 17:13:18] <<< Model loaded in 5.2335 seconds. >>>
[02/11/2018 17:13:18] <<< Loading Dataset instance from datasets/Dataset_EuTrans_esen.pkl ... >>>
[02/11/2018 17:13:19] <<< Dataset instance loaded >>>
[02/11/2018 17:13:19] Removed "val" set outputs of type "text" with id "target_text.
[02/11/2018 17:13:19] 	Applying tokenization function: "tokenize_none".
[02/11/2018 17:13:19] Loaded "val" set inputs of data_type "text" with data_id "source_text" and length 2996.
[02/11/2018 17:13:19] Loaded "val" set inputs of data_type "ghost" with data_id "state_below" and length 2996.
[02/11/2018 17:13:19] Loaded "val" set inputs of type "file-name" with id "raw_source_text".
[02/11/2018 17:13:19] 
 <<< Predicting outputs of val set >>>
[02/11/2018 17:13:26] We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
[02/11/2018 17:13:27] We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
Total cost of the translations: 25239.669452 	 Average cost of the translations: 8.424456
The sampling took: 104.785528 secs (Speed: 0.034975 sec/sample)
Traceback (most recent call last):
  File "sample_ensemble.py", line 61, in <module>
    sample_ensemble(args, params)
  File "/home/Vinay737/nmt-keras/nmt_keras/apply_model.py", line 113, in sample_ensemble
    verbose=args.verbose)
  File "/home/Vinay737/nmt-keras/src/keras-wrapper/keras_wrapper/utils.py", line 998, in decode_predictions_beam_search
    x_text))
  File "/home/Vinay737/nmt-keras/src/keras-wrapper/keras_wrapper/utils.py", line 997, in <lambda>
    map(lambda alignment, x_sentence: np.argmax(alignment[:, :max(1, len(x_sentence))], axis=1), alphas,
IndexError: too many indices for array

Just pushed (another) fix. Please, try again.

Working...!!

How about integrating evaluation metrics after this step with bleu or toolkits like this

I'd rather to maintain the sampling process independent of the evaluation. After sampling, you can run your desired evaluator. There is a script (utils/evaluate_from_file.py) for computing several metrics according to the coco evaluation package. You can use this (or any other) for computing BLEU.