-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
49 lines (39 loc) · 991 Bytes
/
train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 25 17:54:10 2021
@author: James
"""
import torch
import torch.nn as nn
import pandas as pd
from utils import subsequent_mask
from model import Transformer
data_pkl=
train_path=
val_path=
opt={
'-epoch':10,
'-b':2048,
'd_model':512,
'd_ff':2048,
'heads':8,
'n_layers':6,
'n_warmup_steps':4000,
'lr_mul':2,
'seed':10,
'dropout_prob':0.1,
'no_cuda':False,
'label_smoothing':True
}
opt['cuda'] = not opt['no_cuda']
opt['d_word_vec'] = opt['d_model']
# https://pytorch.org/docs/stable/notes/randomness.html
# For reproducibility
if opt['seed'] is not None:
torch.manual_seed(opt['seed'])
torch.backends.cudnn.benchmark = False
# torch.set_deterministic(True)
np.random.seed(opt['seed'])
random.seed(opt['seed'])
transformer=Transformer(d_model,d_ff,heads,n_vocab,max_len,bias,is_gated,
bias_gate,activation,dropout_prob,n_layers)