Skip to content

Instantly share code, notes, and snippets.

View IlievskiV's full-sized avatar
🐻‍❄️

Vladimir Ilievski IlievskiV

🐻‍❄️
View GitHub Profile
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():
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)
import hiplot as hip
hip.Experiment.from_iterable(hiplt_data).display()
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,
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]
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,
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)
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
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
@IlievskiV
IlievskiV / pretrained_bert.py
Created January 15, 2021 09:33
How to use a pre-trained BERT
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