Machine Learning in Elixir: Chapter 13 code errors

Hello @seanmor5! Thanks a lot for the amazing book and new chapter :purple_heart:

I got a couple of errors when trying to run the examples in Chap. 13 and they don’t seem to have been reported yet:

  1. p.313 The :sequence_length and :batch_size keys of text_embedding had to be popped and nested in a :compile key:
opts = Keyword.validate!(opts, [
  :defn_options, sequence_length: 64, batch_size: 16 ])

{model_info, tokenizer} = load()
Bumblebee.Text.TextEmbedding.text_embedding(model_info, tokenizer, opts)
  1. p.316 predict/1 returns an %{embedding: Nx.Tensor.t()}, should return a Nx.Tensor.t() to work when adding it to the changeset later:
def predict(text) do
-  Nx.Serving.batched_run(BookSearchModel, text)
+  Nx.Serving.batched_run(BookSearchModel, text).embedding
end
  1. p.320 needs to assign :query
def mount(_params, _session, socket) do
-  {:ok, assign(socket, :results, [])}
+  {:ok, assign(socket, results: [], query: nil)}
end
  1. p.321 Typo in HTML template
<a
-  href{~p"/book/#{result.id}"}
+  href={~p"/book/#{result.id}"}
1 Like

Hello, can you be more specific on the error from page 313.
I don’t understand.

@pieteeken are you asking @sabiwara to respond, or the author, @seanmor5 ?

@pieteeken I changed it as follows, fixed it for me:

    opts = Keyword.validate!(opts, [:defn_options, sequence_length: 64, batch_size: 16])
    {defn_opts, compile_opts} = Keyword.pop!(opts, :defn_options)
    opts = [defn_options: defn_opts, compile: compile_opts]
1 Like

Thank you. It works!

@sabiwara

Only one problem. All is working , only I don’t get the results, see the warning:

warning: no route path for BookSearchWeb.Router matches "/book/#{result.id}"
lib/book_search_web/live/search_live/index.ex:97: BookSearchWeb.SearchLive.Index.search_results/1

Maybe you know the solution?

Oh right I forgot to mention it above, but it also needs to be pluralized: /books/:id

OK. It’s working.
And I also got the results. But that was because of one forgotten change from the book.

1 Like