Skip to content

Instantly share code, notes, and snippets.

@OhadRubin
OhadRubin / combine_txt.md
Created September 28, 2023 13:13
combine_txt_prompt

Instructions

Your task: Combine multiple texts into one detailed document. Include every piece of information from each source. The goal is to avoid repetition while being thorough and exhaustive.

Essential steps:

  1. Organize structure carefully.
  2. Integrate all details.
  3. Avoid redundancy.

Warnings:

  • Be precise, not general.
@OhadRubin
OhadRubin / simple_gin.py
Created September 24, 2023 06:17
A simple example of using gin with absl
import fire
import gin
from absl import flags
from absl import app
flags.DEFINE_multi_string(
'gin_file', None, 'List of paths to the config files.')
flags.DEFINE_multi_string(
'gin_param', None, 'Newline separated list of Gin parameter bindings.')
import requests
import json
class GistDictionary:
def __init__(self, github_token, base_gist_id):
self.github_token = github_token
self.base_gist_id = base_gist_id
self.headers = {
"Authorization": f"token {github_token}",
"Accept": "application/vnd.github.v3+json",
@OhadRubin
OhadRubin / injecting.py
Created July 4, 2023 11:41
injecting numeracy
import random
from sympy import Eq, Symbol, solve
from transitions import Machine
class WordProblemStateMachine:
def __init__(self):
self.global_state = {}
@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()
@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
import numpy as np
class PythagoreanTriples:
def __init__(self):
self.m = 2
self.n = 1
def __iter__(self):
return self
def __next__(self):
#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
@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
@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):