Sumanth Profile picture
Jul 25, 2023 9 tweets 3 min read Read on X
Neural Network implemented from scratch in Python🔥

Here is the step by step explanation with code.

Thread🧵👇 Image
Below is the simple Neural Network consists of 2 layers:

- Hidden Layer
- Output Layer

First Initialize the size of layers along with the weights & biases.

And also define the sigmoid activation function & it's derivative which is really key to introduce non-linearity. Image
Forward Pass:

Here the input data is passed through the neural network to obtain the predicted output.

In forward pass, First calculate the output of the hidden layer.

hidden_output = X•W1 + b1

Then apply the sigmoid activation to the output.

output = sigmoid( (X•W1) + b1) Image
Backward Pass:

First compute the gradients of the output layer.

Loss = (y - output)

Gradient of Loss = (y - output) * sigmoid_derivative(output)

Now calculate d_W2 which is gradient of the loss function with respect to W2.

d_W2 = hidden_output.T • Gradient of Loss Image
Similarly calculate d_W1, d_b2 & d_b1

dW1: Gradient of the loss function wrt W1

d_b2: Gradient of the loss function wrt b2(bias of neuron in output layer)

d_b1: Gradient of the loss function wrt b1(bias of neuron in hidden layer) Image
Now Update the Weights:

Here learning rate is the hyper parameter!

A low learning rate can cause the model getting caught in local optima, while the high learning rate can cause the model to overshoot the general solution

W1 += learning_rate * d_W1
b1 += learning_rate * d_b1 Image
Now a method to train the neural network using both the forward and backward passes.

The function will run for specified no of epochs, calculating:

1. The Forward Pass
2. Backward Pass
3. Updating the Weights Image
Finally the Predict Function

Now to predict on any new data all we need to do is a single Forward Pass through the Network: Image
That's a wrap!

Every day, I share and simply content around Python, Data Science, Machine Learning & Large Language Models.

Find me → @Sumanth_077 ✅

Like/RT the first tweet and help this reach more people.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Sumanth

Sumanth Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Sumanth_077

May 25
Microsoft released an AI powered data analysis tool!

Data Formulator is an AI-powered tool for analysts to iteratively create rich visualizations.

It's no-code & 100% open-source Image
If you found it useful, reshare it with your network.

Follow me → @Sumanth_077 for more such content and tutorials on ML, LLMs and AI Agents!

Read 4 tweets
May 1
Let's build a PDF RAG Agent, step-by-step:
1. Here’s what we’re building:

The agent pulls context from the indexed PDF files stored in vector DB. If needed, it can also fall back to web search to provide more relevant answers.

Tech stack:

@milvusio for vector DB as knowledge base
@AgnoAgi for agent orchestration
2. Install Milvus

We use Milvus, an open-source vector database, to store document embeddings.

Milvus supports flexible deployments via Kubernetes, Docker, or Lite mode via pip install.

Let's run the "standalone_embed. sh" script to launch Milvus in Docker standalone mode. Image
Read 10 tweets
Apr 26
5 MCP servers that will give superpowers to your AI Agents.

100% open source.
1. Fast API

Turn any FastAPI app into an MCP server!

FastAPI-MCP is a zero-configuration tool for automatically exposing FastAPI endpoints as Model Context Protocol (MCP) tools.

github.com/tadata-org/fas…
2. Github MCP

The Github Official MCP server comes with seamless integration with GitHub APIs, enabling advanced automation and interaction capabilities for developers & tools.

github.com/github/github-…
Read 8 tweets
Apr 12
I've been coding in Python for 5 years now.

If I were to start over today, here's a roadmap:
1. CS50’s Introduction to Programming with Python:

The course is designed for students with or without prior programming experience who’d like to learn Python specifically.

Check this out: cs50.harvard.edu/python/2022/
2. Corey Schafer

Best YouTube channel to learn Python!

Corey explains every python concept from scratch along with project-based implementation.

Check it out: youtube.com/@coreyms
Read 6 tweets
Apr 9
5 MCP servers that will give superpowers to your AI Agents.

100% open source.
1. @firecrawl_dev MCP server

Firecrawl MCP lets you scrape, crawl, search, extract, and run deep research at scale.

It supports JS rendering, batch scraping, URL discovery, and full content extraction from web search.
2. Browser Use MCP Server

This MCP server enables AI agents to control web browsers using browser-use.

github.com/co-browser/bro…
Read 7 tweets
Feb 11
Let's build a RAG app over Excel sheets using Docling and DeepSeek-R1 (100% local):
1. Check out the RAG app we're building!

This app allows you to upload Excel files and chat with them using the DeepSeek-R1 model running locally.

Built entirely in Python using @getreflex
@getreflex 2. Backend State

Define state variables to manage the chat, file uploads, and knowledge base. Image
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(