Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation failed when using SRU network #375

Closed
IdiosyncraticDragon opened this issue Nov 6, 2017 · 2 comments
Closed

Translation failed when using SRU network #375

IdiosyncraticDragon opened this issue Nov 6, 2017 · 2 comments

Comments

@IdiosyncraticDragon
Copy link

IdiosyncraticDragon commented Nov 6, 2017

I have trained a SRU network like this

python train.py -data /home/data/wmt/wmt14-de-en/pywmt14 -save_model /home/deepModels/torch_models/opennmt-py/sru -model_type 'text' -word_vec_size 500 -encoder_type 'rnn'  -rnn_size 500 -rnn_type 'SRU' -global_attention 'general' -layers 10 -input_feed 0 -optim 'sgd' -epochs 15 -batch_size 64 -dropout 0.1 -learning_rate 1.0 -learning_rate_decay 0.000001 -gpuid 0

It worked fine.

However when I tried to do translation like this:

python translate.py -model /home/deepModels/torch_models/opennmt-py/sru_acc_33.94_ppl_41.48_e1.pt -src /home/data/wmt/wmt14-de-en/newstest2014-deen-src.en -replace_unk -verbose -output pred_deen.txt -gpu 1 -batch_size 1

Here came the error:

Loading model parameters.
dTraceback (most recent call last):
  File "translate.py", line 127, in <module>
    main()
  File "translate.py", line 66, in main
    for batch in test_data:
  File "/root/anaconda2/lib/python2.7/site-packages/torchtext/data/iterator.py", line 178, in __iter__
    self.train)
  File "/root/anaconda2/lib/python2.7/site-packages/torchtext/data/batch.py", line 22, in __init__
    setattr(self, name, field.process(batch, device=device, train=train))
  File "/root/anaconda2/lib/python2.7/site-packages/torchtext/data/field.py", line 184, in process
    tensor = self.numericalize(padded, device=device, train=train)
  File "/root/anaconda2/lib/python2.7/site-packages/torchtext/data/field.py", line 294, in numericalize
    arr = [numericalization_func(x) for x in arr]
  File "/root/anaconda2/lib/python2.7/site-packages/torch/tensor.py", line 389, in __float__
    raise TypeError("only 1-element tensors can be converted "
TypeError: only 1-element tensors can be converted to Python scalars
Exception TypeError: "'NoneType' object is not callable" in <bound method Program.__del__ of <pynvrtc.compiler.Program object at 0x7f18ef35ce90>> ignored

I don't know what's wrong with it.

@JianyuZhan
Copy link
Contributor

Well, this is a known bug in torchtext 0.2.0, the maintainer has a fix for it: pytorch/text#159

But probably it still not on pip repository for you to update, you can manually patch it or downgrade your torchtext version to 0.1.0(by uninstalling current one, and install the 0.1.0 version.

@IdiosyncraticDragon
Copy link
Author

@JianyuZhan Thank you! By checkout the latest version (which downgrade to torchtext 0.1.1). The "TypeError" disapear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants