Created
September 6, 2018 22:06
-
-
Save siero5335/263cc8cb1e0710809a33799303800288 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
# Reference: https://github.com/jjallaire/deep-learning-with-r-notebooks | |
library(keras) | |
use_backend(backend = "plaidml") | |
# 6-1 original ver | |
# get_layer(model, index = 2) %>% | |
# set_weights(list(embedding_matrix)) %>% | |
# freeze_weights() | |
# 6-1 plaidML ver | |
# index = 1のままだとembedding_matrixの頭が全部0なので動かない | |
get_layer(model, index = 2) %>% | |
set_weights(list(embedding_matrix)) %>% | |
freeze_weights() | |
# 6-2 original ver | |
# model <- keras_model_sequential() %>% | |
# layer_embedding(input_dim = 10000, output_dim = 32) %>% | |
# layer_simple_rnn(units = 32) # This last layer only returns the last outputs. | |
# summary(model) | |
# 6-2 plaidML ver | |
# input_length = XX を指定しないと動かない。 | |
# このコード以降全て同様 | |
library(keras) | |
use_backend(backend = "plaidml") | |
model <- keras_model_sequential() %>% | |
layer_embedding(input_dim = 10000, output_dim = 32, input_length = 32) %>% | |
layer_simple_rnn(units = 32) | |
summary(model) | |
# 6-2 original ver | |
# model <- keras_model_sequential() %>% | |
# layer_embedding(input_dim = max_features, output_dim = 32) %>% | |
# layer_simple_rnn(units = 32) %>% | |
# layer_dense(units = 1, activation = "sigmoid") | |
# | |
# 6-2 plaidML ver | |
# input_length = maxlenを指定, rnnだけじゃなくlstmも同様 | |
model <- keras_model_sequential() %>% | |
layer_embedding(input_dim = max_features, output_dim = 32, input_length = maxlen) %>% | |
layer_simple_rnn(units = 32) %>% | |
layer_dense(units = 1, activation = "sigmoid") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment