Skip to content

Commit dfc5a7e

Browse files
authoredOct 8, 2022
Add an example to the readme? (#2067)
* add example to readme * add installation note, tweak * tweak wording, remove tutorials link * try adding comments * mv slack to text, add downloads badge * change to use logitcrossentropy * mention that loss(x,y) closes over model this is a slightly weird feature of our API... and since we also call logitcrossentropy a loss function, perhaps we should emphasize that loss(x,y) is a new thing just for this model, not a function for all time.
1 parent 7a276f8 commit dfc5a7e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed
 

‎README.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
<img width="400px" src="https://raw.githubusercontent.com/FluxML/Flux.jl/master/docs/src/assets/logo-dark.png#gh-dark-mode-only"/>
44
</p>
55

6-
[![][action-img]][action-url] [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://fluxml.github.io/Flux.jl/stable/) [![](https://img.shields.io/badge/chat-on%20slack-yellow.svg)](https://julialang.org/slack/) [![DOI](https://joss.theoj.org/papers/10.21105/joss.00602/status.svg)](https://doi.org/10.21105/joss.00602) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) [![][codecov-img]][codecov-url]
6+
<div align="center">
7+
8+
[![](https://img.shields.io/badge/Documentation-stable-blue.svg)](https://fluxml.github.io/Flux.jl/stable/) [![DOI](https://joss.theoj.org/papers/10.21105/joss.00602/status.svg)](https://doi.org/10.21105/joss.00602) [![Flux Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/Flux)](https://pkgs.genieframework.com?packages=Flux)
9+
<br/>
10+
[![][action-img]][action-url] [![][codecov-img]][codecov-url] [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
11+
12+
</div>
713

814
[action-img]: https://github.com/FluxML/Flux.jl/workflows/CI/badge.svg
915
[action-url]: https://github.com/FluxML/Flux.jl/actions
@@ -12,10 +18,23 @@
1218

1319
Flux is an elegant approach to machine learning. It's a 100% pure-Julia stack, and provides lightweight abstractions on top of Julia's native GPU and AD support. Flux makes the easy things easy while remaining fully hackable.
1420

21+
Works best with [Julia 1.8](https://julialang.org/downloads/) or later. Here's a simple example to try it out:
1522
```julia
16-
] add Flux
23+
using Flux # should install everything for you, including CUDA
24+
25+
x = hcat(digits.(0:3, base=2, pad=2)...) |> gpu # let's solve the XOR problem!
26+
y = Flux.onehotbatch(xor.(eachrow(x)...), 0:1) |> gpu
27+
data = ((Float32.(x), y) for _ in 1:100) # an iterator making Tuples
28+
29+
model = Chain(Dense(2 => 3, sigmoid), BatchNorm(3), Dense(3 => 2)) |> gpu
30+
optim = Adam(0.1, (0.7, 0.95))
31+
mloss(x, y) = Flux.logitcrossentropy(model(x), y) # closes over model
32+
33+
Flux.train!(mloss, Flux.params(model), data, optim) # updates model & optim
34+
35+
all((softmax(model(x)) .> 0.5) .== y) # usually 100% accuracy.
1736
```
1837

19-
See the [documentation](https://fluxml.github.io/Flux.jl/) or the [model zoo](https://github.com/FluxML/model-zoo/) for examples.
38+
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).
2039

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

0 commit comments

Comments
 (0)