-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathtemplate.libsonnet
141 lines (132 loc) · 3.81 KB
/
template.libsonnet
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
DyGIE: {
local dygie = self,
// Mapping from target task to the metric used to assess performance on that task.
local validation_metrics = {
'ner': '+MEAN__ner_f1',
'relation': '+MEAN__relation_f1',
'coref': '+coref_f1',
'events': '+MEAN__arg_class_f1'
},
////////////////////
// REQUIRED VALUES. Must be set by child class.
// Paths to train, dev, and test data.
data_paths :: error 'Must override `data_paths`',
// Weights on the losses of the model components (e.g. NER, relation, etc).
loss_weights :: error 'Must override `loss_weights`',
// Make early stopping decisions based on performance for this task.
// Options are: `['ner', 'relation', 'coref': 'events']`
target_task :: error 'Must override `target_task`',
// DEFAULT VALUES. May be set by child class..
bert_model :: 'bert-base-cased',
// If using a different BERT, this number may be different. It's up to the user to set the
// appropriate value.
max_wordpieces_per_sentence :: 512,
max_span_width :: 8,
cuda_device :: -1,
////////////////////
// All remaining values can be overridden using the `:+` mechanism
// described in `doc/config.md`
random_seed: 13370,
numpy_seed: 1337,
pytorch_seed: 133,
dataset_reader: {
type: 'dygie',
token_indexers: {
bert: {
type: 'pretrained_transformer_mismatched',
model_name: dygie.bert_model,
max_length: dygie.max_wordpieces_per_sentence
},
},
max_span_width: dygie.max_span_width
},
train_data_path: dygie.data_paths.train,
validation_data_path: dygie.data_paths.validation,
test_data_path: dygie.data_paths.test,
// If provided, use pre-defined vocabulary. Else compute on the fly.
model: {
type: 'dygie',
embedder: {
token_embedders: {
bert: {
type: 'pretrained_transformer_mismatched',
model_name: dygie.bert_model,
max_length: dygie.max_wordpieces_per_sentence
},
},
},
initializer: { // Initializer for shared span representations.
regexes:
[['_span_width_embedding.weight', { type: 'xavier_normal' }]],
},
module_initializer: { // Initializer for component module weights.
regexes:
[
['.*weight', { type: 'xavier_normal' }],
['.*weight_matrix', { type: 'xavier_normal' }],
],
},
loss_weights: dygie.loss_weights,
feature_size: 20,
max_span_width: dygie.max_span_width,
target_task: dygie.target_task,
feedforward_params: {
num_layers: 2,
hidden_dims: 150,
dropout: 0.4,
},
modules: {
coref: {
spans_per_word: 0.3,
max_antecedents: 100,
coref_prop: 0,
},
ner: {},
relation: {
spans_per_word: 0.5,
},
events: {
trigger_spans_per_word: 0.3,
argument_spans_per_word: 0.8,
loss_weights: {
trigger: 0.2,
arguments: 1.0,
},
},
},
},
data_loader: {
sampler: {
type: "random",
}
},
trainer: {
checkpointer: {
num_serialized_models_to_keep: 3,
},
num_epochs: 50,
grad_norm: 5.0,
cuda_device: dygie.cuda_device,
validation_metric: validation_metrics[dygie.target_task],
optimizer: {
type: 'adamw',
lr: 1e-3,
weight_decay: 0.0,
parameter_groups: [
[
['_embedder'],
{
lr: 5e-5,
weight_decay: 0.01,
finetune: true,
},
],
],
},
learning_rate_scheduler: {
type: 'slanted_triangular'
}
},
},
}