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
.var : New variable | |
ANY → $var$ = $expr$ | |
.str : Cast to string | |
ANY → str($expr$) | |
.fstr : Apply f-string formatting | |
ANY → f"{$expr$}" | |
.list : Cast to list |
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 string import ascii_lowercase | |
import argparse | |
def letter_frequency_builder(words_list): | |
corpus_length = len(words_list) | |
return {letter: sum(letter in word for word in words_list)/corpus_length for letter in ascii_lowercase} | |
def word_score(word, letter_frequency): |
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Fri Oct 23 17:34:25 2020 | |
@author: hemerson.tacon | |
""" | |
import re |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Mar 9 22:51:09 2020 | |
Given n non-negative integers representing an elevation map where the width | |
of each bar is 1, compute how much water it is able to trap after raining. | |
@author: Hemerson Tacon | |
""" | |
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 os | |
import matplotlib.pyplot as plt | |
def plot_and_save(history, name, show_plots=False, folder="imgs"): | |
""" | |
Create a charts comparing accuracy and loss of training and validation | |
phases for each epoch | |
Args: | |
history (Hisotry): The History object returned from a fit function |
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 keras.regularizers import l1_l2 | |
def set_kernel_reg(model, lambdal1 = 0, lambdal2 = 0): | |
""" | |
Apply kernel regularization to keras model | |
Args: | |
model: Instance of `Model` not compiled yet | |
lambda1 (float): L1 regularization factor | |
lambda2 (float): L2 regularization factor |