Skip to content

Instantly share code, notes, and snippets.

View vhxs's full-sized avatar
💻
coding or mathing

Vikram Saraph vhxs

💻
coding or mathing
View GitHub Profile
@vhxs
vhxs / move_triangles.py
Created August 12, 2023 19:12
ChatGPT-generated code to animate a coupla triangles
import pygame
# Initialize Pygame
pygame.init()
# Set up display
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pygame Glide Transformation Animation")
@vhxs
vhxs / langchain_arxiv.py
Created August 12, 2023 17:35
Using LangChain to ask about one of my papers.
from langchain.document_loaders import OnlinePDFLoader
from langchain.indexes import VectorstoreIndexCreator
loader = OnlinePDFLoader("https://arxiv.org/pdf/1606.06353.pdf")
documents = loader.load()
index = VectorstoreIndexCreator().from_documents(documents)
print(index.query("What are the main results of this paper?"))
@vhxs
vhxs / langchain_mastodon.py
Last active August 12, 2023 17:30
Using LangChain's question answering capability to ask questions about what I post on Mastodon
from langchain.document_loaders import MastodonTootsLoader
from langchain.indexes import VectorstoreIndexCreator
from langchain.vectorstores.utils import filter_complex_metadata
loader = MastodonTootsLoader(mastodon_accounts=["@[email protected]"], number_toots=300)
documents = loader.load()
documents = filter_complex_metadata(documents)
index = VectorstoreIndexCreator().from_documents(documents)
print(index.query("What kinds of interests does this user have?"))
@vhxs
vhxs / cpu_vs_gpu_torch.py
Created August 6, 2023 21:27
GPU vectorization via PyTorch
import numpy as np
import torch
from datetime import datetime
if __name__ == '__main__':
num_dims = 3
dim = 1024
for _ in range(10):
@vhxs
vhxs / with_trinity.py
Created June 20, 2023 01:15
with trinity
import torch
import torchvision
import torchvision.transforms as transforms
import torch.optim as optim
import torch.nn as nn
import umap
import matplotlib.pyplot as plt
import json
trinity_template = {
@vhxs
vhxs / resnet18_on_cifar100.py
Last active June 11, 2023 02:59
Fastest possible example of GPU training and inference that I could get working
import torch
import torchvision
import torchvision.transforms as transforms
import torch.optim as optim
import torch.nn as nn
import umap
import matplotlib.pyplot as plt
# Check whether GPU is available and define it as a device
is_gpu_available = torch.cuda.is_available()
@vhxs
vhxs / conv_matrix.py
Created April 30, 2023 15:54
Visualize a convolution operator's matrix representation
import torch
import matplotlib.pyplot as plt
def generate_basis(num_channels, height, width):
zero_tensor = torch.zeros((num_channels, height, width))
for i in range(num_channels):
for j in range(height):
for k in range(width):
basis_element = torch.clone(zero_tensor)
@vhxs
vhxs / euclidean_metric.py
Last active April 2, 2023 04:17
Points sampled from a Euclidean space should hopefully always embed in a Euclidean space
import numpy as np
# Give me some random vectors
def random_vectors_generator(dimension=10, num_vectors=10):
for _ in range(num_vectors):
yield np.random.rand(dimension)
# Give me a random distance matrix
@vhxs
vhxs / jaccard_metric_counterexample.py
Last active June 25, 2023 04:05
Jaccard metric spaces cannot be isometrically embedded in Euclidean space
import numpy as np
from random import sample
# The Jaccard distance is truly a metric: https://arxiv.org/pdf/1612.02696.pdf
def jaccard_distance(set1: set, set2: set):
union_size = len(set1.union(set2))
intersection_size = len(set1.intersection(set2))
return 1 - (intersection_size / union_size)
@vhxs
vhxs / maybe_blank_text_file.txt
Created February 4, 2023 20:44
image uploads?
hey look here's me writing something