CHSurfer

CHSurfer

I just picked up the Machine Learning in Elixir book and am already stuck in Chapter 1.

I am working through the first livebook example. My results are slightly different than in the book

#Explorer.DataFrame<
  Polars[150 x 5]
  sepal_length f64 [5.1, 4.9, 4.7, 4.6, 5.0, ...]

#Explorer.DataFrame<
Polars[150 x 5]
sepal_length float [5.1, 4.9, 4.7, 4.6, 5.0, "..."]

I included the below code, as per instructions

Mix.install([
  {:axon, "~> 0.5"},
  {:nx, "~> 0.5"},
  {:explorer, "~> 0.5"},
  {:kino, "~> 0.8"}
])

but my actual version of axon is 0.7, which might be related…

When i try to evaluate this block:

trained_model_state =
  model
  |> Axon.Loop.trainer(:categorical_cross_entropy, :sgd)
  |> Axon.Loop.metric(:accuracy)
  |> Axon.Loop.run(data_stream, %{}, iterations: 500, epochs: 10)

I get the following warning and error:

20:17:36.449 [warning] passing parameter map to initialization is deprecated, use %Axon.ModelState{} instead
Epoch: 0, Batch: 0, accuracy: 0.0250000 loss: 0.0000000

** (ArgumentError) argument at position 3 is not compatible with compiled function template.

%{i: #Nx.Tensor<
s32

, model_state: #Inspect.Error<
got Protocol.UndefinedError with message:

  """
  protocol Enumerable not implemented for #Nx.Tensor<
    f32[3]
  > of type Nx.Defn.TemplateDiff (a struct). This protocol is implemented for the following type(s): Date.Range, Explorer.Series.Iterator, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Kino.Control, Kino.Input, Kino.JS.Live, List, Map, MapSet, Range, Stream, Table.Mapper, Table.Zipper
  """

while inspecting:

  %{
    data: %{
      "dense_0" => %{
        "bias" => #Nx.Tensor<
          f32[3]
        >,
        "kernel" => #Nx.Tensor<
          f32[4][3]
        >
      }
    },
    state: %{},
    __struct__: Axon.ModelState,
    parameters: %{"dense_0" => ["bias", "kernel"]},
    frozen_parameters: %{}
  }

Stacktrace:

(elixir 1.17.1) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.17.1) lib/enum.ex:166: Enumerable.reduce/3
(elixir 1.17.1) lib/enum.ex:4423: Enum.reduce/3
(axon 0.7.0) lib/axon/model_state.ex:359: anonymous fn/2 in Inspect.Axon.ModelState.get_param_info/1
(stdlib 6.0) maps.erl:860: :maps.fold_1/4
(axon 0.7.0) lib/axon/model_state.ex:359: anonymous fn/2 in Inspect.Axon.ModelState.get_param_info/1
(stdlib 6.0) maps.erl:860: :maps.fold_1/4
(axon 0.7.0) lib/axon/model_state.ex:320: Inspect.Axon.ModelState.inspect/2

, optimizer_state: {%{scale: #Nx.Tensor<
f32
>}}, loss_scale_state: %{}, loss:
<<<<< Expected <<<<<
#Nx.Tensor<
f32

==========
#Nx.Tensor<
f64

Argument >>>>>
, y_pred: #Nx.Tensor<
f64[120][3] >,
y_true: #Nx.Tensor<
u8[120][3] >
}

(nx 0.9.1) lib/nx/defn.ex:342: anonymous fn/7 in Nx.Defn.compile_flatten/5
(nx 0.9.1) lib/nx/lazy_container.ex:73: anonymous fn/3 in Nx.LazyContainer.Map.traverse/3
(elixir 1.17.1) lib/enum.ex:1829: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(elixir 1.17.1) lib/enum.ex:1829: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(nx 0.9.1) lib/nx/lazy_container.ex:72: Nx.LazyContainer.Map.traverse/3
(nx 0.9.1) lib/nx/defn.ex:339: Nx.Defn.compile_flatten/5
(nx 0.9.1) lib/nx/defn.ex:331: anonymous fn/4 in Nx.Defn.compile/3
#cell:lze5noxdnhytfee2:5: (file)

If we ignore the warning, I guess the message is telling me that it expected an f32 tensor instead of the f64.

Is this due to my version of Axon or am I missing something else. I have run it both on the recommended version of Elixer/erlang (Elixir 1.14.3 (compiled with Erlang/OTP 25)) as well as Elixir 1.17.1 (compiled with Erlang/OTP 27)

Showing Posts 1 to 3

joelpaulkoch

joelpaulkoch

Hi, I’m pretty sure this is because of the Axon version.

You can fix the actual version like this (described here):

Mix.install([
  {:axon, "== 0.5.1"},
  {:nx, "~> 0.5"},
  {:explorer, "~> 0.5"},
  {:kino, "~> 0.8"}
])

Note that you must specify the exact version this way.
Can you try that and report back if it works?

In case you’re wondering, there are some changes in Axon from time to time since it’s pre 1.0 but the basic ideas remain the same, so I think it’s still worth following the examples in version 0.5, you can catch up afterwards.

CHSurfer

CHSurfer OP

Thanks, this fixed it.

I noticed that it also forced Nx version to go from 0.9 down to 0.5.3.

Thanks!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews