Machine Learning in Elixir: ArgumentError raised at end of chapter 1

Hi @seanmor5 ,

I’m reading the book and editing a livebook in parallel as suggested. I’m facing an error while executing the last code sample of chapter 1:

data = [{x_test, y_test}]

|> Axon.Loop.evaluator()
|> Axon.Loop.metric(:accuracy)
|>, trained_model_state)

and the error:

** (ArgumentError) cannot broadcast tensor of dimensions {30} to {120}
    (nx 0.6.2) lib/nx/shape.ex:345: Nx.Shape.binary_broadcast/4
    (nx 0.6.2) lib/nx.ex:5490: Nx.devectorized_element_wise_pred_op/3
    (axon 0.6.0) lib/axon/metrics.ex:88: Axon.Metrics.accuracy_transform/4
    (axon 0.6.0) lib/axon/metrics.ex:467: anonymous fn/4 in Axon.Metrics.running_average/1
    (axon 0.6.0) lib/axon/loop.ex:1941: anonymous fn/5 in Axon.Loop.build_batch_fn/2
    (elixir 1.15.7) lib/enum.ex:3945: anonymous fn/4 in Enum.zip_with/3
    (elixir 1.15.7) lib/enum.ex:4005: anonymous fn/3 in Enum.zip_reduce/4
    /Users/svarlet/Library/Application Support/livebook/autosaved/2023_11_03/08_05_xeos/machine_learning_with_elixir.livemd#cell:gdvbkglhchgtaa6fk4ovsw457hsrreg5:6: (file)

How can I solve this problem?


Error fixed, it was my mistake. I defined y_test based on the train set instead of the test set. Silly me!