Skip to content

Commit

Permalink
maybe we should have a much simpler readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Nov 20, 2022
1 parent 03e9533 commit 9c99d60
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,22 @@ Flux is an elegant approach to machine learning. It's a 100% pure-Julia stack, a

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

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

model = Chain(Dense(2 => 3, sigmoid), BatchNorm(3), Dense(3 => 2))
pars = Flux.params(model) # a dictionary of arrays in model
optim = Adam(0.1, (0.7, 0.95))

for _ in 1:100
grad = gradient(() -> Flux.logitcrossentropy(model(x), y), pars)
Flux.update!(optim, pars, grad) # this changes model & optim
loss(x,y) = abs2(model(x) - y)
optim = Flux.Adam()
for epoch in 1:1000
Flux.train!(loss, Flux.params(model), data, optim)
end

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

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).
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).

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

Expand Down

0 comments on commit 9c99d60

Please sign in to comment.