Can't preview or create docs for nbdev project [YAMLError: can not read a block mapping entry]

I was working with my project and had several pages and they are working fine and it was deployed without any error on GitHub pages. At this point my pages looks like this:

      - index.ipynb
      - 00_bigram.ipynb
      - 01_mlp.ipynb
      - 02_bn.ipynb
      - 03_wavenet.ipynb
      - 04_transformers.ipynb
      - 05_uml_diagrams.ipynb

But once I copy and paste the 00_bigram.ipynb notebook from another directory I am start getting the below error when I try to preview the docs nbdev_preview or nbdev_docs even if I nbdev_prepare first and delete the _proc folder.

(base) moneebullah25@DESKTOP-7G3J62T:/mnt/c/Muneeb/Projects/c_code_gen$ nbdev_prepare
Success.
(base) moneebullah25@DESKTOP-7G3J62T:/mnt/c/Muneeb/Projects/c_code_gen$ nbdev_preview
Preparing to preview
ERROR: YAMLError: can not read a block mapping entry; a multiline key may not be an implicit key at line 11, column 1:

    ^

YAMLError: can not read a block mapping entry; a multiline key may not be an implicit key at line 11, column 1:

    ^
    at generateError (file:///opt/quarto/bin/quarto.js:10719:12)
    at throwError (file:///opt/quarto/bin/quarto.js:10722:11)
    at readBlockMapping (file:///opt/quarto/bin/quarto.js:11336:24)
    at composeNode (file:///opt/quarto/bin/quarto.js:11528:84)
    at readDocument (file:///opt/quarto/bin/quarto.js:11642:5)
    at loadDocuments (file:///opt/quarto/bin/quarto.js:11679:9)
    at load (file:///opt/quarto/bin/quarto.js:11684:23)
    at parse3 (file:///opt/quarto/bin/quarto.js:11694:12)
    at parseWithNiceErrors (file:///opt/quarto/bin/quarto.js:19862:16)
    at readYamlFromMarkdown (file:///opt/quarto/bin/quarto.js:19802:26)

If I remove the 00_bigram.ipynb file from the project and try to preview the documents I don’t get any error:

(base) moneebullah25@DESKTOP-7G3J62T:/mnt/c/Muneeb/Projects/c_code_gen$ nbdev_preview
Preparing to preview
[1/6] 01_mlp.ipynb
[2/6] 02_bn.ipynb
[3/6] 03_wavenet.ipynb
[4/6] 04_transformers.ipynb
[5/6] 05_uml_diagrams.ipynb
[6/6] index.ipynb

Watching files for changes
Browse at http://localhost:7359/

Now once I realized I can’t copy the 00_bigram.ipynb file from another project directory, I delete the the 00_bigram.ipynb file and created it from scratch. Copy and pasting cells code and markdown from the another notebook it still doesn’t work. I was thinking it is because of 00_bigram filename but I also tried 06_bigram but it still doesn’t work. If I delete this file it works.

1 Like

Are you able to share the notebook? It seems like there is something may not be converting well from nbdev to quarto. Another idea is to delete the _proc directory and try previewing again. I doubt this will matter, but it is something I would try still.

Do you have any Quarto directives or exports that are being used at the top of the cells?

I am just using the

---
description: Basic Introduction of Bigram character-level language model which is one of the first topics to learn when learning about language models.
output-file: bigram.html
title: Bigram Language Model Character Level 

---


#| default_exp bigram
#| hide
from nbdev.showdoc import *

And in the end there is this below cell.

#| hide
import nbdev; nbdev.nbdev_export()

This is the link of the notebook. However I don’t know why the top cell which contains the description and title is not shown in the gist

I also try deleting the _proc directory and then run nbdev_preview or nbdev_docs but both doesn’t work. Whereas the nbdev_prepare returns success and working fine. Also after deleting the _proc directory when I run nbdev_preview or nbdev_docs it creates the _proc directory again, but returns the same error as mentioned in the first post.

Ok, I am able to reproduce the error using your same file. Let me review and I will let you know what I find!

It looks like the --- lines are causing the issues. I’m not sure why yet. Still researching that, but if you remove those (down the page, not the first cell), it should fix the error.

Ok, I got it narrowed down and think I have a solution for you now. The problem isn’t all of the --- but just the one where there is text directly below it.

Here is a minimal reproduction of the problem:

So for your specific example, you need to add a newline in this:

    "---\n", ######NEED ANOTHER NEWLINE HERE
    "Same shapes are always broadcastable (i.e. the above rules always hold)x=torch.empty(5,7,3)\n",
    "y=torch.empty(5,7,3)"
    "---\n", ####### AND HERE
    "x and y are not broadcastable, because x does not have at least 1 dimension"
    "---\n", ####### AND HERE
    "x and y are not broadcastable, because in the 3rd trailing dimension 2 != 3"
1 Like

Yes thank you. This was exactly the problem. I appreciate that you spend your time on it. But there is one issue if I use “—\n” the rendered markdown in jupyter notebook doesn’t show that horizontal line.

Markdown:


Rendered Markdown:

And in the GitHub pages it shows

I hope I am using the correct syntax like above. I also tried using without double quotes in the markdown but didn’t get the horizontal line in rendered markdown

1 Like

I’m sorry, I can see how that was confusing. Look at this screenshot:

The output that I was showing was the json under the hood of an ipynb file so it has extra quotes around stuff, but basically just find your three dash locations where you want a horizontal line and make sure there is a space directly after it. Let me know if you still have questions!

1 Like

Now I know three dashes then new line will fix. Image from GitHub pages

Also one addition we don’t need to have new line before the three dashes it will work fine. Below is image from rendered GitHub pages:

1 Like