Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmor5 committed Mar 16, 2021
1 parent cc67a51 commit c013efa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
79 changes: 73 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,85 @@ Nx-powered Neural Networks

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `axon` to your list of dependencies in `mix.exs`:
In order to use `Axon`, you will need Elixir installed. Then create an Elixir project via the mix build tool:

```
$ mix new my_app
```

Then you can add `Axon` as dependency in your `mix.exs`. At the moment you will have to use a Git dependency while we work on our first release:

```elixir
def deps do
[
{:axon, "~> 0.1.0"}
{:axon, "~> 0.1.0-dev", github: "elixir-nx/axon", branch: "main"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/axon](https://hexdocs.pm/axon).
You will typically want to include another `Nx` backend or as a dependency as well:

```elixir
def deps do
[
{:axon, "~> 0.1.0-dev", github: "elixir-nx/axon", branch: "main"},
{:exla, "~> 0.1.0-dev", github: "elixir-nx/exla", branch: "main", sparse: "exla"},
{:torchx, "~> 0.1.0-dev", github: "elixir-nx/nx", sparse: "torchx"},
]
end
```

## A Basic Neural Network

You can create neural networks inside modules with the `model` macro:

```elixir
defmodule MyNN do
use Axon

model do
input({nil, 784})
|> dense(128)
|> relu()
|> dense(64, activation: :tanh)
|> dropout(rate: 0.5)
|> dense(10)
|> activation(:softmax)
end
end
```

`model` will generate the numerical definitions `init_random_params/0` and `predict/2`. You can also name models for using multiple models in the same training loop:

```elixir
defmodule GAN do
use Axon

model generator do
input({nil, 100})
|> dense(128)
|> tanh()
|> dense(256)
|> tanh()
|> dense(512)
|> tanh()
|> dense(1024)
|> tanh()
|> dense(784)
|> tanh()
end

model discriminator do
input({nil, 28, 28})
|> flatten()
|> dense(128)
|> relu()
|> dense(64)
|> relu()
|> dense(2)
|> softmax()
end
end
```

In the above example, you can initialize and apply both models using: `init_generator`/`generator` and `init_discriminator`/`discriminator` respectively.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Axon.MixProject do
def project do
[
app: :axon,
version: "0.1.0",
version: @version,
elixir: "~> 1.11",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down

0 comments on commit c013efa

Please sign in to comment.