text_plain_output_1.png
import tensorflow as tf

import tensorflow.keras.layers as L

import tensorflow.keras.models as M

FE = ['content_emb', 'user_emb', 'duration', 'prior_answer']
TARGET = 'answered_correctly'

x = tr_preprocessed.loc[tr_preprocessed.answered_correctly != -1, FE].values
y = tr_preprocessed.loc[tr_preprocessed.answered_correctly != -1, TARGET].values

tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)

tpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)

with tpu_strategy.scope():
    def make_ann(n_in):
        inp = L.Input(shape=(n_in,), name='inp')
        d1 = L.Dense(100, activation='relu', name='d1')(inp)
        d2 = L.Dense(100, activation='relu', name='d2')(d1)
        preds = L.Dense(1, activation='sigmoid', name='preds')(d2)
        model = M.Model(inp, preds, name='ANN')
        model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
        return model

net = make_ann(x.shape[1])

net.fit(x, y, validation_split=0.2, batch_size=30000, epochs=1)