Skip to content

Commit 7a32a70

Browse files
bors[bot]janEbert
andauthored
Merge #853
853: Improve docs r=CarloLucibello a=janEbert If you disagree with any of the changes, please tell me what to reverse or fix. I am unsure about the docstrings I added to `src/utils.jl` for `unsqueeze` and the `[un]stack` functions so please give those a more detailed look. Update Documenter.jl version for new features, fix deprecation warnings in `docs/make.jl` and import Flux for all doctests. Add missing docstrings to `src/utils.jl`, `src/layers/stateless.jl` and `src/data/`; add these and other missing functions to Markdown docs. Improve docstrings by... - fixing typos, - removing trailing or double whitespaces, - using `jldoctest` blocks where applicable, - fixing, updating or correctly setting up existing doctests, - improving consistency (for example, always use "# Examples" instead of other variants), - removing empty lines between docstrings and functions, - instead of mentioning keywords, put them into the docstring, - adding some missing but useful keywords, - adding references (`@ref`), - using LaTeX math where applicable, and - linking papers. Debatable stuff that is untouched: - BE/AE s/z irregularities (e.g. "normalise" versus "normalize") since most papers use the AE version while the Flux source code was written with BE spelling. - Names of normalization functions are capitalized ("Batch Normalization" instead of "batch normalization"). - Default values in argument lists have spaces around the equals sign (`arg = x` instead of `arg=x`). Co-authored-by: janEbert <janpublicebert@posteo.net>
2 parents a9f8250 + 6845706 commit 7a32a70

26 files changed

+757
-430
lines changed

docs/make.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Documenter, Flux, NNlib
22

3+
DocMeta.setdocmeta!(Flux, :DocTestSetup, :(using Flux); recursive=true)
34
makedocs(modules=[Flux, NNlib],
5+
doctest = VERSION >= v"1.4",
46
sitename = "Flux",
57
pages = ["Home" => "index.md",
68
"Building Models" =>
@@ -19,12 +21,16 @@ makedocs(modules=[Flux, NNlib],
1921
"GPU Support" => "gpu.md",
2022
"Saving & Loading" => "saving.md",
2123
"The Julia Ecosystem" => "ecosystem.md",
24+
"Utility Functions" => "utilities.md",
2225
"Performance Tips" => "performance.md",
26+
"Datasets" => "datasets.md",
2327
"Community" => "community.md"],
24-
format = Documenter.HTML(assets = ["assets/flux.css"],
25-
analytics = "UA-36890222-9",
26-
prettyurls = haskey(ENV, "CI")))
28+
format = Documenter.HTML(
29+
analytics = "UA-36890222-9",
30+
assets = ["assets/flux.css"],
31+
prettyurls = get(ENV, "CI", nothing) == "true"),
32+
)
2733

