Skip to content

Instantly share code, notes, and snippets.

View mmuratarat's full-sized avatar
😃

Mustafa Murat Arat mmuratarat

😃
View GitHub Profile
@mmuratarat
mmuratarat / gist:1b1f879fdf58c976fe0a9d253bd477ba
Last active December 6, 2023 07:01
Turkish official holidays for the years 2020, 2021, 2022, 2023
import datetime
holidays = {datetime.date(2020, 1, 1): 'Yeni Yıl',
datetime.date(2020, 4, 23): "Ulusal Egemenlik ve Çocuk Bayramı",
datetime.date(2020, 5, 1): 'İşçi ve Emekçiler Bayramı',
datetime.date(2020, 5, 19): "Atatürk'ü Anma, Gençlik ve Spor Bayramı",
datetime.date(2020, 5, 23): 'Ramazan Bayramı Arife Günü',
datetime.date(2020, 5, 24): 'Ramazan Bayramı',
datetime.date(2020, 5, 25): 'Ramazan Bayramı ',
datetime.date(2020, 5, 26): 'Ramazan Bayramı ',
import re
def tr_upper(self):
self = re.sub(r"i", "İ", self)
self = re.sub(r"ı", "I", self)
self = re.sub(r"ç", "Ç", self)
self = re.sub(r"ş", "Ş", self)
self = re.sub(r"ü", "Ü", self)
self = re.sub(r"ğ", "Ğ", self)
self = re.sub(r"â", "a", self)
@mmuratarat
mmuratarat / reproducibility.txt
Created October 8, 2023 18:30
reproducibility
def seed_everything(seed: int):
import random, os
import numpy as np
import torch
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
@mmuratarat
mmuratarat / gist:eff84ecb11b32cb9db6d4badf92e7c1b
Last active September 19, 2023 17:19
Expanding contractions
contractions_dict = { "ain’t": "are not", "’s":" is", "aren’t": "are not", "can’t": "cannot", "can’t’ve": "cannot have", "‘cause": "because",
"could’ve": "could have", "couldn’t": "could not", "couldn’t’ve": "could not have", "didn’t": "did not", "doesn’t": "does not",
"don’t": "do not", "hadn’t": "had not", "hadn’t’ve": "had not have", "hasn’t": "has not", "haven’t": "have not", "he’d": "he would",
"he’d’ve": "he would have", "he’ll": "he will", "he’ll’ve": "he will have", "how’d": "how did", "how’d’y": "how do you", "how’ll": "how will",
"I’d": "I would", "I’d’ve": "I would have", "I’ll": "I will", "I’ll’ve": "I will have", "I’m": "I am", "I’ve": "I have", "isn’t": "is not",
"it’d": "it would", "it’d’ve": "it would have", "it’ll": "it will", "it’ll’ve": "it will have", "let’s": "let us", "ma’am": "madam",
"mayn’t": "may not", "might’ve": "might have", "mightn’t": "might not", "m
@mmuratarat
mmuratarat / gist:4e607b1cd08c8a35c06a77c0bfbabb0b
Created September 10, 2023 19:02
Turkish cities in a Python List
# # Turkish Cities
cities = ["Adana","Adiyaman","Afyon","Agri","Aksaray","Amasya","Ankara","Antalya","Ardahan","Artvin","Aydin","Balikesir","Bartin","Batman","Bayburt","Bilecik","Bingol","Bitlis","Bolu","Burdur","Bursa","Canakkale","Cankiri","Corum","Denizli","Diyarbakir","Duzce","Edirne","Elazig","Erzincan","Erzurum","Eskisehir","Gaziantep","Giresun","Gumushane","Hakkari","Hatay","Igdir","Isparta","Istanbul","Izmir","Kahramanmaras","Karabuk","Karaman","Kars","Kastamonu","Kayseri","Kilis","Kirikkale","Kirklareli","Kirsehir","Kocaeli","Konya","Kutahya","Malatya","Manisa","Mardin","Mersin","Mugla","Mus","Nevsehir","Nigde","Ordu","Osmaniye","Rize","Sakarya","Samsun","Sanliurfa","Siirt","Sinop","Sirnak","Sivas","Tekirdag","Tokat","Trabzon","Tunceli","Usak","Van","Yalova","Yozgat","Zonguldak"]
# # Turkish Cities Uppercase
cities_upper = ['ADANA', 'ADIYAMAN', 'AFYON', 'AGRI', 'AKSARAY', 'AMASYA', 'ANKARA', 'ANTALYA', 'ARDAHAN', 'ARTVIN', 'AYDIN', 'BALIKESIR', 'BARTIN', 'BATMAN', 'BAYBURT', 'BILECIK', 'BINGOL', '
import matplotlib.pyplot as plt
import numpy as np
from math import ceil
def multi_convolution2d(input, filter, strides=(1, 1), padding='SAME'):
#This is for multiple filter
if not len(filter.shape) == 4:
raise ValueError("The size of filter should be (filter_height, filter_width, filter_depth, number_of_filters)")
if not len(input.shape) == 3:
## MULTICLASS CROSS ENTROPY
import tensorflow as tf
import numpy as np
from sklearn.metrics import log_loss
#4 observations and 4 classes
y_true = [4,4,3,1] #Hard classes
y_true_onehot = [[0,0,0,1], [0,0,0,1], [0,0,1,0], [1,0,0,0]] #one_hot encoding
y_pred = [[0.2, 0.2, 0.2, 0.2], [0.6, 0.7, 0.1, 0.2], [0.3, 0.9, 0.1, 0.1], [0.1, 0.5, 0.7, 0.4]]
y_pred_softmax = [[0.25, 0.25, 0.25, 0.25], [0.29568115, 0.3267782, 0.17933969, 0.198201], [0.22423635, 0.40858525, 0.18358919, 0.18358919], [0.17655984, 0.26339632, 0.32171297, 0.23833084]]
import numpy as np
import tensorflow as tf
from sklearn.datasets import fetch_california_housing
from sklearn.preprocessing import StandardScaler
import math
housing = fetch_california_housing()
print(type(housing['data']))
print(type(housing['target']))
## BINARY CLASS CROSS ENTROPY
import tensorflow as tf
import numpy as np
from sklearn.metrics import log_loss
#4 observations and 2 classes
y_true = [0,0,0,1] #Hard classes
y_pred = [0.2, 0.2, 0.2, 0.2]
y_pred_softmax = [0.54983395, 0.54983395, 0.54983395, 0.54983395] #soft predictions
#BY HAND
file_name multi_hot_encoding Labels Categories
----------------------------------------------------------------------------------------------------
0.png [1, 0, 0, 0, 0] [1] [Desert]
10.png [1, 1, 0, 0, 1] [1, 2] [Desert, Mountains]
47.png [1, 0, 0, 1, 1] [1, 4, 5] [Desert, Sunset, Trees]