def add_model(self, input_data):
"""Adds a linear-layer plus a softmax transformation
The core transformation for this model which transforms a batch of input
data into a batch of predictions. In this case, the mathematical
transformation effected is
y = softmax(xW + b)
Hint: Make sure to create tf.Variables as needed. Also, make sure to use
tf.name_scope to ensure that your name spaces are clean.
Hint: For this simple use-case, it's sufficient to initialize both weights W
and biases b with zeros.
Args:
input_data: A tensor of shape (batch_size, n_features).
Returns:
out: A tensor of shape (batch_size, n_classes)
"""
### YOUR CODE HERE
with tf.name_scope('linear_layer'):
W = tf.Variable(np.zeros((self.config.n_features,
self.config.n_classes)).astype(np.float32))
b = tf.Variable(np.zeros((self.config.n_classes,)).astype(np.float32))
out = softmax(tf.matmul(input_data, W) + b)
### END YOUR CODE
return out
评论列表
文章目录