28-
deploydocs(repo = "github.com/FluxML/Flux.jl.git",
34+
deploydocs(repo = "github.com/FluxML/Flux.jl.git",
2935
target = "build",
3036
push_preview = true)

docs/src/data/dataloader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Flux provides the `DataLoader` type in the `Flux.Data` module to handle iteratio
33

44
```@docs
55
Flux.Data.DataLoader
6-
```
6+
```

docs/src/data/onehot.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ julia> onecold([0.3, 0.2, 0.5], [:a, :b, :c])
3131
:c
3232
```
3333

34+
```@docs
35+
Flux.onehot
36+
Flux.onecold
37+
```
38+
3439
## Batches
3540

3641
`onehotbatch` creates a batch (matrix) of one-hot vectors, and `onecold` treats matrices as batches.
@@ -52,3 +57,7 @@ julia> onecold(ans, [:a, :b, :c])
5257
```
5358

5459
Note that these operations returned `OneHotVector` and `OneHotMatrix` rather than `Array`s. `OneHotVector`s behave like normal vectors but avoid any unnecessary cost compared to using an integer index directly. For example, multiplying a matrix with a one-hot vector simply slices out the relevant row of the matrix under the hood.
60+
61+
```@docs
62+
Flux.onehotbatch
63+
```

docs/src/datasets.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Datasets
2+
3+
Flux includes several standard machine learning datasets.
4+
5+
```@docs
6+
Flux.Data.Iris.features()
7+
Flux.Data.Iris.labels()
8+
Flux.Data.MNIST.images()
9+
Flux.Data.MNIST.labels()
10+
Flux.Data.FashionMNIST.images()
11+
Flux.Data.FashionMNIST.labels()
12+
Flux.Data.CMUDict.phones()
13+
Flux.Data.CMUDict.symbols()
14+
Flux.Data.CMUDict.rawdict()
15+
Flux.Data.CMUDict.cmudict()
16+
Flux.Data.Sentiment.train()
17+
Flux.Data.Sentiment.test()
18+
Flux.Data.Sentiment.dev()
19+
```
20+

docs/src/models/basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Flux.@functor Affine
220220

221221
This enables a useful extra set of functionality for our `Affine` layer, such as [collecting its parameters](../training/optimisers.md) or [moving it to the GPU](../gpu.md).
222222

223-
For some more helpful tricks, including parameter freezing, please checkout the [advanced usage guide](advacned.md).
223+
For some more helpful tricks, including parameter freezing, please checkout the [advanced usage guide](advanced.md).
224224

225225
## Utility functions
226226

@@ -240,5 +240,5 @@ Currently limited to the following layers:
240240
- `MeanPool`
241241

242242
```@docs
243-
outdims
243+
Flux.outdims
244244
```

docs/src/models/layers.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ RNN
3232
LSTM
3333
GRU
3434
Flux.Recur
35+
Flux.reset!
3536
```
3637

3738
## Other General Purpose Layers
@@ -49,20 +50,22 @@ SkipConnection
4950
These layers don't affect the structure of the network but may improve training times or reduce overfitting.
5051

5152
```@docs
53+
Flux.normalise
5254
BatchNorm
53-
Dropout
5455
Flux.dropout
56+
Dropout
5557
AlphaDropout
5658
LayerNorm
59+
InstanceNorm
5760
GroupNorm
5861
```
5962

6063
### Testmode
6164

62-
Many normalisation layers behave differently under training and inference (testing). By default, Flux will automatically determine when a layer evaluation is part of training or inference. Still, depending on your use case, it may be helpful to manually specify when these layers should be treated as being trained or not. For this, Flux provides `testmode!`. When called on a model (e.g. a layer or chain of layers), this function will place the model into the mode specified.
65+
Many normalisation layers behave differently under training and inference (testing). By default, Flux will automatically determine when a layer evaluation is part of training or inference. Still, depending on your use case, it may be helpful to manually specify when these layers should be treated as being trained or not. For this, Flux provides `Flux.testmode!`. When called on a model (e.g. a layer or chain of layers), this function will place the model into the mode specified.
6366

6467
```@docs
65-
testmode!
68+
Flux.testmode!
6669
trainmode!
6770
```
6871

docs/src/models/regularisation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ julia> activations(c, rand(10))
6464
julia> sum(norm, ans)
6565
2.1166067f0
6666
```
67+
68+
```@docs
69+
Flux.activations
70+
```

docs/src/performance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ e.g.
5252
```julia
5353
function loss_total(xs::AbstractVector{<:Vector}, ys::AbstractVector{<:Vector})
5454
sum(zip(xs, ys)) do (x, y_target)
55-
y_pred = model(x) # evaluate the model
55+
y_pred = model(x) # evaluate the model
5656
return loss(y_pred, y_target)
5757
end
5858
end

docs/src/training/optimisers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Momentum
5252
Nesterov
5353
RMSProp
5454
ADAM
55+
RADAM
5556
AdaMax
5657
ADAGrad
5758
ADADelta

docs/src/training/training.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Flux.train!(loss, ps, data, opt)
3232
```
3333

3434
The objective will almost always be defined in terms of some *cost function* that measures the distance of the prediction `m(x)` from the target `y`. Flux has several of these built in, like `mse` for mean squared error or `crossentropy` for cross entropy loss, but you can calculate it however you want.
35+
For a list of all built-in loss functions, check out the [layer reference](../models/layers.md).
3536

3637
At first glance it may seem strange that the model that we want to train is not part of the input arguments of `Flux.train!` too. However the target of the optimizer is not the model itself, but the objective function that represents the departure between modelled and observed data. In other words, the model is implicitly defined in the objective function, and there is no need to give it explicitly. Passing the objective function instead of the model and a cost function separately provides more flexibility, and the possibility of optimizing the calculations.
3738

@@ -94,6 +95,10 @@ julia> @epochs 2 Flux.train!(...)
9495
# Train for two epochs
9596
```
9697

98+
```@docs
99+
Flux.@epochs
100+
```
101+
97102
## Callbacks
98103

99104
`train!` takes an additional argument, `cb`, that's used for callbacks so that you can observe the training process. For example:

0 commit comments

Comments
 (0)