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
# insted of this | |
$Button.connect("pressed", self, "_on_button_pressed") | |
# you do this | |
$Button.pressed.connect(self._on_button_pressed) |
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 shuffle(data): | |
data = data.iloc[np.random.permutation(len(data))] | |
data = data.reset_index(drop=True) | |
return data |
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
# turnung categorical values to numerical once | |
def name2num(name): | |
return [all_letters.index(l) for l in name] | |
def num2name(num): | |
return [all_letters[n] for n in num] | |
def category2num(c): | |
return all_categories.index(c) | |
def num2category(num): | |
return all_categories[num] |
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
# transform data from dict to dataframe | |
import pandas as pd | |
from tqdm import tqdm | |
data = pd.DataFrame(columns=['category', 'name']) | |
for category in tqdm(all_categories): | |
names = category_lines[category] | |
for name in names: | |
frame = {'category':category, 'name':name} |
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
# Load data from files to dict | |
import os | |
import glob | |
import string | |
import unicodedata | |
all_letters = string.ascii_letters + " .,;'-" | |
category_lines = {} | |
all_categories = [] |
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
# Unpuck zip file | |
from zipfile import ZipFile | |
with ZipFile(data_fn, 'r') as zip_obj: | |
zip_obj.extractall() |
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
# loading data from the web | |
import requests | |
data_fn = 'data.zip' | |
data_url = 'https://download.pytorch.org/tutorial/data.zip' | |
f = requests.get(data_url).content | |
open(data_fn, 'wb').write(f) |