forked from rstudio/keras3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
98 lines (63 loc) · 4.43 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: "R interface to Keras"
---
```{r setup, include=FALSE}
library(keras)
# generate dummy training data
x_train <- matrix(rexp(1000*100), nrow = 1000, ncol = 100)
y_train <- matrix(round(runif(1000*10, min = 0, max = 9)), nrow = 1000, ncol = 10)
# genereate dummy input data
x_test <- matrix(rexp(10*100), nrow = 10, ncol = 100)
y_test <- matrix(round(runif(10*10, min = 0, max = 9)), nrow = 10, ncol = 10)
```
# R interface to Keras
[Keras](https://keras.io/) is a high-level neural networks API developed with a focus on enabling fast experimentation. *Being able to go from idea to result with the least possible delay is key to doing good research.* Use Keras if you need a deep learning library that:
- Allows for easy and fast prototyping (through user friendliness, modularity, and extensibility).
- Supports both convolutional networks and recurrent networks, as well as combinations of the two.
- Runs seamlessly on CPU and GPU.
## Getting started: 30 seconds to Keras
The core data structure of Keras is a **model**, a way to organize layers. The simplest type of model is the Sequential model, a linear stack of layers. For more complex architectures, you should use the Keras functional API, which allows to build arbitrary graphs of layers.
Here is the Sequential model:
```{r}
library(keras)
model <- keras_model_sequential()
model %>%
layer_dense(units = 64, input_shape = 100) %>%
layer_activation(activation = 'relu') %>%
layer_dense(units = 10) %>%
layer_activation(activation = 'softmax') %>%
compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_sgd(lr = 0.02),
metrics = c('accuracy')
)
```
You can now iterate on your training data in batches (`x_train` and `y_train` are R matrices):
```{r, results='hide'}
model %>% fit(x_train, y_train, epochs = 5, batch_size = 32)
```
Evaluate your performance in one line:
```{r, results = 'hide'}
loss_and_metrics <- model %>% evaluate(x_test, y_test, batch_size = 128)
```
Or generate predictions on new data:
```{r, results = 'hide'}
classes <- model %>% predict(x_test, batch_size = 128)
```
Building a question answering system, an image classification model, a Neural Turing Machine, or any other model is just as fast. The ideas behind deep learning are simple, so why should their implementation be painful?
To learn more about Keras, you can check out these articles:
- [Guide to the Sequential Model](articles/sequential_model.html)
- [Guide to the Functional API](articles/functional_api.html)
- [Frequently Asked Questions](articles/faq.html)
The [examples](articles/examples) demonstrate more advanced models including transfer learning, variational auto-encoding, question-answering with memory networks, text generation with stacked LSTMs, etc.
The [function reference](reference/index.html) includes detailed information on all of the functions available in the package.
## Installation
1. The R interface to Keras uses [TensorFlow](https://rstudio.github.io/tensorflow/) as it's underlying computation engine. Therefore, you need to install TensorFlow (version 1.1 or higher) before using the package. Instructions for installing TensorFlow are here: <https://www.tensorflow.org/install/>.
2. Then, install the Keras R package from GitHub:
```r
devtools::install_github("rstudio/keras")
```
## Why this name, Keras?
Keras (κέρας) means horn in Greek. It is a reference to a literary image from ancient Greek and Latin literature, first found in the Odyssey, where dream spirits (Oneiroi, singular Oneiros) are divided between those who deceive men with false visions, who arrive to Earth through a gate of ivory, and those who announce a future that will come to pass, who arrive through a gate of horn. It's a play on the words κέρας (horn) / κραίνω (fulfill), and ἐλέφας (ivory) / ἐλεφαίρομαι (deceive).
Keras was initially developed as part of the research effort of project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System).
> "Oneiroi are beyond our unravelling --who can be sure what tale they tell? Not all that men look for comes to pass. Two gates there are that give passage to fleeting Oneiroi; one is made of horn, one of ivory. The Oneiroi that pass through sawn ivory are deceitful, bearing a message that will not be fulfilled; those that come out through polished horn have truth behind them, to be accomplished for men who see them." Homer, Odyssey 19. 562 ff (Shewring translation).