def objective(trial): nl = trial.suggest_int("num_layers", 1, 2) bi = trial.suggest_categorical("bidirectional", [False, True]) model = RNN(d_w, d_h, L, emb, num_layers=nl, bidirectional=bi) lr = trial.suggest_loguniform("learning_rate", 1e-5, 1e-1) bs = trial.suggest_categorical("batch_size", [32, -1]) model = run_train(train, valid, model, epochs=11, lr=lr, batch_size=bs, device=device) loss_eval, acc_eval = run_eval(model, valid, device=device) return acc_eval
from knock82 import run_eval, run_train sys.path.append(os.path.join(os.path.dirname(__file__), "../../")) from kiyuna.utils.pickle import load # noqa: E402 isort:skip logging.basicConfig(level=logging.DEBUG) d_w = 300 d_h = 50 V = get_V() L = 4 if __name__ == "__main__": train = torch.load("./data/train.pt") valid = torch.load("./data/valid.pt") test = torch.load("./data/test.pt") device = torch.device("cuda:6") emb = torch.Tensor(d_w, V).normal_() wv = load("chap07-embeddings") for i, word in enumerate(_list_valid_words()): if word in wv: wv_word = wv[word] wv_word.flags["WRITEABLE"] = True emb[:, i] = torch.from_numpy(wv_word) rnn = RNN(d_w, d_h, L, emb, num_layers=2, bidirectional=True) rnn = run_train(train, valid, rnn, epochs=11, lr=1e-1, batch_size=32, device=device) loss, acc = run_eval(rnn, test, device=device) print(f"Accuracy (test): {acc:f}, Loss (test): {loss:f}")