forked from tensorflow/models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configs_test.py
120 lines (103 loc) · 3.12 KB
/
configs_test.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for configs."""
import tensorflow as tf
from official.nlp.nhnet import configs
BERT2BERT_CONFIG = {
"vocab_size": 30522,
"hidden_size": 768,
"num_hidden_layers": 12,
"num_attention_heads": 12,
"intermediate_size": 3072,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"attention_probs_dropout_prob": 0.1,
"max_position_embeddings": 512,
"type_vocab_size": 2,
"initializer_range": 0.02,
# model params
"decoder_intermediate_size": 3072,
"num_decoder_attn_heads": 12,
"num_decoder_layers": 12,
# training params
"label_smoothing": 0.1,
"learning_rate": 0.05,
"learning_rate_warmup_steps": 20000,
"optimizer": "Adam",
"adam_beta1": 0.9,
"adam_beta2": 0.997,
"adam_epsilon": 1e-09,
# predict params
"beam_size": 5,
"alpha": 0.6,
"initializer_gain": 1.0,
"use_cache": True,
# input params
"input_sharding": False,
"input_data_not_padded": False,
"pad_token_id": 0,
"end_token_id": 102,
"start_token_id": 101,
}
NHNET_CONFIG = {
"vocab_size": 30522,
"hidden_size": 768,
"num_hidden_layers": 12,
"num_attention_heads": 12,
"intermediate_size": 3072,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"attention_probs_dropout_prob": 0.1,
"max_position_embeddings": 512,
"type_vocab_size": 2,
"initializer_range": 0.02,
# model params
"decoder_intermediate_size": 3072,
"num_decoder_attn_heads": 12,
"num_decoder_layers": 12,
"multi_channel_cross_attention": True,
# training params
"label_smoothing": 0.1,
"learning_rate": 0.05,
"learning_rate_warmup_steps": 20000,
"optimizer": "Adam",
"adam_beta1": 0.9,
"adam_beta2": 0.997,
"adam_epsilon": 1e-09,
# predict params
"beam_size": 5,
"alpha": 0.6,
"initializer_gain": 1.0,
"use_cache": True,
# input params
"passage_list": ["b", "c", "d", "e", "f"],
"input_sharding": False,
"input_data_not_padded": False,
"pad_token_id": 0,
"end_token_id": 102,
"start_token_id": 101,
"init_from_bert2bert": True,
}
class ConfigsTest(tf.test.TestCase):
def test_configs(self):
cfg = configs.BERT2BERTConfig()
cfg.validate()
self.assertEqual(cfg.as_dict(), BERT2BERT_CONFIG)
def test_nhnet_config(self):
cfg = configs.NHNetConfig()
cfg.validate()
self.assertEqual(cfg.as_dict(), NHNET_CONFIG)
if __name__ == "__main__":
tf.test.main()