q1_classifier.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:CS224n 作者: akash9182 项目源码 文件源码
def add_prediction_op(self):
        """Adds the core transformation for this model which transforms a batch of input
        data into a batch of predictions. In this case, the transformation is a linear layer plus a
        softmax transformation:

        y = softmax(Wx + b)

        Hint: Make sure to create tf.Variables as needed.
        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:
            pred: A tensor of shape (batch_size, n_classes)
        """
        ### YOUR CODE HERE
        W = tf.Variable(tf.zeros((self.config.n_features, self.config.n_classes)))
        b = tf.Variable(tf.zeros((self.config.n_classes)))
        pred = softmax(tf.matmul(self.input_placeholder, W) + b)

        ### END YOUR CODE
        return pred
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号