Skip to article frontmatterSkip to article content

Introduction

City University of Hong Kong

What is deep learning?

The following videos showcase some interesting applications of the technique.

We can run a generative model locally using ollama. To do so, start the ollama service as follows.

  1. In JupyterLab, navigate to the File menu.
  2. Select New from the drop-down menu and choose Terminal.
  3. The terminal window will appear. You can use this terminal to run a shell command. Enter the following command into the terminal prompt and hit enter.
    ollama serve

Load the JupyterAI magics by running the following cell.

  1. Select the following cell.
  2. Press Shift+Enter.
%reload_ext jupyter_ai_magics

Run the following cell to generate an explanation of what generative AI is.

%%ai diveai:codellama
Explain what is generative AI.

Try a few other examples:

%%ai diveai:codellama -f math
Generate the Pythagoras theorem in LaTeX surrounded by `$$`. Do not include an explanation.
%%ai diveai:codellama -f html
Create a right-angled triangle using SVG with a black border and white fill.

There is also a Jupyternaut chatbot:

  1. Click the chat icon on the left menu bar. A chat panel will open.
  2. Click the gear icon on the chat panel to set up the provider.
  3. Select the Completion model as AI :: codellama, the Embedding model as AI :: mxbai-embed-large, and click the Save Changes button.
  4. Click the back arrow at the top to go back to the chat window.
  5. Enter how are you today? to see a response. You can also ask Jupyternaut to learn local data.

Different models may be of different sizes and may be good at different things. You may try other models from the list below such as llama3.

!ollama list

How to train a neural network?

Deep learning is a technique of

  • training a neural network with
  • many layers of computational units called neurons.

Tensorflow playground

Let’s visualize the training process!
The following trains a neural network that predicts the color of a point (x1,x2)(x_1,x_2):

  • Choose a data set from the DATA column.
  • Click the play button to start training the network.
  • Epoch is the number of times a neural network is trained iteratively using the data selected.
  • In the OUTPUT column,
    • points in the blue region are predicted blue, and
    • points in the orange region are predicted orange.

The above app is a slight modification of the open source project Tensorflow Playground with the additional features that:

  • You can save your configuration to the browser session by clicking the button Save to browser session. If you reopen the browser, it will load your previously saved configuration automatically.
  • You can reset the configuration by clicking the Reset button.
  • The last button Copy permalink to clipboard copies the permalink to your configuration to the clipboard. You can save/share multiple configurations permanently using their the permalinks.

For instance, the following uses the permalink to initialize the simplest neural network for a linearly separable data:

Solution to Exercise 1

One possible solution is to add the features sin(X1)\sin(X_1) and sin(X2)\sin(X_2), and add 4 more nodes to the first hidden layer:

Teachable machine

It is possible to train a practical neural network without any coding, by using a service called the Teachable Machine.

E.g., click the play button at the bottom of the interactive slides below to train a machine that recognizes musical notes.

Solution to Exercise 2

The following links to a machine that classifies three musical notes: “Doe”, “Ray”, and “Me”:
https://www.cs.cityu.edu.hk/~ccha23/drm/