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