Skip to content

Instantly share code, notes, and snippets.

View luoy2's full-sized avatar

YKLuo luoy2

View GitHub Profile
def multilabel_categorical_crossentropy_with_mask(y_true, y_pred):
"""多标签分类的交叉熵
y_true 因为 0., 1. 以及-1.的array, -1. 代表mask
说明:y_true和y_pred的shape一致,y_true的元素非0即1,
1表示对应的类为目标类,0表示对应的类为非目标类。
https://spaces.ac.cn/archives/7359/comment-page-2
"""
y_mask_1 = K.cast(K.greater_equal(y_true, 0.), K.floatx())
y_mask_2 = K.cast(K.less(y_true, 0.), K.floatx()) * (-1e12)
y_true_signed = 1 - 2 * y_true
@luoy2
luoy2 / sqla_regex.py
Created July 5, 2020 08:32 — forked from Xion/sqla_regex.py
Regular expression filters in SQLAlchemy
"""
Module implementing an enhanced string column type for SQLAlchemy
with a support for regular expression operators in Postgres and SQLite.
"""
import re
from sqlalchemy import String as _String, event, exc
from sqlalchemy.engine import Engine
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import BinaryExpression, func, literal
from tqdm import tqdm
tqdm.pandas()
import os
os.environ["TF_KERAS"] = "1"
from sklearn.model_selection import train_test_split
import tensorflow as tf
import tensorflow.keras.backend as K
from tensorflow.keras.layers import *
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.13.0
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] on win32
import pandas as pd
...:
...: from tqdm import tqdm
...: tqdm.pandas()
...: import os
@luoy2
luoy2 / mysqlclient.py
Created May 29, 2019 05:13
pymysql client
import pymysql
pymysql.install_as_MySQLdb()
import logging
from configparser import RawConfigParser
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
SCHEMA_NANE = "tweets"
class mysql_connection(object):