0
$\begingroup$

I hope this is the correct forum. I am going over the feature_column package of the TensorFlow [1] and have checked the code that generates a DNN using the feature_column. Assume that there is a dataset, named dataframe, with 11 attributes, most of the numeric a one categorical. Then, I go ahead and generate my feature_column list as following:

feature_columns = []
numeric_columns = ['age', 'trestbps', 'chol', 'thalach', 'oldpeak', 'slope', 'ca']
for header in numeric_columns:
# Create a numeric feature column  out of the header.
  numeric_feature_column = tf.feature_column.numeric_column(header)    
  feature_columns.append(numeric_feature_column)

age = tf.feature_column.numeric_column('age')
boundaries = [18, 25, 30, 35, 40, 45, 50, 55, 60, 65]
age_buckets = tf.feature_column.bucketized_column(age, boundaries)
feature_columns.append(age_buckets)

thal = tf.feature_column.categorical_column_with_vocabulary_list('thal', 
                  ['fixed', 'normal', 'reversible'])
thal_one_hot = tf.feature_column.indicator_column(thal)
feature_columns.append(thal_one_hot)

thal_embedding = tf.feature_column.embedding_column(thal, 8)
feature_columns.append(thal_embedding)

crossed_feature = tf.feature_column.crossed_column([age_buckets, thal],1000)
crossed_feature = tf.feature_column.indicator_column(crossed_feature)
feature_columns.append(crossed_feature)

# Create a Keras DenseFeatures layer and pass the feature_columns you just created.
feature_layer = tf.keras.layers.DenseFeatures(feature_columns)

# Create a DNN
model = tf.keras.Sequential([
    feature_layer,
    layers.Dense(128, activation='relu'),
    layers.Dense(128, activation='relu'),
    layers.Dense(1, activation='sigmoid')])

model.compile(optimizer='adam',
          loss='binary_crossentropy',
          metrics=['accuracy'])

The first dense layer has these weights' dimensions:

model.layers[1].trainable_variables[0].shape
> TensorShape([1029, 128])

I would like to understand how is the model-input built, and how the list "feature_column" is translated into 1029 dimenions. Does each element of the "feature_column" list generate an input dimension in the model, meaning, the bucketed, embedded layer, one-hot, crossed attributes, and single attributes (7 listed), each one enters the network? That is, e.g., age is used three times as single attributes, as bucketed and as crossed? Or, only the latest processed attributes (age is bucketed and then crossed with thal into a one-hot of 1000 dimensions) are the only attributes entering the network? How do I see the translated attributes into the entry data of the first dense layer and check for correlations among attributes?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.