Last active
April 24, 2019 01:19
-
-
Save osipov/4805a1f1e2b214c5cf7c5c5e9a7879d6 to your computer and use it in GitHub Desktop.
This file contains 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
# Setup the model | |
x <- tf$placeholder(tf$float32, shape(NULL, 1024L)) | |
W <- tf$Variable(tf$zeros(shape(1024L, 10L))) | |
b <- tf$Variable(tf$zeros(shape(10L))) | |
t <- tf$nn$softmax(tf$matmul(x, W) + b) | |
# Specify the loss and optimizer | |
t_ <- tf$placeholder(tf$float32, shape(NULL, 10L)) | |
xent <- tf$reduce_mean(-tf$reduce_sum(t_ * log(t), reduction_indices=1L)) | |
batch_step <- tf$train$GradientDescentOptimizer(0.5)$minimize(xent) | |
titanic_train_ds <- csv_record_spec("titanic.train.csv") | |
# Train | |
for (i in 1:1000) { | |
batches <- tf$contrib$csv_batch$titanic_train_ds(100L) | |
batch_xs <- batches[[1]] | |
batch_ts <- batches[[2]] | |
sess$run(train_step, | |
feed_dict = dict(x = batch_xs, t_ = batch_ts)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment