Created
April 22, 2018 09:01
-
-
Save Swalloow/0eac510c6e2326ec31b784398d707efa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model: | |
def __init__(self, data, target): | |
self.data = data | |
self.target = target | |
self.prediction | |
self.optimize | |
self.error | |
@lazy_property | |
def prediction(self): | |
data_size = int(self.data.get_shape()[1]) | |
target_size = int(self.target.get_shape()[1]) | |
weight = tf.Variable(tf.truncated_normal([data_size, target_size])) | |
bias = tf.Variable(tf.constant(0.1, shape=[target_size])) | |
incoming = tf.matmul(self.data, weight) + bias | |
return tf.nn.softmax(incoming) | |
@lazy_property | |
def optimize(self): | |
cross_entropy = -tf.reduce_sum(self.target, tf.log(self.prediction)) | |
optimizer = tf.train.RMSPropOptimizer(0.03) | |
return optimizer.minimize(cross_entropy) | |
@lazy_property | |
def error(self): | |
mistakes = tf.not_equal( | |
tf.argmax(self.target, 1), tf.argmax(self.prediction, 1)) | |
return tf.reduce_mean(tf.cast(mistakes, tf.float32)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment