🐻❄️
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 matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
def make_animation(sierpinski_triangle: list): | |
num_points = len(sierpinski_triangle) | |
points_split = list(zip(*sierpinski_triangle)) | |
xx, yy = points_split[0], points_split[1] | |
fig = plt.figure(figsize=(10, 10)) | |
def init(): |
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 random | |
from operator import add | |
def generate_sierpinski_triangle(n: int): | |
sierpinski_triangle = [] # final list of points | |
# initial points | |
A = (0.0, 0.0) | |
B = (0.5, 1.0) | |
C = (1.0, 0.0) |
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 hiplot as hip | |
hip.Experiment.from_iterable(hiplt_data).display() |
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 itertools | |
epochs = 3 # number of training epochs | |
test_batch_size = 32 # batch size for testing | |
arrays = [ | |
embedding_size, | |
dropout, | |
filters, | |
kernel_size, | |
pool_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
from keras.metrics import BinaryAccuracy, Precision, Recall | |
METRICS = [ | |
BinaryAccuracy(name='accuracy'), | |
Precision(name='precision'), | |
Recall(name='recall'), | |
] # metrics to track | |
# hyperparameters to track | |
embedding_size = [32, 128] |
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
from keras.models import Sequential | |
from keras.layers import Activation, Bidirectional, Conv1D, Dense | |
from keras.layers import Dropout, Embedding, LSTM, MaxPooling1D | |
def make_model( | |
embedding_dim: int, | |
dropout: float, | |
filters: int, | |
kernel_size: int, |
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
from keras.datasets import imdb | |
from keras.preprocessing import sequence | |
max_features = 20000 # vocabulary size | |
maxlen = 100 # max length of every input sequence | |
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features) | |
x_train, y_train = x_train[:2500], y_train[:2500] | |
x_test, y_test = x_test[:1000], y_test[:1000] | |
x_train = sequence.pad_sequences(x_train, maxlen=maxlen) |
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 | |
def cellular_automaton(rule_number, size, steps, | |
init_cond='random', impulse_pos='center'): | |
"""Generate the state of an elementary cellular automaton after a pre-determined | |
number of steps starting from some random state. | |
Args: | |
rule_number (int): the number of the update rule to use | |
size (int): number of cells in the row |
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 | |
powers_of_two = np.array([[4], [2], [1]]) # shape (3, 1) | |
def step(x, rule_binary): | |
"""Makes one step in the cellular automaton. | |
Args: | |
x (np.array): current state of the automaton | |
rule_binary (np.array): the update rule |
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
from transformers import BertTokenizer, BertModel | |
import torch | |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') | |
model = BertModel.from_pretrained('bert-base-uncased') | |
inputs = tokenizer("[CLS] This is very awesome!", return_tensors="pt") | |
outputs = model(**inputs) | |
# the learned representation for the [CLS] token |
NewerOlder