# Machine Learning in Elixir: Chapter 13 code errors

**URL:** <https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031>\
**Category:** PragProg Customers\
**Tags:** book-machine-learning-in-elixir, errata\
**Created:** [25 February 2024 03:55 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031 "2024-02-25T03:55:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabiwara](https://forum.devtalk.com/user_avatar/forum.devtalk.com/sabiwara/32/5823_2.png) [@sabiwara](https://forum.devtalk.com/u/sabiwara)\
**Post date:** [25 February 2024 03:55 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/1 "2024-02-25T03:55:10Z")

</div>

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

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`](https://hexdocs.pm/bumblebee/Bumblebee.Text.html#text_embedding/3) had to be popped and nested in a `:compile` key:

```elixir
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:

```diff
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`

```diff
def mount(_params, _session, socket) do
- {:ok, assign(socket, :results, [])}
+ {:ok, assign(socket, results: [], query: nil)}
end

```

1. p.321 Typo in HTML template

```diff
<a
- href{~p"/book/#{result.id}"}
+ href={~p"/book/#{result.id}"}

```

---

<div class="post-metadata">

**Author:** ![pieteeken](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pieteeken](https://forum.devtalk.com/u/pieteeken)\
**Post date:** [12 March 2024 05:23 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/2 "2024-03-12T05:23:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Margaret](https://forum.devtalk.com/user_avatar/forum.devtalk.com/margaret/32/237_2.png) [@Margaret](https://forum.devtalk.com/u/Margaret)\
**Post date:** [12 March 2024 17:34 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/3 "2024-03-12T17:34:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sabiwara](https://forum.devtalk.com/user_avatar/forum.devtalk.com/sabiwara/32/5823_2.png) [@sabiwara](https://forum.devtalk.com/u/sabiwara)\
**Post date:** [12 March 2024 22:35 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/4 "2024-03-12T22:35:14Z")

</div>

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

```elixir
    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]

```

---

<div class="post-metadata">

**Author:** ![pieteeken](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pieteeken](https://forum.devtalk.com/u/pieteeken)\
**Post date:** [13 March 2024 09:37 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/5 "2024-03-13T09:37:46Z")

</div>

> [@sabiwara](#):
>
> ```auto
> 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]
> 
> ```

Thank you. It works!

---

<div class="post-metadata">

**Author:** ![pieteeken](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pieteeken](https://forum.devtalk.com/u/pieteeken)\
**Post date:** [13 March 2024 18:34 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/6 "2024-03-13T18:34:39Z")

</div>

@sabiwara

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

```elixir
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?

---

<div class="post-metadata">

**Author:** ![sabiwara](https://forum.devtalk.com/user_avatar/forum.devtalk.com/sabiwara/32/5823_2.png) [@sabiwara](https://forum.devtalk.com/u/sabiwara)\
**Post date:** [13 March 2024 22:42 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/7 "2024-03-13T22:42:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pieteeken](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pieteeken](https://forum.devtalk.com/u/pieteeken)\
**Post date:** [14 March 2024 08:52 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-chapter-13-code-errors/145031/8 "2024-03-14T08:52:44Z")

</div>

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