[Solved]: TypeError: softmax() got an unexpected keyword argument 'axis'

ERROR:

Traceback (most recent call last):  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__    return self.wsgi_app(environ, start_response)  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app    response = self.handle_exception(e)  File "/Users/admin/rahul/lib/python3.6/site-packages/flask_restful/__init__.py", line 269, in error_router    return original_handler(e)  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception    reraise(exc_type, exc_value, tb)  File "/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise    raise value  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app    response = self.full_dispatch_request()  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request    rv = self.handle_user_exception(e)  File "/Users/admin/rahul/lib/python3.6/site-packages/flask_restful/__init__.py", line 269, in error_router    return original_handler(e)  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception    reraise(exc_type, exc_value, tb)  File "/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise    raise value  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request    rv = self.dispatch_request()  File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request    return self.view_functions[rule.endpoint](**req.view_args)  File "/Users/admin/Documents/Sentiment/Sentiment_Analysis/app.py", line 16, in post1    sent = get_sentiment(text)  File "/Users/admin/Documents/Sentiment/Sentiment_Analysis/sentiment.py", line 21, in get_sentiment    pred_sentiment = predict_sentiment(text,128,'tokenizer_convo_sentiment.pickle','convo_sentiement')  File "/Users/admin/Documents/Sentiment/Sentiment_Analysis/sentiment.py", line 16, in predict_sentiment    loaded_model = model_load(model_name)  File "/Users/admin/Documents/Sentiment/Sentiment_Analysis/load.py", line 14, in model_load    loaded_model = model_from_json(loaded_model_json)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/engine/saving.py", line 492, in model_from_json    return deserialize(config, custom_objects=custom_objects)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize    printable_module_name='layer')  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object    list(custom_objects.items())))  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/engine/network.py", line 1032, in from_config    process_node(layer, node_data)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/engine/network.py", line 991, in process_node    layer(unpack_singleton(input_tensors), **kwargs)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/engine/base_layer.py", line 457, in __call__    output = self.call(inputs, **kwargs)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/layers/core.py", line 299, in call    return self.activation(inputs)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/activations.py", line 31, in softmax    return K.softmax(x)  File "/Users/admin/rahul/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3231, in softmax    return tf.nn.softmax(x, axis=axis)

TypeError: softmax() got an unexpected keyword argument ‘axis’

Solution:

Upgrade your tensorflow and Keras libraries to latest versions.

lower versions don’t support the softmax axis.

Make sure you are upgrading them in the environment in which you are running the program (Very important thing).

pip install -U keras tensorflow

Method 2:

pip3 install --upgrade keras==2.1.3

Made it for me. Tensorflow version 1.4

Method 3:

You can add softmax layer in this fashion and will work:

First:

import tensorflow as tf

then, within your model definition:

model.add(Activation(tf.nn.softmax))