Skip to content

Instantly share code, notes, and snippets.

@myazdani
myazdani / ridge.py
Last active September 26, 2023 13:39
Ridge regression in PyTorch
import torch
from torch import nn
import torch.nn.functional as F
class Ridge:
def __init__(self, alpha = 0, fit_intercept = True,):
self.alpha = alpha
self.fit_intercept = fit_intercept
def fit(self, X: torch.tensor, y: torch.tensor) -> None:
@myazdani
myazdani / torch-multinomial-picking-0-prob-element.ipynb
Created April 20, 2023 20:47
torch.multinomial picking 0 prob element.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / -1-trick-for-masking-subsets-of-sequence-for-loss.ipynb
Created March 29, 2023 05:18
-1 trick for masking subsets of sequence for loss.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / computing-jacobians-different-ways.ipynb
Created November 21, 2022 07:46
computing-jacobians-different-ways.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / glove-embeddings-load.py
Created March 31, 2019 18:44
Loading glove embeddings in Pandas DataFrame
import pandas as pd
import csv
glove_df = pd.read_csv("glove.6B.50d.txt.zip", sep=" ", index_col=0, header=None,
quoting=csv.QUOTE_NONE)
"new york" in glove_df.index
vocabs = list(glove_df.index)
@myazdani
myazdani / approximate-7up-embedding.ipynb
Created December 6, 2020 17:38
approximate-7UP-embedding.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import argparse
from loguru import logger
parser = argparse.ArgumentParser(description='Minimal example of dumping args into log file.')
parser.add_argument('--flag',type=str,
help='Some parameter flag')
args = parser.parse_args()
logger.add("file_{time}.log")
for arg, value in sorted(vars(args).items()):
@myazdani
myazdani / plotly-figure-representation.ipynb
Created April 5, 2020 22:29
plotly-figure-representation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / notes.txt
Created March 24, 2020 18:55
Working out a toy example on do-calculus for smoking causing cancer from Pearl's book "Book of Why"
p(c = True | tar = True, smoking = True) = 0.99
p(c = True | tar = False, smoking = True) = 0.2
p(c = True | tar = False, smoking = False) = 0.01
p(c = True | tar = True, smoking = False) = 0.99
p(smoking = True) = 0.1
p(smoking = False) = 0.9
p(tar = True | smoking = True) = 0.99
p(tar = False | smoking = True) = 0.01
@myazdani
myazdani / father_son_heights.tsv
Created December 2, 2019 23:10
Tab separated data of father and son heights as collected by Karl Pearson.
Father Son
65.0 59.8
63.3 63.2
65.0 63.3
65.8 62.8
61.1 64.3
63.0 64.2
65.4 64.1
64.7 64.0
66.1 64.6