Reload Modules

If I am developing a module, and testing it on a jupyter notebook, I would add the following lines to the beginning of the notebook.

%load_ext autoreload
%autoreload 2

With these magical commands, the modifications on the module code would immediately affect the result on the jupyter notebook.

Export to HTML with TOC

For the lateset jupyter notebook 7+, we can not export notebook to a single HTML page anymore. This has been a long term issue and it’s not likely to get fixed.

The way to get nice HTML is to

  1. install quarto from their webiste.
  2. install pandoc. On Debian 12, this is possible with apt.
  3. Execute the following command.
quarto render FILENAME.ipynb --to html

If we want to have a self–contained html file with TOC, we can add the following raw cell to the beginning of the notebook.

---
title: "Preprocessing Unstructured Data for LLM Applications"
format:
  html:
    toc: true
    css: styles.css
    embed-resources: true
    html-math-method: katex
---

Install / Uninstall a Kernel

If I have many multiple versions of Python install on my machine, I would want to use them separately and clarely in jupyter notebook. For instance, if I have the versions of 3.6.8, 3.7.3, 3.8.1 and 3.9.0, I would not want to have a kernal naming Python3, because this is not specific.

To be more specific, I use the following command to install those kernels separately, with special names such as Python368.

# install python to the kernel, customise the NAME of the kernel
pip install ipykernel
python -m ipykernel install --user --name NAME --display-name "NAME"

# uninstall a particular kernel
jupyter kernelspec uninstall NAME

Install Image and Resize

The default chose of inserting an image into the markdown cell of jupyter notebook is the following line.

![](link_to_image)

However, the image size is fixed in this size, and quite often the image is way too big. To insert an image with the desired size, I will need to write the html code, instead of the markdown.

<img src='image' alt="Drawing" style="width: 200px;"/>

(Caveat: the render would not work on GitHub.)

Connecting to Server

I want to use BlueCrystal (HPC in University of Bristol) in my own laptop, with jupyter notebook. This is what I will have to do

start notebook in blue crystal

Run jupyter notebook --no-browser in blue crystal, getting something like this

to login with a token:
    http://localhost:8888/?token=xxxxxx

forward remote port to local

Start another session, log to blue crystal again, with following command

ssh yy17363@bluecrystalp3.acrc.bris.ac.uk -L 8888:localhost:8888 -N

(notice I will have to kill local notebook server if it use 8888 as port)

use notebook

copy the link

http://localhost:8888/?token=xxxxxx

to the browser and enjoy!