I am doing Stanford's CS224n course. I get an error in assignment2 q2_parser_model.py in my dependency parser
== Initializing==
Loading data... took 2.17 seconds
Building parser... took 0.04 seconds
Loading pretrained embeddings... took 2.16 seconds
Vectorizing data... took 0.06 seconds
Preprocessing training data...
1000/1000 [==============================] - 1s
Building model...
Traceback (most recent call last):
File "q2_parser_model.py", line 286, in <module>
main()
File "q2_parser_model.py", line 252, in main
model = ParserModel(config, embeddings)
File "q2_parser_model.py", line 237, in __init__
self.build()
File "/home/jarvis/My projects/Machine Learning/CS224n/My assignments/assignment2/model.py", line 109, in build
self.pred = self.add_prediction_op()
File "q2_parser_model.py", line 149, in add_prediction_op
x = self.add_embedding()
File "q2_parser_model.py", line 119, in add_embedding
features = tf.nn.embedding_lookup(embedding, self.input_placeholder)
File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/embedding_ops.py", line 110, in embedding_lookup
validate_indices=validate_indices)
File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1293, in gather
validate_indices=validate_indices, name=name)
File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 582, in apply_op
_Attr(op_def, input_arg.type_attr))
File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: DataType float32 for attr 'Tindices' not in list of allowed values: int32, int64
Following is the code snippet and line where I am getting error
def add_embedding(self):
embedding = tf.Variable(self.pretrained_embeddings, name = "embedding")
--> features = tf.nn.embedding_lookup(embedding, self.input_placeholder)
embeddings = tf.reshape(features, [-1, self.config.n_features *
self.config.embedding_size])
### END YOUR CODE
return embeddings
I got my mistake, it was due to an improper datatype definition. I defined a placeholder as float32 instead of int32
Your
self.input_placeholder
must be passed totf.nn.embedding_lookup
as an array ofint32
orint64
, so you could just: