File size: 6,431 Bytes
550665c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
from dataclasses import dataclass, field
from .. import models

@dataclass
class RetroDataModelArguments:
    pass

@dataclass
class DataArguments(RetroDataModelArguments):
    max_seq_length: int = field(
        default=512,
        metadata={
            "help": "The maximum total input sequence length after tokenization. Sequences longer "
            "than this will be truncated, sequences shorter will be padded."
        },
    )
    max_answer_length: int = field(
        default=30,
        metadata={
            "help": "Maximum length of an answer (in tokens) to be generated. This is not "
            "a hard limit but the model's internal length limit."
        },
    )
    doc_stride: int = field(
        default=128,
        metadata={
            "help": "When splitting up a long document into chunks, how much stride to take between chunks."
        },
    )
    return_token_type_ids: bool = field(
        default=True,
        metadata={
            "help": "Whether to return token type ids."
        },
    )
    pad_to_max_length: bool = field(
        default=True,
        metadata={
            "help": "Whether to pad all samples to `max_seq_length`. "
            "If False, will pad the samples dynamically when batching to the maximum length in the batch (which can "
            "be faster on GPU but will be slower on TPU)."
        },
    )
    preprocessing_num_workers: int = field(
        default=5,
        metadata={
            "help": "The number of processes to use for the preprocessing."
        },
    )
    overwrite_cache: bool = field(
        default=False,
        metadata={
            "help": "Overwrite the cached training and evaluation sets"
        },
    )
    version_2_with_negative: bool = field(
        default=True,
        metadata={
            "help": ""
        },
    )
    null_score_diff_threshold: float = field(
        default=0.0,
        metadata={
            "help": "If null_score - best_non_null is greater than the threshold predict null."
        },
    )
    rear_threshold: float = field(
        default=0.0,
        metadata={
            "help": "Rear threshold."
        },
    )
    n_best_size: int = field(
        default=20,
        metadata={
            "help": "The total number of n-best predictions to generate when looking for an answer."
        },
    )
    use_choice_logits: bool = field(
        default=False,
        metadata={
            "help": "Whether to use choice logits."
        },
    )
    start_n_top: int = field(
        default=-1,
        metadata={
            "help": ""
        },
    )
    end_n_top: int = field(
        default=-1,
        metadata={
            "help": ""
        },
    )
    beta1: int = field(
        default=1,
        metadata={
            "help": ""
        },
    )
    beta2: int = field(
        default=1,
        metadata={
            "help": ""
        },
    )
    best_cof: int = field(
        default=1,
        metadata={
            "help": ""
        },
    )
    
@dataclass
class ModelArguments(RetroDataModelArguments):
    use_auth_token: bool = field(
        default=False,
        metadata={
            # "help": "Will use the token generated when running `transformers-cli login` (necessary to use this script "
            # "with private models)."
            "help": ""
        },
    )
    

@dataclass
class SketchModelArguments(ModelArguments):
    sketch_revision: str = field(
        default="main",
        metadata={
            "help": "The revision of the pretrained sketch model."
        },
    )
    sketch_model_name: str = field(
        default="monologg/koelectra-small-v3-discriminator",
        metadata={
            "help": "The name of the pretrained sketch model."
        },
    )
    sketch_model_mode: str = field(
        default="finetune",
        metadata={
            "help": "Choices = ['finetune', 'transfer']"
        },
    )
    sketch_tokenizer_name: str = field(
        default=None,
        metadata={
            "help": "The name of the pretrained sketch tokenizer."
        },
    )
    sketch_architectures: str = field(
        default="ElectraForSequenceClassification",
        metadata={
            "help": ""
        },
    )
    

@dataclass
class IntensiveModelArguments(ModelArguments):
    intensive_revision: str = field(
        default="main",
        metadata={
            "help": "The revision of the pretrained intensive model."
        },
    )
    intensive_model_name: str = field(
        default="monologg/koelectra-base-v3-discriminator",
        metadata={
            "help": "The name of the pretrained intensive model."
        },
    )
    intensive_model_mode: str = field(
        default="finetune",
        metadata={
            "help": "Choices = ['finetune', 'transfer']"
        },
    )
    intensive_tokenizer_name: str = field(
        default=None,
        metadata={
            "help": "The name of the pretrained intensive tokenizer."
        },
    )
    intensive_architectures: str = field(
        default="ElectraForQuestionAnsweringAVPool",
        metadata={
            "help": ""
        },
    )
    
@dataclass
class RetroArguments(DataArguments, SketchModelArguments, IntensiveModelArguments):
    def __post_init__(self):
        # Sketch 
        model_cls = getattr(models, self.sketch_architectures, None)
        if model_cls is None:
            raise ValueError(f"The sketch architecture '{self.sketch_architectures}' is not supported.")
            # raise AttributeError
        self.sketch_model_cls = model_cls
        self.sketch_model_type = model_cls.model_type
        if self.sketch_tokenizer_name is None:
            self.sketch_tokenizer_name = self.sketch_model_name
            
        # Intensive
        model_cls = getattr(models, self.intensive_architectures, None)
        if model_cls is None:
            raise AttributeError
        self.intensive_model_cls = model_cls
        self.intensive_model_type = model_cls.model_type
        
        # Tokenizer
        if self.intensive_tokenizer_name is None:
            self.intensive_tokenizer_name = self.intensive_model_name