Ejemplo n.º 1
0
            h_train.shape, h_val.shape, h_test.shape, 
            y_train.shape, y_val.shape, y_test.shape)


if USE_HOLIDAY == 'no_use':
    X_train[:, :, [1]] = 0
    # X_val[:, :, [1]] = 0
    X_test[:, :, [1]] = 0

    model = RNNModel(
        lookback=LOOKBACK, lookahead=LOOKAHEAD, input_dim=2, hid_dim=40, 
        device='cuda', data_dir=DATA_DIR, task=USE_HOLIDAY
    )
    model.fit(
        X_train=X_train, y_train=y_train, 
        X_val=X_test, y_val=y_test, 
        metric='mae', max_epoch=MAX_EPOCH, patience=3000000, 
        batch_size=128, lr=1e-3, weight_decay=1e-3
    )
    forecast = model.eval(X_test=X_test)


elif USE_HOLIDAY == 'feature':
    model = RNNModel(
        lookback=LOOKBACK, lookahead=LOOKAHEAD, input_dim=2, hid_dim=40, 
        device='cuda', data_dir=DATA_DIR, task=USE_HOLIDAY
    )
    model.fit(
        X_train=X_train, y_train=y_train, 
        X_val=X_test, y_val=y_test, 
        metric='mae', max_epoch=MAX_EPOCH, patience=3000000, 
        batch_size=128, lr=1e-3, weight_decay=1e-3
Ejemplo n.º 2
0
filepath = "_{}_{}_{}_{}_{}_{}_".format(
    'LSTM' if RNN_TYPE == LSTM else 'GRU',
    'X'.join(str(x) for x in LAYERS_SIZE), 'ATT' if ATTENTION else 'NO_ATT',
    'DROPOUT_' + 'X'.join(str(x) for x in SPATIAL_DROPOUT),
    str(DENSE) if DENSE != 0 else 'NO_DENSE',
    str() if DROPOUT_DENSE else '')
filepath = "/data/spc_{epoch:02d}_F1_{f1_micro_score:.4f}_catAcc_{val_categorical_accuracy:.4f}_trainable" + filepath + ".hdf5"

# model.model().predict((([np.array(X_val), np.array(X_val_text)], np.array(Y_val))[0]), batch_size=BATCH_SIZE)

model.fit(x=[np.array(X), np.array(X_text)],
          y=np.array(Y),
          validation_data=val_data,
          batch_size=BATCH_SIZE,
          epochs=EPOCHS,
          callbacks=[
              MicroF1ModelCheckpoint(filepath=filepath,
                                     verbose=1,
                                     monitor='categorical_accuracy',
                                     save_weights_only=True,
                                     mode='auto')
          ])

predictions = []
# predictions = model.model().predict(np.array([np.array(X_val), np.array(X_val_text)]), batch_size=BATCH_SIZE)
predictions = predictions.argmax(axis=1)
label2emotion = {0: "others", 1: "happy", 2: "sad", 3: "angry"}
with open('/data/result/test.txt', "w", encoding="utf8") as fout:
    fout.write('\t'.join(["id", "turn1", "turn2", "turn3", "label"]) + '\n')
    with open(env.DEV_FILE_PATH, encoding="utf8") as fin:
        fin.readline()
        for lineNum, line in enumerate(fin):