Fix Google seq2seq Installation Errors
A collection of solutions to solve seq2seq installation and unit test issues.
I bet there are numerous people who are enthusiastic about NLP. Especially in deep neural networks, such as seq2seq models, which is widely applied in translations, conversational modeling and etc. Google has released an exciting package about seq2seq https://github.com/google/seq2seq. What is annoying is that it is a little bit outdated and it has some tiny issues while installation and unit testing. I have listed some of the possible issues and their solutions. Hope they can be useful. Enjoy
Bug 1:
ImportError: Failed to import test module: seq2seq
Traceback (most recent call last):
File “/usr/lib/python3.5/unittest/loader.py”, line 153, in loadTestsFromName
module = __import__(module_name)
File “/home/tfdata/seq2seq/seq2seq/__init__.py”, line 26, in <module>
from seq2seq import decoders
File “/home/tfdata/seq2seq/seq2seq/decoders/__init__.py”, line 20, in <module>
from seq2seq.decoders.attention_decoder import *
File “/home/tfdata/seq2seq/seq2seq/decoders/attention_decoder.py”, line 27, in <module>
from seq2seq.contrib.seq2seq.helper import CustomHelper
File “/home/tfdata/seq2seq/seq2seq/contrib/seq2seq/helper.py”, line 35, in <module>
from tensorflow.contrib.distributions.python.ops import bernoulli
ImportError: cannot import name ‘bernoulli’
Soln 1:
vim seq2seq/contrib/seq2seq/helper.py
change the following code
from tensorflow.contrib.distributions.python.ops import bernoulli
from tensorflow.contrib.distributions.python.ops import categoricalsample_id_sampler = categorical.Categorical(logits=outputs)
sampler = bernoulli.Bernoulli(probs=self._sampling_probability)
to
from tensorflow.contrib.distributions import Bernoulli
from tensorflow.contrib.distributions import Categoricalsample_id_sampler = Categorical(logits=outputs)
sampler = Bernoulli(probs=self._sampling_probability)
Bug 2:
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
Tests training and inference scripts.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Traceback (most recent call last):
File “/home/tfdata/seq2seq/seq2seq/test/pipeline_test.py”, line 76, in test_train_infer
_clear_flags()
File “/home/tfdata/seq2seq/seq2seq/test/pipeline_test.py”, line 44, in _clear_flags
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
AttributeError: module ‘tensorflow.python.platform.flags’ has no attribute ‘_FlagValues’
Soln 2:
vim seq2seq/test/pipeline_test.py
change the following part
def _clear_flags():
"""Resets Tensorflow’s FLAG values"""
#pylint: disable=W0212
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
tf.app.flags._global_parser = argparse.ArgumentParser()
to
def _clear_flags():
"""Resets Tensorflow's FLAG values"""
#pylint: disable=W0212
for flag_key in dir(tf.app.flags.FLAGS):
delattr(tf.app.flags.FLAGS, flag_key)
#tf.app.flags.FLAGS = tf.app.flags._FlagValues()
tf.app.flags._global_parser = argparse.ArgumentParser()
Bug 3:
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
Tests training and inference scripts.
--------------------------------------------------------------------
ValueError: num_units is not a valid argument for GRUCell class. Available arguments are: set()
Soln 3:
vim seq2seq/training/utils.py
change the following
cell_args = set(inspect.getargspec(cell_class.__init__).args[1:])
to
cell_args = set(inspect.signature(cell_class.__init__).parameters)
Bug 4:
ImportError: No module named '_tkinter'
Soln 4:
sudo apt update
sudo apt install python3-tk -y
Bug 5:
**RuntimeError**: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
Soln 5:
vim ~/.matplotlib/matplotlibrc
paste
backend: TkAgg
Now try:
python -m unittest seq2seq.test.pipeline_test
You should see the the OK
now!
Reference: