Exercise#1 Neural Network

Objective

Create a neural network that can predict the output number based on the given input number. For this exercise use a linear equation to generate the synthetic data for training. The neural network model will take a single input (x) and generate a single number as output (y).

ax-plus-b.png

Note

  • The intent of this exercise is to demystify neural networks
  • The linear equation problem does not require neural network to solve :)
  • As a Generative AI app developer or architect you don’t need to learn how to code neural networks

Code layout

The code used in the demo is divided into 5 steps:

Step-1: Generate synthetic data for training

Step-2: Define the neural network model

Step-3: Define the loss function & optimizer

Step-4: Train the model

Step-5: Test the model

Visual representation

This is the visual representation of the neural network created by the code.

exercise-1-neural-network

Demo code

  • Code is available under the repository folder AI-Essentials/basic_neural_network_demo.ipynb
  • Code was generated with ChatGPT with the prompt:

generate demo code for pytorch based neural network. This neural network will be trained for predicting the output for a linear function like ax+b

  • Open in Google Colab Open In Colab

Suggestions for further experimentation (Optional)

  1. Change the structure of the model
  2. Try out the model for large value of x
  3. Re-train the model with different set of x_train
  4. Create a neural network to solve Quadratic equations
  5. Use the code with some real dataset for a non-regression problem !!