Skip to content

Instantly share code, notes, and snippets.

View noahtren's full-sized avatar

Noah Trenaman noahtren

  • Cincinnati, Ohio
View GitHub Profile
import matplotlib.pyplot as plt
import numpy as np
def normalize_freq_coeff(coeff):
freqs = np.fft.fftfreq(coeff.shape[-1], d=1 / coeff.shape[-1])
scale = (1 / (np.abs(freqs) + 1))
return coeff * scale
@noahtren
noahtren / huggingface_to_tftext.py
Last active March 23, 2023 13:13
HuggingFace Tokenizer -> TF.Text
import tensorflow as tf
import tensorflow_text as text
from transformers import AutoTokenizer
def get_tf_tokenizer(hf_model_name, do_test=False):
hf_tokenizer = AutoTokenizer.from_pretrained(hf_model_name)
model_proto = hf_tokenizer.sp_model.serialized_model_proto()
tf_tokenizer = text.SentencepieceTokenizer(model=model_proto, out_type=tf.int32)
if do_test:
test_string = "This is a testtt, hah! reaaly cool :)"
@noahtren
noahtren / Colab-S3.md
Last active June 27, 2020 00:27
Run code hosted on S3 in a Colab Notebook

Colab + S3 For Syncing Local Code

Scripts to add to your Colab Notebook to sync with an S3 bucket that contains code to run.


  1. Write AWS credentials to disk in order to use s3fs
%%writefile ~/.passwd-s3fs
:
@noahtren
noahtren / experimental_aug.py
Last active June 4, 2020 19:17
TPU-Compatible Differentiable Affine Transformations
"""Originally from https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96#Data-Augmentation,
modified to be in pure TensorFlow and to work on a batch of images rather than a single image.
(For a tf.data pipeline, you may want to look at the original code at the link above.)
"""
import math
import tensorflow as tf
def transform_batch(images,
@noahtren
noahtren / client.py
Created April 17, 2020 22:08
FoodData Central Python API Client
"""Client class to interface with FoodData Central.
FoodData Central requires a Data.gov key: https://api.data.gov/signup/
"""
from enum import Enum
import json
import requests
BASE_URL = 'https://api.nal.usda.gov/fdc/v1'
@noahtren
noahtren / residual_convnet_keras.py
Created July 29, 2019 15:01
Small convolutional neural network with residual connections implemented with Keras
"""Small convnet with residual connections.
inspired by https://gist.github.com/mjdietzx/0cb95922aac14d446a6530f87b3a04ce,
which builds a full ResNet-50 or ResNeXt-50 model
"""
NUM_CLASSES = 2
from keras.layers import BatchNormalization, Conv2D, LeakyReLU, Input, MaxPool2D, Dense, Flatten, Dropout
from keras.models import Model
def add_common_layers(y):