From c0ea1580e2a676f15f5e4bab549c8fef6d087770 Mon Sep 17 00:00:00 2001 From: autodocs Date: Wed, 18 Oct 2017 14:33:23 +0000 Subject: [PATCH] build based on fd249b7 --- latest/community.html | 2 +- latest/data/onehot.html | 2 +- latest/gpu.html | 2 +- latest/index.html | 2 +- latest/models/basics.html | 2 +- latest/models/layers.html | 10 ++++++---- latest/models/recurrence.html | 4 ++-- latest/search.html | 2 +- latest/search_index.js | 34 ++++++++++++++++++++------------- latest/training/optimisers.html | 4 ++-- latest/training/training.html | 2 +- 11 files changed, 38 insertions(+), 28 deletions(-) diff --git a/latest/community.html b/latest/community.html index 81bee480..554f3857 100644 --- a/latest/community.html +++ b/latest/community.html @@ -6,4 +6,4 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

Community

Community

All Flux users are welcome to join our community on the Julia forum, the slack (channel #machine-learning), or Flux's Gitter. If you have questions or issues we'll try to help you out.

If you're interested in hacking on Flux, the source code is open and easy to understand – it's all just the same Julia code you work with normally. You might be interested in our intro issues to get started.

+

Community

Community

All Flux users are welcome to join our community on the Julia forum, the slack (channel #machine-learning), or Flux's Gitter. If you have questions or issues we'll try to help you out.

If you're interested in hacking on Flux, the source code is open and easy to understand – it's all just the same Julia code you work with normally. You might be interested in our intro issues to get started.

diff --git a/latest/data/onehot.html b/latest/data/onehot.html index 88cf15ca..1c609bf5 100644 --- a/latest/data/onehot.html +++ b/latest/data/onehot.html @@ -6,7 +6,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

One-Hot Encoding

One-Hot Encoding

It's common to encode categorical variables (like true, false or cat, dog) in "one-of-k" or "one-hot" form. Flux provides the onehot function to make this easy.

julia> using Flux: onehot
+

One-Hot Encoding

One-Hot Encoding

It's common to encode categorical variables (like true, false or cat, dog) in "one-of-k" or "one-hot" form. Flux provides the onehot function to make this easy.

julia> using Flux: onehot
 
 julia> onehot(:b, [:a, :b, :c])
 3-element Flux.OneHotVector:
diff --git a/latest/gpu.html b/latest/gpu.html
index c66b2b8e..3238787a 100644
--- a/latest/gpu.html
+++ b/latest/gpu.html
@@ -6,7 +6,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
 
 ga('create', 'UA-36890222-9', 'auto');
 ga('send', 'pageview');
-

GPU Support

GPU Support

Support for array operations on other hardware backends, like GPUs, is provided by external packages like CuArrays and CLArrays. Flux doesn't care what array type you use, so we can just plug these in without any other changes.

For example, we can use CuArrays (with the cu converter) to run our basic example on an NVIDIA GPU.

using CuArrays
+

GPU Support

GPU Support

Support for array operations on other hardware backends, like GPUs, is provided by external packages like CuArrays and CLArrays. Flux doesn't care what array type you use, so we can just plug these in without any other changes.

For example, we can use CuArrays (with the cu converter) to run our basic example on an NVIDIA GPU.

using CuArrays
 
 W = cu(rand(2, 5)) # a 2×5 CuArray
 b = cu(rand(2))
diff --git a/latest/index.html b/latest/index.html
index 97873719..b9248ded 100644
--- a/latest/index.html
+++ b/latest/index.html
@@ -6,5 +6,5 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
 
 ga('create', 'UA-36890222-9', 'auto');
 ga('send', 'pageview');
-

Home

Flux: The Julia Machine Learning Library

Flux is a library for machine learning. It comes "batteries-included" with many useful tools built in, but also lets you use the full power of the Julia language where you need it. The whole stack is implemented in clean Julia code (right down to the GPU kernels) and any part can be tweaked to your liking.

Installation

Install Julia 0.6.0 or later, if you haven't already.

Pkg.add("Flux")
+

Home

Flux: The Julia Machine Learning Library

Flux is a library for machine learning. It comes "batteries-included" with many useful tools built in, but also lets you use the full power of the Julia language where you need it. The whole stack is implemented in clean Julia code (right down to the GPU kernels) and any part can be tweaked to your liking.

Installation

Install Julia 0.6.0 or later, if you haven't already.

Pkg.add("Flux")
 Pkg.test("Flux") # Check things installed correctly

Start with the basics. The model zoo is also a good starting point for many common kinds of models.

diff --git a/latest/models/basics.html b/latest/models/basics.html index ec97d6f6..d70ca15e 100644 --- a/latest/models/basics.html +++ b/latest/models/basics.html @@ -6,7 +6,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

Basics

Model-Building Basics

Taking Gradients

Consider a simple linear regression, which tries to predict an output array y from an input x. (It's a good idea to follow this example in the Julia repl.)

W = rand(2, 5)
+

Basics

Model-Building Basics

Taking Gradients

Consider a simple linear regression, which tries to predict an output array y from an input x. (It's a good idea to follow this example in the Julia repl.)

W = rand(2, 5)
 b = rand(2)
 
 predict(x) = W*x .+ b
diff --git a/latest/models/layers.html b/latest/models/layers.html
index 79da5315..cb85de10 100644
--- a/latest/models/layers.html
+++ b/latest/models/layers.html
@@ -1,20 +1,22 @@
 
-Layer Reference · Flux

Layer Reference

Model Layers

These core layers form the foundation of almost all neural networks.

Flux.ChainType.
Chain(layers...)

Chain multiple layers / functions together, so that they are called in sequence on a given input.

m = Chain(x -> x^2, x -> x+1)
+

Model Reference

Layers

These core layers form the foundation of almost all neural networks.

Flux.ChainType.
Chain(layers...)

Chain multiple layers / functions together, so that they are called in sequence on a given input.

m = Chain(x -> x^2, x -> x+1)
 m(5) == 26
 
 m = Chain(Dense(10, 5), Dense(5, 2))
 x = rand(10)
-m(x) == m[2](m[1](x))

Chain also supports indexing and slicing, e.g. m[2] or m[1:end-1]. m[1:3](x) will calculate the output of the first three layers.

source
Flux.DenseType.
Dense(in::Integer, out::Integer, σ = identity)

Creates a traditional Dense layer with parameters W and b.

y = σ.(W * x .+ b)

The input x must be a vector of length in, or a batch of vectors represented as an in × N matrix. The out y will be a vector or batch of length out.

julia> d = Dense(5, 2)
+m(x) == m[2](m[1](x))

Chain also supports indexing and slicing, e.g. m[2] or m[1:end-1]. m[1:3](x) will calculate the output of the first three layers.

source
Flux.DenseType.
Dense(in::Integer, out::Integer, σ = identity)

Creates a traditional Dense layer with parameters W and b.

y = σ.(W * x .+ b)

The input x must be a vector of length in, or a batch of vectors represented as an in × N matrix. The out y will be a vector or batch of length out.

julia> d = Dense(5, 2)
 Dense(5, 2)
 
 julia> d(rand(5))
 Tracked 2-element Array{Float64,1}:
   0.00257447
-  -0.00449443
source

Activation Functions

Non-linearities that go between layers of your model. Most of these functions are defined in NNlib but are available by default in Flux.

Note that, unless otherwise stated, activation functions operate on scalars. To apply them to an array you can call σ.(xs), relu.(xs) and so on.

NNlib.σFunction.
σ(x) = 1 / (1 + exp(-x))

Classic sigmoid activation function.

source
NNlib.reluFunction.
relu(x) = max(0, x)

Rectified Linear Unit activation function.

source
NNlib.leakyreluFunction.
leakyrelu(x) = max(0.01x, x)

Leaky Rectified Linear Unit activation function.

You can also specify the coefficient explicitly, e.g. leakyrelu(x, 0.01).

source
NNlib.eluFunction.
elu(x; α = 1) = x > 0 ? x : α * (exp(x) - one(x)

Exponential Linear Unit activation function. See Fast and Accurate Deep Network Learning by Exponential Linear Units

source
NNlib.swishFunction.
swish(x) = x * σ(x)

Self-gated actvation function.

See Swish: a Self-Gated Activation Function.

source
+ -0.00449443
source

Recurrent Cells

Much like the core layers above, but can be used to process sequence data (as well as other kinds of structured data).

RNN
+LSTM
+Recur

Activation Functions

Non-linearities that go between layers of your model. Most of these functions are defined in NNlib but are available by default in Flux.

Note that, unless otherwise stated, activation functions operate on scalars. To apply them to an array you can call σ.(xs), relu.(xs) and so on.

NNlib.σFunction.
σ(x) = 1 / (1 + exp(-x))

Classic sigmoid activation function.

source
NNlib.reluFunction.
relu(x) = max(0, x)

Rectified Linear Unit activation function.

source
NNlib.leakyreluFunction.
leakyrelu(x) = max(0.01x, x)

Leaky Rectified Linear Unit activation function.

You can also specify the coefficient explicitly, e.g. leakyrelu(x, 0.01).

source
NNlib.eluFunction.
elu(x; α = 1) = x > 0 ? x : α * (exp(x) - one(x)

Exponential Linear Unit activation function. See Fast and Accurate Deep Network Learning by Exponential Linear Units

source
NNlib.swishFunction.
swish(x) = x * σ(x)

Self-gated actvation function.

See Swish: a Self-Gated Activation Function.

source
diff --git a/latest/models/recurrence.html b/latest/models/recurrence.html index 871bae8c..9b2eb2d9 100644 --- a/latest/models/recurrence.html +++ b/latest/models/recurrence.html @@ -6,7 +6,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

Recurrence

Recurrent Models

Recurrent Cells

In the simple feedforward case, our model m is a simple function from various inputs xᵢ to predictions yᵢ. (For example, each x might be an MNIST digit and each y a digit label.) Each prediction is completely independent of any others, and using the same x will always produce the same y.

y₁ = f(x₁)
+

Recurrence

Recurrent Models

Recurrent Cells

In the simple feedforward case, our model m is a simple function from various inputs xᵢ to predictions yᵢ. (For example, each x might be an MNIST digit and each y a digit label.) Each prediction is completely independent of any others, and using the same x will always produce the same y.

y₁ = f(x₁)
 y₂ = f(x₂)
 y₃ = f(x₃)
 # ...

Recurrent networks introduce a hidden state that gets carried over each time we run the model. The model now takes the old h as an input, and produces a new h as output, each time we run it.

h = # ... initial state ...
@@ -39,4 +39,4 @@ m = Flux.Recur(rnn, h)
 
 y = m(x)

The Recur wrapper stores the state between runs in the m.state field.

If you use the RNN(10, 5) constructor – as opposed to RNNCell – you'll see that it's simply a wrapped cell.

julia> RNN(10, 5)
 Recur(RNNCell(Dense(15, 5)))

Sequences

Often we want to work with sequences of inputs, rather than individual xs.

seq = [rand(10) for i = 1:10]

With Recur, applying our model to each element of a sequence is trivial:

m.(seq) # returns a list of 5-element vectors

This works even when we've chain recurrent layers into a larger model.

m = Chain(LSTM(10, 15), Dense(15, 5))
-m.(seq)

Truncating Gradients

By default, calculating the gradients in a recurrent layer involves the entire history. For example, if we call the model on 100 inputs, calling back! will calculate the gradient for those 100 calls. If we then calculate another 10 inputs we have to calculate 110 gradients – this accumulates and quickly becomes expensive.

To avoid this we can truncate the gradient calculation, forgetting the history.

truncate!(m)

Calling truncate! wipes the slate clean, so we can call the model with more inputs without building up an expensive gradient computation.

+m.(seq)

Truncating Gradients

By default, calculating the gradients in a recurrent layer involves the entire history. For example, if we call the model on 100 inputs, calling back! will calculate the gradient for those 100 calls. If we then calculate another 10 inputs we have to calculate 110 gradients – this accumulates and quickly becomes expensive.

To avoid this we can truncate the gradient calculation, forgetting the history.

truncate!(m)

Calling truncate! wipes the slate clean, so we can call the model with more inputs without building up an expensive gradient computation.

diff --git a/latest/search.html b/latest/search.html index af1c20e5..704545f3 100644 --- a/latest/search.html +++ b/latest/search.html @@ -6,4 +6,4 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

Search

Search

Number of results: loading...

    +

    Search

    Search

    Number of results: loading...

      diff --git a/latest/search_index.js b/latest/search_index.js index 1c9b6a26..58cb914c 100644 --- a/latest/search_index.js +++ b/latest/search_index.js @@ -114,15 +114,15 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#", - "page": "Layer Reference", - "title": "Layer Reference", + "page": "Model Reference", + "title": "Model Reference", "category": "page", "text": "" }, { "location": "models/layers.html#Flux.Chain", - "page": "Layer Reference", + "page": "Model Reference", "title": "Flux.Chain", "category": "Type", "text": "Chain(layers...)\n\nChain multiple layers / functions together, so that they are called in sequence on a given input.\n\nm = Chain(x -> x^2, x -> x+1)\nm(5) == 26\n\nm = Chain(Dense(10, 5), Dense(5, 2))\nx = rand(10)\nm(x) == m[2](m[1](x))\n\nChain also supports indexing and slicing, e.g. m[2] or m[1:end-1]. m[1:3](x) will calculate the output of the first three layers.\n\n\n\n" @@ -130,23 +130,31 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#Flux.Dense", - "page": "Layer Reference", + "page": "Model Reference", "title": "Flux.Dense", "category": "Type", "text": "Dense(in::Integer, out::Integer, σ = identity)\n\nCreates a traditional Dense layer with parameters W and b.\n\ny = σ.(W * x .+ b)\n\nThe input x must be a vector of length in, or a batch of vectors represented as an in × N matrix. The out y will be a vector or batch of length out.\n\njulia> d = Dense(5, 2)\nDense(5, 2)\n\njulia> d(rand(5))\nTracked 2-element Array{Float64,1}:\n 0.00257447\n -0.00449443\n\n\n\n" }, { - "location": "models/layers.html#Model-Layers-1", - "page": "Layer Reference", - "title": "Model Layers", + "location": "models/layers.html#Layers-1", + "page": "Model Reference", + "title": "Layers", "category": "section", "text": "These core layers form the foundation of almost all neural networks.Chain\nDense" }, +{ + "location": "models/layers.html#Recurrent-Cells-1", + "page": "Model Reference", + "title": "Recurrent Cells", + "category": "section", + "text": "Much like the core layers above, but can be used to process sequence data (as well as other kinds of structured data).RNN\nLSTM\nRecur" +}, + { "location": "models/layers.html#NNlib.σ", - "page": "Layer Reference", + "page": "Model Reference", "title": "NNlib.σ", "category": "Function", "text": "σ(x) = 1 / (1 + exp(-x))\n\nClassic sigmoid activation function.\n\n\n\n" @@ -154,7 +162,7 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#NNlib.relu", - "page": "Layer Reference", + "page": "Model Reference", "title": "NNlib.relu", "category": "Function", "text": "relu(x) = max(0, x)\n\nRectified Linear Unit activation function.\n\n\n\n" @@ -162,7 +170,7 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#NNlib.leakyrelu", - "page": "Layer Reference", + "page": "Model Reference", "title": "NNlib.leakyrelu", "category": "Function", "text": "leakyrelu(x) = max(0.01x, x)\n\nLeaky Rectified Linear Unit activation function.\n\nYou can also specify the coefficient explicitly, e.g. leakyrelu(x, 0.01).\n\n\n\n" @@ -170,7 +178,7 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#NNlib.elu", - "page": "Layer Reference", + "page": "Model Reference", "title": "NNlib.elu", "category": "Function", "text": "elu(x; α = 1) = x > 0 ? x : α * (exp(x) - one(x)\n\nExponential Linear Unit activation function. See Fast and Accurate Deep Network Learning by Exponential Linear Units\n\n\n\n" @@ -178,7 +186,7 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#NNlib.swish", - "page": "Layer Reference", + "page": "Model Reference", "title": "NNlib.swish", "category": "Function", "text": "swish(x) = x * σ(x)\n\nSelf-gated actvation function.\n\nSee Swish: a Self-Gated Activation Function.\n\n\n\n" @@ -186,7 +194,7 @@ var documenterSearchIndex = {"docs": [ { "location": "models/layers.html#Activation-Functions-1", - "page": "Layer Reference", + "page": "Model Reference", "title": "Activation Functions", "category": "section", "text": "Non-linearities that go between layers of your model. Most of these functions are defined in NNlib but are available by default in Flux.Note that, unless otherwise stated, activation functions operate on scalars. To apply them to an array you can call σ.(xs), relu.(xs) and so on.σ\nrelu\nleakyrelu\nelu\nswish" diff --git a/latest/training/optimisers.html b/latest/training/optimisers.html index 239b3f62..51268454 100644 --- a/latest/training/optimisers.html +++ b/latest/training/optimisers.html @@ -6,7 +6,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

      Optimisers

      Optimisers

      Consider a simple linear regression. We create some dummy data, calculate a loss, and backpropagate to calculate gradients for the parameters W and b.

      W = param(rand(2, 5))
      +

      Optimisers

      Optimisers

      Consider a simple linear regression. We create some dummy data, calculate a loss, and backpropagate to calculate gradients for the parameters W and b.

      W = param(rand(2, 5))
       b = param(rand(2))
       
       predict(x) = W*x .+ b
      @@ -27,4 +27,4 @@ end

      If we call update, the parameters W Dense(10, 5, σ), Dense(5, 2), softmax)

      Instead of having to write [m[1].W, m[1].b, ...], Flux provides a params function params(m) that returns a list of all parameters in the model for you.

      For the update step, there's nothing whatsoever wrong with writing the loop above – it'll work just fine – but Flux provides various optimisers that make it more convenient.

      opt = SGD([W, b], 0.1) # Gradient descent with learning rate 0.1
       
      -opt() # Carry out the update, modifying `W` and `b`.

      An optimiser takes a parameter list and returns a function that does the same thing as update above. We can pass either opt or update to our training loop, which will then run the optimiser after every mini-batch of data.

      Optimiser Reference

      All optimisers return a function that, when called, will update the parameters passed to it.

      Flux.Optimise.SGDFunction.
      SGD(params, η = 1; decay = 0)

      Classic gradient descent optimiser. For each parameter p and its gradient δp, this runs p -= η*δp.

      Supports decayed learning rate decay if the decay argument is provided.

      source
      Momentum(params, ρ, decay = 0)

      SGD with momentum ρ and optional learning rate decay.

      source
      Nesterov(params, ρ, decay = 0)

      SGD with Nesterov momentum ρ and optional learning rate decay.

      source
      Flux.Optimise.RMSPropFunction.
      RMSProp(params; η = 0.001, ρ = 0.9, ϵ = 1e-8, decay = 0)

      RMSProp optimiser. Parameters other than learning rate don't need tuning. Often a good choice for recurrent networks.

      source
      Flux.Optimise.ADAMFunction.
      ADAM(params; η = 0.001, β1 = 0.9, β2 = 0.999, ϵ = 1e-08, decay = 0)

      ADAM optimiser.

      source
      Flux.Optimise.ADAGradFunction.
      ADAGrad(params; η = 0.01, ϵ = 1e-8, decay = 0)

      ADAGrad optimiser. Parameters don't need tuning.

      source
      ADADelta(params; η = 0.01, ρ = 0.95, ϵ = 1e-8, decay = 0)

      ADADelta optimiser. Parameters don't need tuning.

      source
      +opt() # Carry out the update, modifying `W` and `b`.

      An optimiser takes a parameter list and returns a function that does the same thing as update above. We can pass either opt or update to our training loop, which will then run the optimiser after every mini-batch of data.

      Optimiser Reference

      All optimisers return a function that, when called, will update the parameters passed to it.

      Flux.Optimise.SGDFunction.
      SGD(params, η = 1; decay = 0)

      Classic gradient descent optimiser. For each parameter p and its gradient δp, this runs p -= η*δp.

      Supports decayed learning rate decay if the decay argument is provided.

      source
      Momentum(params, ρ, decay = 0)

      SGD with momentum ρ and optional learning rate decay.

      source
      Nesterov(params, ρ, decay = 0)

      SGD with Nesterov momentum ρ and optional learning rate decay.

      source
      Flux.Optimise.RMSPropFunction.
      RMSProp(params; η = 0.001, ρ = 0.9, ϵ = 1e-8, decay = 0)

      RMSProp optimiser. Parameters other than learning rate don't need tuning. Often a good choice for recurrent networks.

      source
      Flux.Optimise.ADAMFunction.
      ADAM(params; η = 0.001, β1 = 0.9, β2 = 0.999, ϵ = 1e-08, decay = 0)

      ADAM optimiser.

      source
      Flux.Optimise.ADAGradFunction.
      ADAGrad(params; η = 0.01, ϵ = 1e-8, decay = 0)

      ADAGrad optimiser. Parameters don't need tuning.

      source
      ADADelta(params; η = 0.01, ρ = 0.95, ϵ = 1e-8, decay = 0)

      ADADelta optimiser. Parameters don't need tuning.

      source
      diff --git a/latest/training/training.html b/latest/training/training.html index 28215d8b..9093eec8 100644 --- a/latest/training/training.html +++ b/latest/training/training.html @@ -6,7 +6,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ga('create', 'UA-36890222-9', 'auto'); ga('send', 'pageview'); -

      Training

      Training

      To actually train a model we need three things:

      • A model loss function, that evaluates how well a model is doing given some input data.

      • A collection of data points that will be provided to the loss function.

      • An optimiser that will update the model parameters appropriately.

      With these we can call Flux.train!:

      Flux.train!(modelLoss, data, opt)

      There are plenty of examples in the model zoo.

      Loss Functions

      The loss that we defined in basics is completely valid for training. We can also define a loss in terms of some model:

      m = Chain(
      +

      Training

      Training

      To actually train a model we need three things:

      • A model loss function, that evaluates how well a model is doing given some input data.

      • A collection of data points that will be provided to the loss function.

      • An optimiser that will update the model parameters appropriately.

      With these we can call Flux.train!:

      Flux.train!(modelLoss, data, opt)

      There are plenty of examples in the model zoo.

      Loss Functions

      The loss that we defined in basics is completely valid for training. We can also define a loss in terms of some model:

      m = Chain(
         Dense(784, 32, σ),
         Dense(32, 10), softmax)