This file contains 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
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
from __future__ import unicode_literals | |
# author: Kyle Kastner | |
# References: | |
# needleman wunsch (could use other alignment algorithms instead) | |
# https://colab.research.google.com/github/zaneveld/full_spectrum_bioinformatics/blob/master/content/08_phylogenetic_trees/needleman_wunsch_alignment.ipynb |
This file contains 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
#!/usr/bin/env python | |
import math | |
import matplotlib.pyplot as plt | |
import torch | |
import torch.nn as nn | |
from sklearn.datasets import make_moons | |
from torch import Tensor | |
from tqdm import tqdm |
This file contains 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 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). |
This file contains 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
# Author: Kyle Kastner | |
# BSD 3-Clause | |
# Thanks to jakevdp for the nice blog post on FFT | |
# https://jakevdp.github.io/blog/2013/08/28/understanding-the-fft/ | |
# Summary | |
# http://www.arazim-project.com/sites/default/files/public/lesson_sums/1fft.pdf | |
# Details on hartley and many xforms | |
# https://caxapa.ru/thumbs/455725/algorithms.pdf | |
# pg 332 http://sep.stanford.edu/data/media/public/oldreports/sep38/38_29.pdf |
This file contains 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 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) |
This file contains 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 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`_. |
This file contains 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
def typical_top_k_filtering(logits, top_k=0, top_p=0.0, temperature=1.0, min_tokens_to_keep=1, filter_value=-1E12): | |
""" Filter a distribution of logits using typicality, with optional top-k and/or nucleus (top-p) filtering | |
Meister et. al. https://arxiv.org/abs/2202.00666 | |
Args: | |
logits: logits distribution shape (..., vocabulary size) | |
top_k >0: keep top k tokens with highest prob (top-k filtering). | |
top_p >0.0: keep the top p tokens which compose cumulative probability mass top_p (nucleus filtering). | |
min_tokens_to_keep >=1: always keep at least this many tokens through the top_p / nucleus sampling | |
""" | |
# https://arxiv.org/abs/2202.00666 |
This file contains 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
{ | |
"seconds_per_quarter": 0.5, | |
"parts_names": [ | |
"Soprano", | |
"Alto", | |
"Tenor", | |
"Bass" | |
], | |
"parts_cumulative_times": [ | |
[ |
This file contains 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 numpy as np | |
# make a minibatch of time, batch, features | |
# time length 7 | |
# batch size 2 | |
# feature dimension 4: | |
# 1:4, 10:14, 20:24, 30:34, etc for first minibatch element | |
# 5:8, 15:18, etc second minibatch el | |
n_features = 4 | |
n_timesteps = 7 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder