diff --git a/latest/apis/backends.html b/latest/apis/backends.html index 70a50de2..b7523f00 100644 --- a/latest/apis/backends.html +++ b/latest/apis/backends.html @@ -113,6 +113,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -140,7 +145,7 @@ Backends
  • - + diff --git a/latest/apis/batching.html b/latest/apis/batching.html index 7cd71c34..ecdb515e 100644 --- a/latest/apis/batching.html +++ b/latest/apis/batching.html @@ -118,6 +118,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -145,7 +150,7 @@ Batching
  • - + diff --git a/latest/contributing.html b/latest/contributing.html index 32631df3..6bf53d47 100644 --- a/latest/contributing.html +++ b/latest/contributing.html @@ -101,6 +101,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -126,7 +131,7 @@ Contributing & Help
  • - + @@ -159,7 +164,15 @@ starring the repo .

    -If you're interested in hacking on Flux, most of the code is pretty straightforward. Adding new layer definitions or cost functions is simple using the Flux DSL itself, and things like data utilities and training processes are all plain Julia code. The +If you're interested in hacking on Flux, most of the + +code + + is pretty straightforward. Adding new + +layer definitions + + or cost functions is simple using the Flux DSL itself, and things like data utilities and training processes are all plain Julia code. The compiler directory is a bit more involved and is documented in @@ -172,12 +185,12 @@ If you get stuck or need anything, let us know!

    diff --git a/latest/index.html b/latest/index.html index d89548ea..04eadf52 100644 --- a/latest/index.html +++ b/latest/index.html @@ -113,6 +113,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -137,7 +142,7 @@ Home
  • - + diff --git a/latest/internals.html b/latest/internals.html index 9f2cd7c7..ef6261ed 100644 --- a/latest/internals.html +++ b/latest/internals.html @@ -101,6 +101,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -126,7 +131,7 @@ Internals
  • - + diff --git a/latest/models/basics.html b/latest/models/basics.html index b21367d8..74e508a0 100644 --- a/latest/models/basics.html +++ b/latest/models/basics.html @@ -118,6 +118,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -145,7 +150,7 @@ Model Building Basics
  • - + diff --git a/latest/models/debugging.html b/latest/models/debugging.html index 38789fd9..91801c62 100644 --- a/latest/models/debugging.html +++ b/latest/models/debugging.html @@ -102,6 +102,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -129,7 +134,7 @@ Debugging
  • - + diff --git a/latest/models/recurrent.html b/latest/models/recurrent.html index 7f53986b..7eb21500 100644 --- a/latest/models/recurrent.html +++ b/latest/models/recurrent.html @@ -102,6 +102,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -129,7 +134,7 @@ Recurrence
  • - + diff --git a/latest/models/templates.html b/latest/models/templates.html index b5fa454d..7f23a390 100644 --- a/latest/models/templates.html +++ b/latest/models/templates.html @@ -118,6 +118,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • @@ -145,7 +150,7 @@ Model Templates
  • - + diff --git a/latest/search.html b/latest/search.html index 4c7cf95f..77629df4 100644 --- a/latest/search.html +++ b/latest/search.html @@ -101,6 +101,11 @@ In Action Logistic Regression +
  • + +Char RNN + +
  • diff --git a/latest/search_index.js b/latest/search_index.js index 22dc6f1a..7905bb47 100644 --- a/latest/search_index.js +++ b/latest/search_index.js @@ -232,6 +232,22 @@ var documenterSearchIndex = {"docs": [ "text": "This walkthrough example will take you through writing a multi-layer perceptron that classifies MNIST digits with high accuracy.First, we load the data using the MNIST package:using Flux, MNIST\n\ndata = [(trainfeatures(i), onehot(trainlabel(i), 0:9)) for i = 1:60_000]\ntrain = data[1:50_000]\ntest = data[50_001:60_000]The only Flux-specific function here is onehot, which takes a class label and turns it into a one-hot-encoded vector that we can use for training. For example:julia> onehot(:b, [:a, :b, :c])\n3-element Array{Int64,1}:\n 0\n 1\n 0Otherwise, the format of the data is simple enough, it's just a list of tuples from input to output. For example:julia> data[1]\n([0.0,0.0,0.0, … 0.0,0.0,0.0],[0,0,0,0,0,1,0,0,0,0])data[1][1] is a 28*28 == 784 length vector (mostly zeros due to the black background) and data[1][2] is its classification.Now we define our model, which will simply be a function from one to the other.m = Chain(\n Input(784),\n Affine(128), relu,\n Affine( 64), relu,\n Affine( 10), softmax)\n\nmodel = tf(model)We can try this out on our data already:julia> model(data[1][1])\n10-element Array{Float64,1}:\n 0.10614 \n 0.0850447\n 0.101474\n ...The model gives a probability of about 0.1 to each class – which is a way of saying, \"I have no idea\". This isn't too surprising as we haven't shown it any data yet. This is easy to fix:Flux.train!(model, train, test, η = 1e-4)The training step takes about 5 minutes (to make it faster we can do smarter things like batching). If you run this code in Juno, you'll see a progress meter, which you can hover over to see the remaining computation time.Towards the end of the training process, Flux will have reported that the accuracy of the model is now about 90%. We can try it on our data again:10-element Array{Float32,1}:\n ...\n 5.11423f-7\n 0.9354 \n 3.1033f-5 \n 0.000127077\n ...Notice the class at 93%, suggesting our model is very confident about this image. We can use onecold to compare the true and predicted classes:julia> onecold(data[1][2], 0:9)\n5\n\njulia> onecold(model(data[1][1]), 0:9)\n5Success!" }, +{ + "location": "examples/char-rnn.html#", + "page": "Char RNN", + "title": "Char RNN", + "category": "page", + "text": "" +}, + +{ + "location": "examples/char-rnn.html#Char-RNN-1", + "page": "Char RNN", + "title": "Char RNN", + "category": "section", + "text": "using Flux\nimport StatsBase: wsample\n\nnunroll = 50\nnbatch = 50\n\ngetseqs(chars, alphabet) = sequences((onehot(Float32, char, alphabet) for char in chars), nunroll)\ngetbatches(chars, alphabet) = batches((getseqs(part, alphabet) for part in chunk(chars, nbatch))...)\n\ninput = readstring(\"$(homedir())/Downloads/shakespeare_input.txt\")\nalphabet = unique(input)\nN = length(alphabet)\n\nXs, Ys = getbatches(input, alphabet), getbatches(input[2:end], alphabet)\n\nbasemodel = Chain(\n Input(N),\n LSTM(N, 256),\n LSTM(256, 256),\n Affine(256, N),\n softmax)\n\nmodel = Chain(basemodel, softmax)\n\nm = tf(unroll(model, nunroll))\n\n@time Flux.train!(m, Xs, Ys, η = 0.1, epoch = 1)\n\nfunction sample(model, n, temp = 1)\n s = [rand(alphabet)]\n m = tf(unroll(model, 1))\n for i = 1:n\n push!(s, wsample(alphabet, softmax(m(Seq((onehot(Float32, s[end], alphabet),)))[1]./temp)))\n end\n return string(s...)\nend\n\nsample(basemodel, 100)" +}, + { "location": "contributing.html#", "page": "Contributing & Help",