Giter Club home page Giter Club logo

twitter-sentiment-analysis's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

twitter-sentiment-analysis's Issues

ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(20000, 200), dtype=float32)'

I follow the instructions and get this error, can you please help?

[root@localhost sentiment]# echo "This is a sample tweet to predict on" | python predict.py
Using TensorFlow backend.
/usr/lib/python2.7/site-packages/keras/preprocessing/text.py:139: UserWarning: The nb_words argument in Tokenizer has been renamed num_words.
warnings.warn('The nb_words argument in Tokenizer '
/usr/lib/python2.7/site-packages/keras/engine/topology.py:1242: UserWarning: The dropout argument is no longer support in Embedding. You can apply a keras.layers.SpatialDropout1D layer right after the Embedding layer to get the same behavior.
return cls(**config)
/usr/lib/python2.7/site-packages/keras/engine/topology.py:1242: UserWarning: Update your Embedding call to the Keras 2 API: Embedding(embeddings_initializer="uniform", trainable=False, name="embedding_1", output_dim=200, activity_regularizer=None, embeddings_regularizer=None, input_dtype="int32", embeddings_constraint=None, mask_zero=False, input_dim=20000, batch_input_shape=[None, 100..., input_length=1000)
return cls(**config)
Traceback (most recent call last):
File "predict.py", line 41, in
main()
File "predict.py", line 20, in main
model = load_model('model.h5')
File "/usr/lib/python2.7/site-packages/keras/models.py", line 233, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/usr/lib/python2.7/site-packages/keras/models.py", line 307, in model_from_config
return layer_module.deserialize(config, custom_objects=custom_objects)
File "/usr/lib/python2.7/site-packages/keras/layers/init.py", line 54, in deserialize
printable_module_name='layer')
File "/usr/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object
list(custom_objects.items())))
File "/usr/lib/python2.7/site-packages/keras/models.py", line 1210, in from_config
model.add(layer)
File "/usr/lib/python2.7/site-packages/keras/models.py", line 436, in add
layer(x)
File "/usr/lib/python2.7/site-packages/keras/engine/topology.py", line 569, in call
self.build(input_shapes[0])
File "/usr/lib/python2.7/site-packages/keras/layers/embeddings.py", line 101, in build
dtype=self.dtype)
File "/usr/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
return func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/keras/engine/topology.py", line 391, in add_weight
weight = K.variable(initializer(shape), dtype=dtype, name=name)
File "/usr/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 321, in variable
v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 200, in init
expected_shape=expected_shape)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 289, in _init_from_args
initial_value, name="initial_value", dtype=dtype)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 676, in convert_to_tensor
as_ref=False)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 741, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 614, in _TensorTensorConversionFunction
% (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(20000, 200), dtype=float32)'

I have these packages installed:
[root@localhost sentiment]# pip list -l
backports.ssl-match-hostname (3.4.0.2)
backports.weakref (1.0rc1)
bleach (1.5.0)
blivet (0.61.15.59)
Brlapi (0.6.0)
cffi (1.6.0)
chardet (2.2.1)
configobj (4.7.2)
configshell-fb (1.1.18)
coverage (3.6b3)
cryptography (1.3.1)
cupshelpers (1.0)
custodia (0.1.0)
decorator (3.4.0)
di (0.3)
dnspython (1.12.0)
enum34 (1.0.4)
ethtool (0.8)
firstboot (19.5)
fros (1.0)
funcsigs (1.0.2)
gssapi (1.2.0)
h5py (2.7.0)
html5lib (0.9999999)
idna (2.0)
iniparse (0.4)
initial-setup (0.3.9.36)
ipaclient (4.4.0)
ipaddress (1.0.16)
ipalib (4.4.0)
ipaplatform (4.4.0)
ipapython (4.4.0)
IPy (0.75)
javapackages (1.0.0)
jwcrypto (0.2.1)
Keras (2.0.6)
kitchen (1.1.1)
kmod (0.1)
langtable (0.0.31)
lxml (3.2.1)
Markdown (2.6.8)
mock (2.0.0)
netaddr (0.7.5)
netifaces (0.10.4)
ntplib (0.3.2)
numpy (1.13.1)
pbr (3.1.1)
perf (0.1)
pip (8.1.2)
ply (3.4)
policycoreutils-default-encoding (0.1)
protobuf (3.3.0)
pyasn1 (0.1.9)
pycparser (2.14)
pycups (1.9.63)
pycurl (7.19.0)
pygobject (3.14.0)
pygpgme (0.3)
pyinotify (0.9.4)
pykickstart (1.99.66.10)
pyliblzma (0.5.3)
pyOpenSSL (0.13.1)
pyparsing (1.5.6)
pyparted (3.9)
pysmbc (1.0.13)
python-augeas (0.5.0)
python-dateutil (1.5)
python-dmidecode (3.10.13)
python-ldap (2.4.15)
python-meh (0.25.2)
python-nss (0.16.0)
python-yubico (1.2.3)
pytz (2016.6.1)
pyudev (0.15)
pyusb (1.0.0b1)
pyxattr (0.5.1)
PyYAML (3.12)
qrcode (5.0.1)
requests (2.6.0)
rtslib-fb (2.1.57)
scikit-learn (0.18.2)
scipy (0.19.1)
seobject (0.1)
sepolicy (1.1)
setroubleshoot (1.1)
setuptools (0.9.8)
six (1.10.0)
sklearn (0.0)
slip (0.4.0)
slip.dbus (0.4.0)
SSSDConfig (1.14.0)
targetcli-fb (2.1.fb41)
tensorflow (1.2.1)
Theano (0.9.0)
urlgrabber (3.10)
urllib3 (1.10.2)
urwid (1.1.1)
Werkzeug (0.12.2)
wheel (0.29.0)
yum-langpacks (0.4.2)
yum-metadata-parser (1.1.4)
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)

