This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing | |
from collections.abc import Iterable, Mapping | |
import pandas as pd | |
HashableT = typing.TypeVar("HashableT", bound=typing.Hashable) | |
T = TypeVar("T", pd.Series, pd.DataFrame) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this file uses a leading space in its name, to give the gist a nice name | |
this gist is some python code to reproduce the LLM arena leaderboard | |
it is based on https://colab.research.google.com/drive/1KdwokPjirkTmpO_P1WByFNFiqxWQquwH | |
but convert the huge json it uses to a smaller parquet file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Generate images using Dall-E, save the parameters and the output easily to file. | |
Usage: | |
```python | |
import os; os.environ["OPENAI_API_KEY"] = "SECRET_KEY" # set your API key | |
from generate_images import GeneratedImage, GeneratedImagesFile # import this code | |
img = GeneratedImage.generate("Astronaut") # generate an image | |
img # display the generated image + metadata in Jupyter | |
img.save_image("astronaut.png") # save a specific image |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import requests | |
def check_contributors(repo, username, token): | |
_owner, _repo_name = repo.split("/") | |
base_url = ( | |
"https://api.github.com/repos/{}/contributors?anon=1&per_page=100&page={}" | |
) | |
headers = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tqdm | |
from joblib import Parallel, delayed | |
class ParallelTqdm(Parallel): | |
"""joblib.Parallel, but with a tqdm progressbar | |
Additional parameters: | |
---------------------- | |
n_jobs: int, default: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
commit types from: https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional | |
and https://commitlint.js.org/reference/prompt.html | |
--> | |
# API changes | |
## feat: A new feature | |
✨:sparkles:Introduce new features. | |
💄:lipstick:Add or update the UI and style files. | |
📈:chart-with-upwards-trend:Add or update analytics or track code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
based on https://andyljones.com/posts/rl-debugging.html | |
Documentation is quoted from that blogpost. | |
The usual advice to people writing RL algorithms is to use a simple environment | |
like the classic control ones from the Gym. Thing is, these envs have the same | |
problem as looking at loss curves: at best they give you a noisy indicator, and | |
if the noisy indicator looks poor you don't know why it looks poor. They don't | |
localise errors. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing as mp | |
import queue | |
import signal | |
from functools import partial | |
from typing import Callable, Iterable | |
def get_queue() -> queue.Queue: | |
""" | |
return a multi-processing queue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain | |
from pathlib import Path | |
class PathGroup(list): | |
def __getitem__(self, y): | |
res = super().__getitem__(y) | |
return PathGroup(res) if (type(res) == list) else res | |
def glob(self, pattern): | |
return PathGroup(chain.from_iterable(sorted(p.glob(pattern)) for p in self)) | |
def __getattr__(self, name): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import xarray as xr | |
def register_dataarray_module(module, accessor_name=None): | |
if accessor_name is None: | |
accessor_name = module.__name__.split(".")[-1] | |
callable_funcs = [name for name in dir(module) if callable(getattr(module, name))] |
NewerOlder