Skip to content

Instantly share code, notes, and snippets.

View enamoria's full-sized avatar
💭
vohox

Kính Phan enamoria

💭
vohox
  • Viet Nam
View GitHub Profile
@enamoria
enamoria / unicode_to_ascii.py
Last active December 16, 2018 10:39
Convert unicode character to the nearest (removed tone, accent, ... that feature a specific language) ASCII character. For ex: "Тгцмр" will be converted to "Tgtsmr", not Trump
# Source: https://stackoverflow.com/a/518232/4102479
# This is better approach, compared to unidecode, though unidecode provide acceptable result in almost every cases
import unicodedata
import string
all_letters = string.ascii_letters + " .,;'"
nb_letter = len(all_letters)
print(all_letters, len(all_letters))
"""
A weighted version of categorical_crossentropy for keras (2.0.6). This lets you apply a weight to unbalanced classes.
@url: https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d
@author: wassname
"""
from keras import backend as K
def weighted_categorical_crossentropy(weights):
"""
A weighted version of keras.objectives.categorical_crossentropy