chatbot-rnn icon indicating copy to clipboard operation
chatbot-rnn copied to clipboard

no module named tensorflow.contrib

Open akarthik2014 opened this issue 4 years ago • 7 comments

Exception has occurred: ModuleNotFoundError No module named 'tensorflow.contrib'

akarthik2014 avatar Sep 09 '20 10:09 akarthik2014

since your issue is not very old so I guess you have Tensorflow 2.0.x installed in your machine but tensorflowf.contrib no longer exists in tensorflow 2.0.x, it was there in Tensorflow 1.x

101Priyanshi avatar Oct 05 '20 08:10 101Priyanshi

Any suggestions for using Tensorflow 2.x?

wmodes avatar Nov 08 '20 16:11 wmodes

Any suggestions for using Tensorflow 2.x?

  • First, install tensorflow_addons:
pip install tensorflow-addons

Option 1:

  • Run the following script in the repository's directory:
from glob import glob

def update(find, replacement):
    for file in glob('*.py'):
        with open(file) as f:
            s = f.read().replace(find, replacement)
        with open(file, 'w') as f:
            f.write(s)

update('import tensorflow as tf', '''import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
import tensorflow_addons as tfa''')
update('tf.contrib.rnn.LSTMStateTuple', 'tf.compat.v1.nn.rnn_cell.LSTMStateTuple')
update('from tensorflow.contrib import rnn', '')
update('rnn.NASCell', 'tfa.rnn.NASCell')

Option 2:

  • Clone my fork, which is compatible with TensorFlow v2.x:
git clone https://github.com/Alyetama/chatbot-rnn.git

Alyetama avatar Jun 25 '21 22:06 Alyetama

pip install tensorflow==1.15

breadbrowser avatar Apr 27 '22 11:04 breadbrowser

is all you need to do

breadbrowser avatar Apr 27 '22 11:04 breadbrowser

no editing

breadbrowser avatar Apr 27 '22 11:04 breadbrowser

needed

breadbrowser avatar Apr 27 '22 11:04 breadbrowser