Search code examples
pythontensorflowgoogle-cloud-datalab

TensorFlow 1.5.0 run with DataLab raise AttributeError: 'Tensor' object has no attribute 'length' while attempting to use embedding_column


Attempt to use embedding_column in a way:

from tensorflow.contrib import layers // output = layers.embedding_column(input, 10, combiner='sum', max_norm=None)

result in error message:

{ File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/feature_column.py", line 1302, in embedding_column max_norm=max_norm, trainable=trainable) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/feature_column.py", line 1046, in new stddev = 1 / math.sqrt(sparse_id_column.length) AttributeError: 'Tensor' object has no attribute 'length' }

"input" is a column of integer values. Any ideas how to handle that?


Solution

  • It seems that your "input" argument is a Tensor while it should be a feature column and, more specifically, a sparse column created by sparse_column_with_* or weighted_sparse_column functions.