Skip to content

Instantly share code, notes, and snippets.

import cv2
import numpy as np
# Load the input image
image = cv2.imread('input.jpg')
# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply gaussian blur to the image
@OhadRubin
OhadRubin / KL_controller.md
Created January 12, 2023 14:54
KL_controller
@OhadRubin
OhadRubin / gitlog.py
Created February 13, 2023 15:46
Prints out the most changed files in a repo
import os
counts = {}
for hash in os.popen('git log --all --format=%H'):
hash = hash.strip()
os.system('git checkout {}'.format(hash))
for fname in os.popen('git diff --name-only HEAD^ HEAD'):
fname = fname.strip()
counts[fname] = counts.get(fname, 0) + 1
print('Most changed files:')
print('-------------------')
@OhadRubin
OhadRubin / chat.py
Created March 2, 2023 12:32
chat.py
from colorama import Fore, Back, Style
import os
import openai
# Set up OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
prompt = """Your prompts here"""
# Set up initial message
messages = [{"role": "system", "content": }]
@OhadRubin
OhadRubin / variable_capture.py
Created March 8, 2023 08:19
a context manager to capture variables
import inspect
from contextlib import ContextDecorator
class VariableCapture(ContextDecorator):
def __enter__(self):
frame = inspect.currentframe().f_back
self.keys = {k for k,v in frame.f_locals.items() if k != 'self'}
return self
def __exit__(self, exc_type, exc_value, traceback):
@OhadRubin
OhadRubin / seqio_hf_tokenizing.py
Created April 10, 2023 09:00
Uses a queue and a multiprocessing pool to tokenize a tf dataset
import multiprocessing
import tensorflow as tf
import seqio
import numpy as np
import tqdm
from transformers import AutoTokenizer
import jax
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
tokenizer.pad_token = tokenizer.eos_token
#The following code is the result of taking the code for gpt-j-6b and changing the model name and config name to gpt-neox along with concating the gpt-neox code from pytorch
# our job is to modify it such that it will be correct for gpt-neox, since right now it is just a copy of gpt-j-6b (with names replaced)
from functools import partial
from typing import Optional, Tuple
import flax.linen as nn
import jax
import jax.numpy as jnp
import numpy as np
from flax.core.frozen_dict import FrozenDict, freeze, unfreeze
import numpy as np
class PythagoreanTriples:
def __init__(self):
self.m = 2
self.n = 1
def __iter__(self):
return self
def __next__(self):
@OhadRubin
OhadRubin / dag.py
Last active December 25, 2024 00:13
import networkx as nx
from itertools import product
"""
When we compare this code with Airflow, the strengths of your code lie in its simplicity, lightweight nature, and the ability to easily integrate with existing Python code:
Simplicity: This code provides a simple and straightforward way to model and work with DAGs without needing to go through the process of setting up and configuring a comprehensive system like Airflow. For smaller teams or projects with less complexity, this can be an advantage.
Lightweight and easy to incorporate: Your code is a compact, single-file solution that can be easily integrated into an existing Python project without having to set up an entire Airflow environment. When your primary focus is on creating task dependencies with parameter combinations, rather than scheduling and monitoring, your code is easier to incorporate.
Focused on task generation: Your code emphasizes creating a Cartesian product of tasks associated with nodes' parameters. It is geared towards tackling
@OhadRubin
OhadRubin / spcfg.py
Last active July 4, 2023 07:02
Synchronous Probabilistic Context-Free Grammars sampling
import nltk
import random
class ProductionRule:
def __init__(self, production):
self.production = production
def get_lhs(self):
return self.production.lhs()