Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@kastnerkyle
kastnerkyle / semantic_search_with_gzip.py
Created July 15, 2023 14:25 — forked from kyo-takano/lexical_search_with_gzip.py
Semantic Search with gzip (gzipによるセマンティック検索)
import gzip
def gzip_search(query: str, candidate_chunks: list[str], top_k: int=1):
"""
文字列ベースで類似したテキストチャンクを推定するアルゴリズム.
`query`, `chunk`, および`query + " " + chunk`をそれぞれgzipで圧縮し、編集距離のようなものをベースに評価する.
Parameters:
query (str): 検索クエリとして使用する文字列.
top_k (int, optional): 返される類似チャンクの上位k個を指定する (default: 1).
@kastnerkyle
kastnerkyle / pytorch-glumpy.md
Created March 4, 2020 22:45 — forked from victor-shepardson/pytorch-glumpy.md
using pycuda and glumpy to draw pytorch GPU tensors to the screen without copying to host memory
@kastnerkyle
kastnerkyle / find_noise.py
Created September 12, 2022 00:00 — forked from trygvebw/find_noise.py
A "reverse" version of the k_euler sampler for Stable Diffusion, which finds the noise that will reconstruct the supplied image
import torch
import k_diffusion as K
from PIL import Image
from torch import autocast
from einops import rearrange, repeat
def pil_img_to_latent(model, img, batch_size=1, device='cuda', half=True):
init_image = pil_img_to_torch(img, half=half).to(device)
init_image = repeat(init_image, '1 ... -> b ...', b=batch_size)
import math
import torch
from torch import optim
class AdamWFinetune(optim.Optimizer):
r"""Implements AdamW algorithm with optional weight decay toward the starting value, to
prevent overfitting to the new dataset during fine-tuning.
The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_.
@kastnerkyle
kastnerkyle / make_audiobook.py
Created April 26, 2020 20:55 — forked from madebyollin/make_audiobook.py
Converts an epub or text file to audiobook via Google Cloud TTS
#!/usr/bin/env python3
"""
To use:
1. install/set-up the google cloud api and dependencies listed on https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/texttospeech/cloud-client
2. install pandoc and pypandoc, also tqdm
3. create and download a service_account.json ("Service account key") from https://console.cloud.google.com/apis/credentials
4. run GOOGLE_APPLICATION_CREDENTIALS=service_account.json python make_audiobook.py book_name.epub
"""
import re
import sys
@kastnerkyle
kastnerkyle / newsci-headlines
Created March 27, 2020 18:09 — forked from gamesbyangelina/newsci-headlines
New Scientist Headlines (Mar 13 - Sept 19)
Some planets may orbit a supermassive black hole instead of a star
This is almost certainly not what Denisovans looked like
UN climate summit: Scientists' messages to world leaders
A hat that zaps the scalp with electricity helps reverse male balding
Man sees the world in miniature after a stroke damages his brain
Do dads matter? Anna Machin on the fascinating science of fatherhood
People like the idea of a carbon tax - if the money is put to good use
Climate change will boost risk of extreme flooding in northern Europe
Fast swimming fish robot could perform underwater surveillance
Ad Astra: Pirates and space monkeys can't save dull space psychodrama
@kastnerkyle
kastnerkyle / Kiritan singing voice synthesis demo.ipynb
Created May 3, 2020 06:09 — forked from r9y9/Kiritan singing voice synthesis demo.ipynb
Neural_network_based_singing_voice_synthesis_demo_using_kiritan_singing_database_(Japanese)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kastnerkyle
kastnerkyle / make_audiobook.py
Created April 26, 2020 20:55 — forked from madebyollin/make_audiobook.py
Converts an epub or text file to audiobook via Google Cloud TTS
#!/usr/bin/env python3
"""
To use:
1. install/set-up the google cloud api and dependencies listed on https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/texttospeech/cloud-client
2. install pandoc and pypandoc, also tqdm
3. create and download a service_account.json ("Service account key") from https://console.cloud.google.com/apis/credentials
4. run GOOGLE_APPLICATION_CREDENTIALS=service_account.json python make_audiobook.py book_name.epub
"""
import re
import sys
@kastnerkyle
kastnerkyle / Instantaneous Frequency and Phase Derivatives.ipynb
Created March 20, 2019 16:13
Instantaneous frequency and rainbowgrams with librosa.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kastnerkyle
kastnerkyle / lm_example.ipynb
Last active September 4, 2019 18:56 — forked from yoavg/lm_example
Unreasonable Effectiveness of LMs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.