Skip to content

Commit 9c99d60

Browse files
committed
maybe we should have a much simpler readme example
1 parent 03e9533 commit 9c99d60

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

README.md

+10-12
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,22 @@ Flux is an elegant approach to machine learning. It's a 100% pure-Julia stack, a
2020

2121
Works best with [Julia 1.8](https://julialang.org/downloads/) or later. Here's a very short example to try it out:
2222
```julia
23-
using Flux # should install everything for you, including CUDA
23+
using Flux, Plots
24+
data = [([x], x-cbrt(x)) for x in range(-2, 2, 100)]
2425

25-
x = hcat(digits.(0:3, base=2, pad=2)...) # data for the XOR problem
26-
y = Flux.onehotbatch(xor.(eachrow(x)...), 0:1)
26+
model = Chain(Dense(1 => 10, tanh), Dense(10 => 1), only)
2727

28-
model = Chain(Dense(2 => 3, sigmoid), BatchNorm(3), Dense(3 => 2))
29-
pars = Flux.params(model) # a dictionary of arrays in model
30-
optim = Adam(0.1, (0.7, 0.95))
31-
32-
for _ in 1:100
33-
grad = gradient(() -> Flux.logitcrossentropy(model(x), y), pars)
34-
Flux.update!(optim, pars, grad) # this changes model & optim
28+
loss(x,y) = abs2(model(x) - y)
29+
optim = Flux.Adam()
30+
for epoch in 1:1000
31+
Flux.train!(loss, Flux.params(model), data, optim)
3532
end
3633

37-
all((softmax(model(x)) .> 0.5) .== y) # usually 100% accuracy.
34+
plot(x -> x-cbrt(x), -2, 2, legend=false)
35+
scatter!(-2:0.1:2, [model([x]) for x in -2:0.1:2])
3836
```
3937

40-
The [quickstart page](https://fluxml.ai/Flux.jl/stable/models/quickstart/) has a longer version. 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).
38+
The [quickstart page](https://fluxml.ai/Flux.jl/stable/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).
4139

4240
If you use Flux in your research, please [cite](CITATION.bib) our work.
4341

0 commit comments

Comments
 (0)