Skip to content

Instantly share code, notes, and snippets.

View sumanmichael's full-sized avatar

Suman Michael sumanmichael

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sumanmichael on github.
  • I am sumanmichael (https://keybase.io/sumanmichael) on keybase.
  • I have a public key ASD1wzElG_voZQBacUCrvmz0gEUa9UKDfZdBaM3ISl-HxAo

To claim this, I am signing this object:

@sumanmichael
sumanmichael / conv_2d_with_same_padding.py
Created June 3, 2021 13:35
PyTorch Conv2d equivalent of Tensorflow tf.nn.conv2d(....,padding='SAME')
import tensorflow as tf
import torch
from torch import nn
import numpy as np
from functools import reduce
from operator import __add__
class Conv2dSamePadding(nn.Conv2d):
@sumanmichael
sumanmichael / tf_batch_norm_in_pytorch.py
Created June 21, 2021 11:01
Tensorflow BatchNormalization's Equivalent in PyTorch (incl. Loading Weights)
class BatchNorm2d(nn.Module):
# `num_features`: the number of output channels for a convolutional layer.
def __init__(self, num_features):
super().__init__()
shape = (1, num_features, 1, 1)
self.weight = nn.Parameter(torch.ones(shape))
self.bias = nn.Parameter(torch.zeros(shape))
self.moving_mean = torch.zeros(shape)
@sumanmichael
sumanmichael / get_pytorch_lstm_weights_from_tensorflow.py
Last active June 22, 2021 04:37
Get pytorch LSTM weights (w_ih, w_hh, b_ih, b_hh) from tensorflow LSTM weights (kernel, bias)
import torch
from torch import nn
import numpy as np
# Get pytorch LSTM weights (w_ih, w_hh, b_ih, b_hh) from tensorflow LSTM weights (kernel, bias)
def get_pytorch_lstm_weights_from_tensorflow(kernel, bias, INPUT_SIZE, HIDDEN_SIZE):
def reorder_lstm_gates(w):
# The split order of gates are different in pytorch and tensorflow
# i = input_gate, j = new_input, f = forget_gate, o = output_gate
@sumanmichael
sumanmichael / oracle_fdw_ubuntu.sh
Created December 22, 2022 11:55
Install oracle_fdw in Ubuntu
# Tested with oracle_fdw 2.5.0, PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg22.04+1), Oracle client 21.8.0.0.0
# user: root
apt update
apt install -y wget unzip
# change the postgres version here (15)
# also make sure you've configured postgres repository and installed this way: https://www.postgresql.org/download/linux/ubuntu/
apt install -y build-essential libaio1 postgresql-server-dev-15
dnf -y update
dnf -y install oracle-database-preinstall-19c.aarch64
mkdir -p /u01/app/oracle
chown -r oracle:oinstall /u01/app
systemctl stop firewalld
# Optional:
passwd oracle
@sumanmichael
sumanmichael / rag_chatbot.py
Created November 22, 2023 20:49
RAG ChatBot using OpenAI's LLM and LangChain
import os
os.environ["OPENAI_API_KEY"] = "Set-Your-Key"
# For retriving the data from the website
import bs4
from bs4 import BeautifulSoup as Soup
from langchain.document_loaders.recursive_url_loader import RecursiveUrlLoader
# For accessing the database
from langchain.vectorstores.pgvector import PGVector
# For Embedding and accessing LLM Model