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 softmax(x): | |
e_x = np.exp(x - np.max(x, axis=1).reshape(-1, 1)) | |
return e_x / e_x.sum(axis=1).reshape(-1, 1) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys, time | |
import collections | |
import numpy as np | |
class Progbar(object): | |
"""Displays a progress bar. |
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(train_data: np.array, seed: int = 8864): | |
np.random.seed(seed) | |
n = train_data.shape[0] | |
indices = np.random.randint(0, n, n) | |
train_data = [train_data[i] for i in indices] |
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%%% 这是一份 beamer 文档. 本源文件仅供学习参考之用. %%% | |
%%% 使用请注明出处. 本文作者拥有版权 (c)2017. 保留所有权利. %%% | |
%%% 若不能编译通过, 可能是您的 beamer 需要更新了. %%% | |
%%% 更新的具体方法可参考: http://bbs.ctex.org/forums/index.php?showtopic=27695 %%% | |
%%% 温馨提示:文档基本对所都的宏包和命令都加了注释,一般情况下不要删除,会发生错误喔 %%% | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
\documentclass[CJK,notheorems,compress,mathserif,table,11pt]{beamer} %更改全文字体大小,设置xxpt(如9pt,10pt,.....)%一定要定义documentclass[cjk]{beamer},别忘了“cjk”,否则编译不通过 | |
%\useoutertheme[height=0.1\textwidth,width=0.15\textwidth,hideothersubsections]{sidebar}%加上此命令会出现上部和左侧边框 | |
\usetheme{Madrid}%主题AnnArbor Antibes Bergen Berkeley Berlin Boadilla boxes CambridgeUS Copenhagen Darmstadt |
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
# https://github.com/ShahariarRabby/Mnist_cnn_Swish | |
from keras import backend as K | |
from keras.layers import Activationfrom | |
keras.utils.generic_utils import get_custom_objects | |
def swish(x): | |
return (K.sigmoid(x) * x) | |
get_custom_objects().update({'swish': swish}) | |
#Now just add Swish as an activation | |
model.add(Conv2D(filters = 32, kernel_size = (5,5),padding = ‘Same’, |
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
# coding=utf-8 | |
from keras import Input, Model | |
from keras import backend as K | |
from keras.layers import Embedding, Dense, SimpleRNN, Lambda, Concatenate, Conv1D, GlobalMaxPooling1D | |
class RCNN(object): | |
def __init__(self, maxlen, max_features, embedding_dims, | |
class_num=1, |
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
# coding=utf-8 | |
from keras import Input, Model | |
from keras.layers import Embedding, Dense, Concatenate, Conv1D, Bidirectional, CuDNNLSTM, GlobalAveragePooling1D, GlobalMaxPooling1D | |
class RCNNVariant(object): | |
"""Variant of RCNN. | |
Base on structure of RCNN, we do some improvement: | |
1. Ignore the shift for left/right context. |
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
# coding=utf-8 | |
from keras import Input, Model | |
from keras.layers import Embedding, GlobalAveragePooling1D, Dense | |
class FastText(object): | |
def __init__(self, maxlen, max_features, embedding_dims, | |
class_num=1, | |
last_activation='sigmoid'): |
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
# coding=utf-8 | |
from keras import Input, Model | |
from keras.layers import Embedding, Dense, Bidirectional, CuDNNLSTM, TimeDistributed | |
from attention import Attention | |
class HAN(object): | |
def __init__(self, maxlen_sentence, maxlen_word, max_features, embedding_dims, |
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
# coding=utf-8 | |
from keras import Input, Model | |
from keras.layers import Embedding, Dense, Dropout, Bidirectional, CuDNNLSTM | |
from attention import Attention | |
class TextAttBiRNN(object): | |
def __init__(self, maxlen, max_features, embedding_dims, |
NewerOlder