Skip to content

Instantly share code, notes, and snippets.

@kelcecil
Created July 20, 2023 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelcecil/1afa0e3fa3109a2f3c94e05cd558c621 to your computer and use it in GitHub Desktop.
Save kelcecil/1afa0e3fa3109a2f3c94e05cd558c621 to your computer and use it in GitHub Desktop.
Machine Learning in Elixir - Errata and Feedback

For any randos that stumble on this gist, you should consider buying Machine Learning in Elixir. Despite any notes I add here, it's an exceptional book that's worth your time and money.

Chapter 1

Pg 13

I can't get the code snippet to work as written:

cols = ~w(sepal_width sepal_length petal_length petal_width)
normalized_iris =
  DF.mutate(
  iris,
  for col <- across(cols) do
    {col.name, (col - mean(col)) / variance(col)}
  end
)

getting:

** (ArgumentError) undefined variable "cols"
    (explorer 0.6.1) lib/explorer/query.ex:365: Explorer.Query.traverse/3
    (elixir 1.15.2) lib/enum.ex:1819: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (explorer 0.6.1) lib/explorer/query.ex:375: Explorer.Query.traverse/3
    (explorer 0.6.1) lib/explorer/query.ex:401: Explorer.Query.traverse_for/3
    (explorer 0.6.1) lib/explorer/query.ex:298: anonymous fn/3 in Explorer.Query.traverse/2
    (elixir 1.15.2) lib/enum.ex:1819: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (explorer 0.6.1) lib/explorer/query.ex:296: Explorer.Query.traverse/2
    (explorer 0.6.1) expanding macro: Explorer.Query.query/1

Passing the sigil into across makes the example work. I checked the Livebook files with the book and discovered it does the same thing.

Chapter 2

Pg 44

A couple notes here:

tensor = Nx.random_uniform({1_000_000})

Benchee.run(
  %{
    "JIT with EXLA" => fn ->
      apply(EXLA.jit(&Softmax.softmax/1), [tensor])
    end,
    "Regular Elixir" => fn ->
      Softmax.softmax(tensor)
    end
  },
  time: 10
)

Nx.random_uniform/1 throws a deprecation warning. It's still mentioned in the Nx 0.5.x docs as a core API function for tensor creation, but there's no function listing for it unless you go back to 0.4.x. It was a bit of work to track down old function to understand the params. I ended up replacing that with this.

key = Nx.Random.key(42)
tensor = Nx.Random.uniform(key, shape: {1_000_000})

Happy to submit an PR to Nx to improve the docs issue I ran into.

The second issue I ran into is that running the JIT example in the LiveBook standalone binary on MacOS (arm64) blew up being unable to get my erlang version. Installing using escript.install and running the example worked just fine. Your install info doesn't mention the universal binary at all, so I don't think any changes are necessary. Just wanted to raise the issue and workaround in case someone else asked about it.

Chapter 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment