Data Loading for Machine Learning

When we load data to train a neural network model, We usually split data into the training data and testing data. Then the training data is further split into batches to train the model. This is done to reduce the memory usage and speed up the training process. Let’s see how to load data into a neural network model using PyTorch. Dataset pytorch provides a Dataset class to load data into a neural network model. We can create a custom dataset by inheriting the Dataset class and implementing the __len__ and __getitem__ methods. ...

Neural Network Model Dissection

Data Flow Inside a Neural Network Model Inside a Neural Network Model, when we pass in a value it should some other value. Let’s inspect an example model import torch import torch.nn as nn class NeuralNetwork(nn.Module): def __init__(self): super(NeuralNetwork, self).__init__() self.input_layer = nn.Linear(1, 1) def forward(self, x): x = self.input_layer(x) return x Here, we have a simple neural network model with a single input and output layer. The input layer has a single node and the output layer has a single node. ...

Neural Networks

AI had been really influencing our daily life, It’s a powerful tool to help us with a lot of tasks. As of 2024 There are prototypes of self driving cars to humanoid robots that does chores. Neural Network is the core of the whole Machiene Learning and AI all around us. Let’s break down Neural Networks with examples in pytorch. What is a Neural Network? Neural Network is a programmable network of neurons called nodes with layers to compute and return few outputs. It’s a model that can be trained to recognize patterns in data. ...

Why Go error handling is my favorite

Go has very simple and efficient error handling mechanism. Error as value is very powerful concept and some people find it annoying. I think errors should be annoying so that we don’t ignore them. Most notable aspects of go’s error handling I found myself are: It is just straight forward and simple, I didn’t have to do anything clever to tweak it and make it more erganomic. I got used to it quickly after a bit of skepticism. I believe It’s common for us to force a familiar paradigm when we try new languages and when it’s different, we tend to question it. I had to think more about error handling and it made me write more robust code. I always write prototypes in other languges by ignoring errors and it can slip to production, even if I ignore errors in go, there is an explicit _ which reminds me that I’m ignoring an error. Error as value In go, a typical function defintion can give away if it returns an error or not. If a function returns an error, it’s usually the last return value. This makes it very easy to identify if a function can return an error or not. ...

Zig Overview

Zig is a systems programming language that emphasizes simplicity, performance, and safety. It has gained attention for its minimalistic approach and powerful features. Zig is particularly well-suited for developing low-level systems and applications where control over hardware and performance are critical. Features of Zig No hidden control flow: Zig has no hidden control flow, which means that the behavior of the program is predictable and easy to understand. This makes debugging and optimization easier. Error handling: Zig has a unique error handling mechanism that is designed to be simple, efficient, and safe. It uses compile-time checks to ensure that errors are handled correctly. Compile-time execution: Zig supports compile-time execution, which allows developers to run code at compile time to generate data or perform computations. This feature can be used to generate code, perform optimizations, or validate data. Memory Management: Zig provides fine-grained control over memory management, allowing developers to manage memory allocation and deallocation manually. This can help reduce memory overhead and improve performance. Interop with C: Zig has excellent interoperability with C, allowing developers to call C functions and use C libraries directly. This makes it easy to integrate Zig code with existing C codebases. Variables In Zig, variables are declared using the var keyword followed by the variable name and type. Zig supports type inference, allowing developers to omit the type when it can be inferred from the value. ...

Implementing Redis in Golang

Redis is well known for a in-memory data store which is widely used as cache, database and message broker. In this article, we will implement a simple Redis client in Golang. Let’s look at the basic parts like, Listening to a port Accepting connections Reading the commands Parsing the commands Handling the commands Listening to a port We can use the net package in Golang to listen to a port. We can use the net.Listen function to listen to a port. ...

Setting up Observability in your app

Observability is a very important topic to consider in any application just like Tests. It helps understand a lot about how our system works, and measure a lot of aspects to make data-driven decisions. It can mostly be a go-to guide to what is happenning in your system, and how to improve it. Parts of Observability I’d like to categorize Observability into 3 parts: Logging: Logging is the logs we generate from our application usually in levels like info, debug, error, warn, etc. These logs are custom messages that we can use to debug our application or monitor each event that happens in our application. Metrics: Metrics or data points are the data we collect from our application to monitor the performance of our application. These metrics can be anything like the number of requests, response time, etc. Tracing: Tracing is the process of monitoring the flow of a request through our application. It helps us understand how a request is processed in our application. Setting up Observability For logging ...

Phoenix - Overview

Phoenix web framework had been there since a while and it caught my attention with it’s LiveView feature. The framework is built on top of Elixir and the BEAM VM is designed for highly concurrent, distributed systems. This means Live view and sockets are gonna be really feasible with Phoenix. Getting Started We need to install Elixir brew install elixir and then install Phoenix using mix. mix archive.install hex phx_new Mix is the build tool for Elixir and Phoenix uses mix to create new projects and manage dependencies. ...

Gleam Overview

Gleam is a statically typed language for the Erlang VM (BEAM). It is designed to be a productive and fun language to work with. Gleam is a compiled language, which means that it is compiled to BEAM bytecode and runs on the Erlang VM. It is a functional programming language with a strong type system that helps catch errors at compile time. Few things I like about Gleam are: Gleam ships with all language tooling just like Go. This makes it easy to get started with Gleam. Gleam’s async support is very good. It is easy to write concurrent code in Gleam. No nulls representation in Gleam. This makes it easier to write safe code. Few things I dislike about Gleam are: ...

Vim Inspired modern IDEs

I learned vim a while ago but really didn’t use it for main projects or daily work. Lately I decided to rebuild my neovim config from scratch and really enjoyed setting up and using all the parts. It inspired me to setup similar configurations in other modern editors. While looking around the internet for similar setups, I found that zed is a very attractive choice for a good combination of vim and modern IDE features. ...