TensorFlow-功能列-AttributeError:对象没有属性“长度”

时间:2018-12-26 16:26:15

标签: python tensorflow tensorflow-estimator

我正在尝试将单词索引添加到自定义估算器的功能列。这是我所拥有的:

模型功能:

def model_function(features, labels, mode, params):    
    word_categorical_column = tf.feature_column.categorical_column_with_identity(key="word_column", num_buckets=10000)
    feature_columns = [tf.contrib.layers.embedding_column(word_categorical_column, 64)]
    input = tf.feature_column.input_layer(features, feature_columns )
    ...

估算器:

estimator = tf.estimator.Estimator(
    model_fn=model_function,
    model_dir = model_directory,
    params={
        'n_classes': 5,
    })

输入功能:

def input_fntn(train_x, train_y, batch_size):
    dataset = tf.data.Dataset.from_tensor_slices(({"word_column":train_x}, train_y))
    dataset = dataset.shuffle(1000).repeat().batch(batch_size)
    return dataset

train_x是一个包含填充单词索引的numpy数组[n_samples,n_features]。

运行训练方法:

estimator.train(
    input_fn=lambda:input_fntn(train_x, train_y, 128),
    steps=100)

产生错误: AttributeError:“ _ IdentityCategoricalColumn”对象没有属性“ length”

我尝试改用categorical_column_with_vocabulary_list,但是会导致相同的错误。我想我犯了一些基本错误。任何帮助将不胜感激。

0 个答案:

没有答案