示例#1
0
def make_data_set():
    ds = Dataset()
    print("Datasets loaded.")
    X_all = pad_vec_sequences(ds.X_all_vec_seq)
    Y_all = ds.Y_all
    #print (X_all.shape)
    x_train, x_test, y_train, y_test = model_selection.train_test_split(X_all,Y_all,test_size=0.2)
    y_train = pad_class_sequence(y_train, nb_classes)
    y_test = pad_class_sequence(y_test, nb_classes)
    y_test = np.array(y_test)
    x_train = np.asarray(x_train)
    x_train.ravel()
    
    y_train = np.asarray(y_train)
    y_train.ravel()
    return x_train,y_train,x_test,y_test
示例#2
0
from keras.utils import np_utils, generic_utils
from keras import optimizers, metrics

maxlen = 50  #sentences with length > maxlen will be ignored
hidden_dim = 32
nb_classes = len(labels)

ds = Dataset()
print("Datasets loaded.")

X_all = pad_vec_sequences(ds.X_all_vec_seq)
Y_all = ds.Y_all
#print (X_all.shape)
x_train, x_test, y_train, y_test = model_selection.train_test_split(
    X_all, Y_all, test_size=0.2)
y_train = pad_class_sequence(y_train, nb_classes)
y_test = pad_class_sequence(y_test, nb_classes)

#THE MODEL
sequence = Input(shape=(maxlen, 384), dtype='float32', name='input')
#forwards lstm
forwards = LSTM(hidden_dim,
                activation='tanh',
                recurrent_activation='hard_sigmoid',
                use_bias=True,
                dropout=0.1,
                recurrent_dropout=0.1)(sequence)
#backwards lstm
backwards = LSTM(hidden_dim,
                 activation='tanh',
                 recurrent_activation='hard_sigmoid',