I get following error trying to train the model:

C:\Users\JK186034\Documents\Py\sentiment> python train.py
Using TensorFlow backend.
Traceback (most recent call last):
File "train.py", line 159, in
main()
File "train.py", line 39, in main
word_index, x_train, x_val, y_train, y_val = get_training_and_validation_set
s()
File "train.py", line 49, in get_training_and_validation_sets
X_raw, Y_raw = load_data_set()
File "train.py", line 140, in load_data_set
for i, line in enumerate(reader):
_csv.Error: iterator should return strings, not bytes (did you open the file in
text mode?)

I am running this on anaconda under windows:
C:\Users\JK186034\Documents\Py\sentiment>python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1
900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(20000, 200), dtype=float32)'

When I run your code I get this error:

[jalal@goku twitter-sentiment-analysis]$  echo "This is a sample tweet to predict on" | python predict.py
Using TensorFlow backend.
2018-03-03 22:15:52.298930: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-03-03 22:15:52.298964: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-03-03 22:15:52.298974: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-03-03 22:15:52.298981: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-03-03 22:15:52.298987: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2018-03-03 22:15:52.521523: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 0 with properties: 
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.6705
pciBusID 0000:05:00.0
Total memory: 10.92GiB
Free memory: 9.92GiB
2018-03-03 22:15:52.742797: W tensorflow/stream_executor/cuda/cuda_driver.cc:523] A non-primary context 0x5626add8a580 exists before initializing the StreamExecutor. We haven't verified StreamExecutor works with that.
2018-03-03 22:15:52.743474: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 1 with properties: 
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.6705
pciBusID 0000:06:00.0
Total memory: 10.92GiB
Free memory: 10.76GiB
2018-03-03 22:15:52.744161: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0 1 
2018-03-03 22:15:52.744178: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0:   Y Y 
2018-03-03 22:15:52.744185: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 1:   Y Y 
2018-03-03 22:15:52.744197: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:05:00.0)
2018-03-03 22:15:52.744206: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:06:00.0)
/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/preprocessing/text.py:145: UserWarning: The `nb_words` argument in `Tokenizer` has been renamed `num_words`.
  warnings.warn('The `nb_words` argument in `Tokenizer` '
/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/engine/topology.py:1253: UserWarning: The `dropout` argument is no longer support in `Embedding`. You can apply a `keras.layers.SpatialDropout1D` layer right after the `Embedding` layer to get the same behavior.
  return cls(**config)
/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/engine/topology.py:1253: UserWarning: Update your `Embedding` call to the Keras 2 API: `Embedding(trainable=False, name="embedding_1", activity_regularizer=None, input_dtype="int32", mask_zero=False, input_dim=20000, batch_input_shape=[None, 100..., output_dim=200, input_length=1000, embeddings_initializer="uniform", embeddings_regularizer=None, embeddings_constraint=None)`
  return cls(**config)
Traceback (most recent call last):
  File "predict.py", line 41, in <module>
    main()
  File "predict.py", line 20, in main
    model = load_model('model.h5')
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/models.py", line 239, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/models.py", line 313, in model_from_config
    return layer_module.deserialize(config, custom_objects=custom_objects)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object
    list(custom_objects.items())))
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/models.py", line 1249, in from_config
    model.add(layer)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/models.py", line 442, in add
    layer(x)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/engine/topology.py", line 576, in __call__
    self.build(input_shapes[0])
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/layers/embeddings.py", line 101, in build
    dtype=self.dtype)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/engine/topology.py", line 400, in add_weight
    constraint=constraint)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 376, in variable
    v = tf.Variable(value, dtype=tf.as_dtype(dtype), name=name)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 199, in __init__
    expected_shape=expected_shape)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 289, in _init_from_args
    initial_value, name="initial_value", dtype=dtype)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 611, in convert_to_tensor
    as_ref=False)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 676, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 549, in _TensorTensorConversionFunction
    % (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(20000, 200), dtype=float32)'
[jalal@goku twitter-sentiment-analysis]$ 

How should I fix it?

doubt regarding files used

As "model.save(model.h5)" in line 63 of train.py already has architecture of the model and its weights, what is the use of creating a seperate weights.h5 file?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.