After discussing about the fundamentals of Neural Networks and Deep Learning, we have arrived to an exciting stage where we can learn how we program a Neural Network.
I have created some simple programs to get some basic idea on how to program a Neural Network and I have used a Python library called PyTorch to program it.
Program 1 : Calculate total numbers of parameters in a neural network
Points to remember :
- We need to import nn submodule from main module torch
- We need to inherit the Module class available in torch.nn submodule
- We should use self otherwise method doesn't get class objects data
- Do not confuse about forward(), we don't call it directly, it will be called via constructor in super class. Hence using self.
- p.numel() return the elements in the Model. Please see my explanation in the downloaded code
- Need basics of Oops concepts in Python
GitHub location : https://github.com/amathe1/GenAI-AgenticAI-Hub/blob/main/Calulate_Params_in_Neural_Network.ipynb
Also, please find more explanation in the program once you download. Finally, it printed total number of parameters in the entire Neural Network. We could also see weight and bias values of our ML model.
Program 2 : House price prediction based on house size and no. of rooms
This is a full length NN programming with entire flow.
Points to remember :
- In real time, we get the data either from files, cloud etc. and we need to segregate it properly
- this is whole different activity!
- there are ML teams dedicated only to do this activity, imagine the level of complexity and depth in segregating data
- we need to remove outliers etc. before injecting this data to ML models
- for ease of understand, we considered simple data X, Y(tensors)
- X contains data like house size in sqft & no. of bedrooms, it have 5 records
- Y represents actual price, we need to come close to these values using our ML model
- Please ignore logic like model knows what is size and what is price, we need to understand the concept of co-relation for it, for now I recommend you to concentrate on the programming part and understand the logic behind a NN
Please download below program for more clarity on explanation. Observe that for 500 epochs, model started learning and came up with lower loss.
GitHub location : https://github.com/amathe1/GenAI-AgenticAI-Hub/blob/main/House_Price_Prediction.ipynb
Conclusion :
I am coming up with more programs on building a ML model for different problem statements. Incase if you are interested, then please watch out this GitHub space : https://github.com/amathe1/GenAI-AgenticAI-Hub/tree/main
Thank you for reading this blog !
Comments
Post a Comment