Skip to content

Commit 8c60006

Browse files
Re-write "basics" page of docs (#2535)
* heading id * re-write of basics page * change readme too? * fix some doctests * Update docs/src/guide/models/basics.md Co-authored-by: Christian Guinard <[email protected]> * evalpoly, Enzyme, heading, withgradient, glorot_uniform, etc * more doctests, shorten fitting example, and a regex I copied from somewhere * maybe I should remember how to run documenter locally * fixes? * bytes on 1.11, and revert a fix * logos & links * move custom-models / advanced.md back to tutorial section * tweaks * more tweaks * more tweaks & typos --------- Co-authored-by: Christian Guinard <[email protected]>
1 parent 5cc50e9 commit 8c60006

File tree

6 files changed

+367
-155
lines changed

6 files changed

+367
-155
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,25 @@ Flux is an elegant approach to machine learning. It's a 100% pure-Julia stack, a
2222

2323
Works best with [Julia 1.10](https://julialang.org/downloads/) or later. Here's a very short example to try it out:
2424
```julia
25-
using Flux, Plots
26-
data = [([x], 2x-x^3) for x in -2:0.1f0:2]
25+
using Flux
26+
data = [(x, 2x-x^3) for x in -2:0.1f0:2]
2727

28-
model = Chain(Dense(1 => 23, tanh), Dense(23 => 1, bias=false), only)
28+
model = let
29+
w, b, v = (randn(Float32, 23) for _ in 1:3) # parameters
30+
x -> sum(v .* tanh.(w*x .+ b)) # callable
31+
end
32+
# model = Chain(vcat, Dense(1 => 23, tanh), Dense(23 => 1, bias=false), only)
2933

3034
opt_state = Flux.setup(Adam(), model)
31-
for epoch in 1:1000
35+
for epoch in 1:100
3236
Flux.train!((m,x,y) -> (m(x) - y)^2, model, data, opt_state)
3337
end
3438

35-
plot(x -> 2x-x^3, -2, 2, legend=false)
36-
scatter!(x -> model([x]), -2:0.1f0:2)
39+
using Plots
40+
plot(x -> 2x-x^3, -2, 2, label="truth")
41+
scatter!(model, -2:0.1f0:2, label="learned")
3742
```
43+
In Flux 0.15, almost any parameterised function in Julia is a valid Flux model -- such as this closure over `w, b, v`. The same function can also be implemented with built-in layers as shown.
3844

3945
The [quickstart page](https://fluxml.ai/Flux.jl/stable/guide/models/quickstart/) has a longer example. See the [documentation](https://fluxml.github.io/Flux.jl/) for details, or the [model zoo](https://github.com/FluxML/model-zoo/) for examples. Ask questions on the [Julia discourse](https://discourse.julialang.org/) or [slack](https://discourse.julialang.org/t/announcing-a-julia-slack/4866).
4046

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ makedocs(
3030
"Quick Start" => "guide/models/quickstart.md",
3131
"Fitting a Line" => "guide/models/overview.md",
3232
"Gradients and Layers" => "guide/models/basics.md",
33-
"Custom Layers" => "guide/models/custom_layers.md",
3433
"Training" => "guide/training/training.md",
3534
"Recurrence" => "guide/models/recurrence.md",
3635
"GPU Support" => "guide/gpu.md",
@@ -63,6 +62,7 @@ makedocs(
6362
# Or perhaps those should just be trashed, model zoo versions are newer & more useful.
6463
"Linear Regression" => "tutorials/linear_regression.md",
6564
"Logistic Regression" => "tutorials/logistic_regression.md",
65+
"Custom Layers" => "tutorials/custom_layers.md",
6666
"Model Zoo" => "tutorials/model_zoo.md",
6767
#=
6868
# "Multi-layer Perceptron" => "tutorials/mlp.md",

docs/src/assets/zygote-crop.png

61.8 KB
Loading

0 commit comments

Comments
 (0)