Skip to content

Instantly share code, notes, and snippets.

View wiseodd's full-sized avatar

Agustinus Kristiadi wiseodd

View GitHub Profile
from __future__ import annotations
import warnings
warnings.filterwarnings("ignore")
import torch
from gpytorch.likelihoods import Likelihood
from gpytorch.mlls import ExactMarginalLogLikelihood
from botorch.models.gp_regression import SingleTaskGP
from gpytorch.kernels import Kernel
from collections.abc import MutableMapping
from collections import UserDict
import numpy
import torch
from torch import nn
import torch.utils.data as data_utils
from laplace import Laplace
from laplace.curvature import CurvlinopsGGN, AsdlGGN
from laplace import Laplace
from laplace.curvature import CurvlinopsGGN
import torch
from torch import nn
import torch.utils.data as data_utils
from collections import UserDict
import collections.abc as cols_abc
class Model(nn.Module):
@wiseodd
wiseodd / beam_search.py
Created March 31, 2024 17:57
Beam Search
import torch
import tqdm
from transformers import GPT2Tokenizer, GPT2LMHeadModel
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
tokenizer.pad_token = tokenizer.eos_token
model = GPT2LMHeadModel.from_pretrained('gpt2').to(torch.bfloat16)
assert next(model.parameters()).dtype == torch.bfloat16
input_text = 'Earth is'
import warnings
warnings.filterwarnings('ignore')
import torch
from laplace import Laplace
from helper.dataloaders import get_sinusoid_example
from laplace import Laplace
n_epochs = 1000
torch.manual_seed(711)
@wiseodd
wiseodd / llla_img2img.ipynb
Created November 23, 2022 13:38
Last-Layer Laplace for Image2Image Problems
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wiseodd
wiseodd / natural_grad.py
Created March 13, 2018 19:36
Natural Gradient Descent for Logistic Regression
import numpy as np
from sklearn.utils import shuffle
# Data comes from y = f(x) = [2, 3].x + [5, 7]
X0 = np.random.randn(100, 2) - 1
X1 = np.random.randn(100, 2) + 1
X = np.vstack([X0, X1])
t = np.vstack([np.zeros([100, 1]), np.ones([100, 1])])
@wiseodd
wiseodd / pde_numpy.py
Created January 8, 2017 05:48
Implementation of Finite Difference solution of Laplace Equation in Numpy and Theano
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import time
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
plt.ion()
fig = plt.figure()
@wiseodd
wiseodd / gan.py
Last active September 1, 2020 10:22
Generative Adversarial Nets (GAN) implementation in TensorFlow using MNIST Data.
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import os
def xavier_init(size):
in_dim = size[0]
import numpy as np
from sklearn.datasets import make_moons
from sklearn.cross_validation import train_test_split
n_feature = 2
n_class = 2
def make_network(n_hidden=100):