Skip to main content

Posts

Showing posts from July, 2025

What is Tensors in electricity /Physics

  Tensors in Physics & Electricity: The Mathematical Swiss Army Knife What Is a Tensor in Physics? (The Simple Truth) In physics, a tensor is a mathematical object that describes how physical quantities change when you look at them from different angles or coordinate systems. Think of it as a "super-variable" that keeps track of how things transform in space. Simple analogy : If a scalar is like a temperature reading (same from any angle), a tensor is like stress on a beam - it matters which direction you're pushing and measuring from! The Hierarchy of Physical Quantities 🔢 Rank 0: Scalars (Regular Numbers) What : Single values, same from any viewpoint Examples : Temperature: 25°C Electric charge: -1.6 × 10⁻¹⁹ C Voltage: 12V Energy: 100 Joules 🡆 Rank 1: Vectors (Arrows) What : Magnitude + Direction Examples : Electric field: E = 100 N/C pointing north Current density: J = 50 A/m² flowing east Force: F = 10 N pushing down Velocity: v = 30 m...

What are Tensors in AI

  Tensors in AI: The Building Blocks of Deep Learning Explained What Is a Tensor? (The 30-Second Version) A tensor is just a container for numbers, organized in a specific shape. Think of it as: Scalar = Single number (0D tensor) Vector = List of numbers (1D tensor) Matrix = Table of numbers (2D tensor) Tensor = Numbers in 3D, 4D, or more dimensions That's it! Everything in deep learning is built on this simple concept. From Numbers to Neural Networks: A Journey Step 1: The Scalar (0-Dimensional Tensor) 42 Just a single number. Examples in AI: Learning rate: 0.001 Loss value: 2.34 Accuracy: 95.2% Step 2: The Vector (1-Dimensional Tensor) [1.2, 3.4, 5.6, 7.8] A list of numbers. Examples in AI: Word embedding: [0.2, -0.5, 0.8, ...] Neuron activations: [0, 0.9, 0.1, 0.7] Probabilities: [0.1, 0.3, 0.6] (cat, dog, bird) Step 3: The Matrix (2-Dimensional Tensor) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] A table of numbers. Examples in AI: Grayscale image: pix...

Compare Diffusion and Auto-Regression for say new Image or Video Creations

  Diffusion vs Auto-Regression: The Ultimate Showdown for Image and Video Creation The Big Picture Imagine two artists creating a painting: Auto-Regression : Paints pixel by pixel, left to right, top to bottom Diffusion : Starts with a messy canvas and gradually refines the entire image Both can create masterpieces, but they work in fundamentally different ways! Auto-Regression: The Sequential Storyteller How It Works Auto-regression generates content one piece at a time, like writing a story word by word: Next_Pixel = f(All_Previous_Pixels) For a 256×256 image, that's 65,536 sequential decisions! The Math (Simplified) P(image) = P(pixel₁) × P(pixel₂|pixel₁) × P(pixel₃|pixel₁,pixel₂) × ... Each pixel depends on ALL previous pixels. Examples Images : PixelCNN, PixelRNN, VQ-VAE Video : VideoGPT, TATS Famous : The original DALL-E (used VQ-VAE) Diffusion: The Noise Sculptor How It Works Diffusion starts with pure noise and gradually removes it: Clean_Image = Re...

TensorFlow Short Tutorials

  TensorFlow 2.x: Complete Step-by-Step Guide Table of Contents Introduction & Setup Tensors Basics Keras API Fundamentals Building Neural Networks Training & Evaluation CNN Example RNN/LSTM Example Custom Training Loops TensorFlow Advanced Features Deployment & Production Interview Questions 1. Introduction & Setup {#introduction} What is TensorFlow? TensorFlow is Google's open-source machine learning framework that supports: Eager execution (immediate operation evaluation) Graph execution (optimized computation graphs) Distributed training Production deployment across platforms Installation # CPU only pip install tensorflow # GPU support pip install tensorflow-gpu # Verify installation python -c "import tensorflow as tf; print(tf.__version__)" Basic Imports import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers, models import numpy as np import matplotlib.pyplot as plt # Check GPU availability print(...

PyTorch Competitors and Alternatives

  PyTorch Competitors and Alternatives 1. TensorFlow (Google) The main competitor to PyTorch. Key Features: TensorFlow 2.x : More user-friendly with eager execution TensorFlow Lite : Mobile and embedded devices TensorFlow.js : Browser-based ML TensorFlow Extended (TFX) : Production ML pipelines TPU support : Optimized for Google's hardware Comparison with PyTorch: # TensorFlow 2.x import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dense(10, activation='softmax') ]) # PyTorch equivalent import torch.nn as nn model = nn.Sequential( nn.Linear(input_size, 128), nn.ReLU(), nn.Linear(128, 10), nn.Softmax(dim=1) ) Pros: Better production deployment tools Stronger mobile/edge support Larger ecosystem Better visualization (TensorBoard) Cons: Steeper learning curve Less pythonic Debugging can be harder 2. JAX (Google) Rising star in research community. K...

PyTorch Short Tutorials

  PyTorch: Complete Step-by-Step Guide Table of Contents Introduction & Setup Tensors - The Foundation Autograd - Automatic Differentiation Neural Networks with nn.Module Training Loop CNN Example RNN/LSTM Example Transfer Learning Interview Questions 1. Introduction & Setup {#introduction} What is PyTorch? PyTorch is an open-source machine learning library developed by Facebook's AI Research lab. It provides: Dynamic computational graphs Strong GPU acceleration Rich ecosystem for deep learning Installation # CPU only pip install torch torchvision # With CUDA (GPU) pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 Basic Import import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F from torch.utils.data import DataLoader, Dataset import torchvision import torchvision.transforms as transforms 2. Tensors - The Foundation {#tensors} Creating Tensors # From data tensor_from_li...

How YIN Algorithm for Audio Pitch Detection Works

The YIN algorithm is a pitch detection method that accurately estimates the fundamental frequency of a signal. Here's a step-by-step explanation of how the YIN algorithm works: Step 1: Calculate the difference function Take an input buffer of audio samples and calculate the difference function. For each time lag Ï„ (tau) from 1 to half the buffer size, calculate the difference between each pair of samples that are Ï„ samples apart. Square these differences and sum them up for each Ï„. This gives you a new buffer (yinBuffer) of size halfBufferSize. Step 2: Calculate the cumulative mean normalized difference function Initialize the first element of yinBuffer to 1. For each Ï„ from 1 to halfBufferSize - 1, calculate the cumulative sum of the yinBuffer up to that Ï„. Divide the yinBuffer[Ï„] by the cumulative sum. This normalizes the difference function by the average of the differences up to that Ï„. If the cumulative sum is zero, set the yinBuffer[Ï„] to 1 to avoid division by ze...