-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.py
More file actions
73 lines (57 loc) · 1.78 KB
/
Copy pathconfig.py
File metadata and controls
73 lines (57 loc) · 1.78 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# coding:utf-8
import sys
from pathlib import Path
PROJECT_PATH = Path(__file__).absolute().parent
sys.path.insert(0, str(PROJECT_PATH))
from utils.log import log_info as _info
from utils.log import log_error as _error
RNN_ENCODER_TYPE_UNI = 'uni'
RNN_ENCODER_TYPE_BI = 'bi'
RNN_UNIT_TYPE_LSTM = 'lstm'
RNN_UNIT_TYPE_GRU = 'gru'
RNN_UNIT_TYPE_LAYER_NORM_LSTM = 'layer_norm_lstm'
SOS_ID = 1
EOS_ID = 2
PADDING_ID = 3
BATCH_SIZE = 32
TRIAN_STEPS = 100000
QUE_PATH = PROJECT_PATH / 'data/question.data'
ANS_PATH = PROJECT_PATH / 'data/answer.data'
DATA_PATH = PROJECT_PATH / 'data/all.data'
DIST_PATH = PROJECT_PATH / 'data/vocab_idx.bin'
def forbid_new_attributes(wrapped_setatrr):
def __setattr__(self, name, value):
if hasattr(self, name):
wrapped_setatrr(self, name, value)
else:
_error('Add new {} is forbidden'.format(name))
raise AttributeError
return __setattr__
class NoNewAttrs(object):
"""forbid to add new attributes"""
__setattr__ = forbid_new_attributes(object.__setattr__)
class __metaclass__(type):
__setattr__ = forbid_new_attributes(type.__setattr__)
class NmtConfig(NoNewAttrs):
# Encoder
vocab_size = 10509
embedding_size = 160
num_layers = 2
hidden_size = 320
forget_bias = 1.0
dropout = 0.2
residual_or_not = True
kernel_size = [1, 2, 3]
pool_size = [640, 639, 637]
# Decoder
tgt_vocab_size = 10509
max_len_infer = 50
encoder_type = RNN_ENCODER_TYPE_BI
unit_type = RNN_UNIT_TYPE_GRU
# global
model_dir = 'models/'
initializer_range = 0.02
learning_rate = 1e-4
lr_limit = 1e-4
colocate_gradients_with_ops = True
nmt_config = NmtConfig()