Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c06b02

Browse files
authored
update yapf (PaddlePaddle#2464)
1 parent 837d06a commit 7c06b02

1,100 files changed

Lines changed: 36325 additions & 33561 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

โ€Ž.pre-commit-config.yamlโ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
repos:
2-
- repo: https://github.com/PaddlePaddle/mirrors-yapf.git
3-
sha: 0d79c0c469bab64f7229c9aca2b1186ef47f0e37
2+
- repo: https://github.com/google/yapf
3+
rev: v0.32.0
44
hooks:
55
- id: yapf
66
files: \.py$
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
sha: a11d9314b22d8f8c7556443875b731ef05965464
8+
rev: v4.1.0
99
hooks:
1010
- id: check-merge-conflict
1111
- id: check-symlinks
@@ -16,7 +16,7 @@ repos:
1616
- id: trailing-whitespace
1717
files: \.md$
1818
- repo: https://github.com/Lucas-C/pre-commit-hooks
19-
sha: v1.0.1
19+
rev: v1.1.14
2020
hooks:
2121
- id: forbid-crlf
2222
files: \.md$

โ€ŽREADME_cn.mdโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ PaddleNLPๆไพ›[ไธ€้”ฎ้ข„ๆต‹ๅŠŸ่ƒฝ](./docs/model_zoo/taskflow.md)๏ผŒๆ— ้œ€่ฎญ็ปƒ
294294
PaddleNLPๆไพ›ๅ…จๆต็จ‹็š„ๆ–‡ๆœฌ้ข†ๅŸŸAPI๏ผŒๅฏๅคงๅน…ๆๅ‡NLPไปปๅŠกๅปบๆจก็š„ๆ•ˆ็އ๏ผš
295295

296296
- ๆ”ฏๆŒ[ๅƒ่จ€](https://www.luge.ai)็ญ‰ไธฐๅฏŒไธญๆ–‡ๆ•ฐๆฎ้›†ๅŠ ่ฝฝ็š„[Dataset API](https://paddlenlp.readthedocs.io/zh/latest/data_prepare/dataset_list.html)ใ€‚
297-
- ๆไพ›๐Ÿค—Hugging Face Style็š„API๏ผŒๆ”ฏๆŒ **500+** ไผ˜่ดจ้ข„่ฎญ็ปƒๆจกๅž‹ๅŠ ่ฝฝ็š„[Transformers API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/index.html)ใ€‚
297+
- ๆไพ›๐Ÿค—Hugging Face Style็š„API๏ผŒๆ”ฏๆŒ **500+** ไผ˜่ดจ้ข„่ฎญ็ปƒๆจกๅž‹ๅŠ ่ฝฝ็š„[Transformers API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/index.html)ใ€‚
298298
- ๆไพ›30+ๅคš่ฏญ่จ€่ฏๅ‘้‡็š„[Embedding API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/embeddings.html)
299299

300300
ๆ›ดๅคšไฝฟ็”จๆ–นๆณ•่ฏทๅ‚่€ƒ[APIๆ–‡ๆกฃ](https://paddlenlp.readthedocs.io/zh/latest/)ใ€‚

โ€ŽREADME_en.mdโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ For more usage please refer to [Taskflow Docs](./docs/model_zoo/taskflow.md).
5757

5858
### Awesome Chinese Model Zoo
5959

60-
#### ๐Ÿ€„ Comprehensive Chinese Transformer Models
60+
#### ๐Ÿ€„ Comprehensive Chinese Transformer Models
6161

6262
We provide **45+** network architectures and over **500+** pretrained models. Not only includes all the SOTA model like ERNIE, PLATO and SKEP released by Baidu, but also integrates most of the high-quality Chinese pretrained model developed by other organizations. Use `AutoModel` API to **โšกSUPER FASTโšก** download pretrained mdoels of different architecture. We welcome all developers to contribute your Transformer models to PaddleNLP!
6363

โ€Žapplications/doc_vqa/Extraction/docvqa.pyโ€Ž

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
class DocVQAExample(object):
17+
1718
def __init__(self,
1819
question,
1920
doc_tokens,
@@ -48,6 +49,7 @@ def __init__(self,
4849

4950

5051
class DocVQA(Dataset):
52+
5153
def __init__(self,
5254
args,
5355
tokenizer,
@@ -264,7 +266,8 @@ def convert_examples_to_features(self, examples, tokenizer, label_map,
264266
input_mask=spans_input_mask,
265267
segment_ids=spans_segment_ids,
266268
boxes=spans_boxes_tokens,
267-
label=label_ids, )
269+
label=label_ids,
270+
)
268271
features.append(feature)
269272
return features
270273

@@ -292,8 +295,9 @@ def create_examples(self, data, is_test=False):
292295
scale_y = 1000 / max(width, height)
293296

294297
scaled_doc_boxes = [[
295-
round((b[0] - x_min) * scale_x), round(
296-
(b[2] - y_min) * scale_y), round((b[1] - x_min) * scale_x),
298+
round((b[0] - x_min) * scale_x),
299+
round((b[2] - y_min) * scale_y),
300+
round((b[1] - x_min) * scale_x),
297301
round((b[3] - y_min) * scale_y)
298302
] for b in doc_boxes]
299303

@@ -308,11 +312,10 @@ def create_examples(self, data, is_test=False):
308312
if pos > 1000:
309313
print(width, height, box, oribox)
310314

311-
example = DocVQAExample(
312-
question=question,
313-
doc_tokens=doc_tokens,
314-
doc_boxes=scaled_doc_boxes,
315-
labels=labels)
315+
example = DocVQAExample(question=question,
316+
doc_tokens=doc_tokens,
317+
doc_boxes=scaled_doc_boxes,
318+
labels=labels)
316319
examples.append(example)
317320
return examples
318321

@@ -338,19 +341,21 @@ def docvqa_input(self):
338341
max_span_num=self.max_span_num,
339342
max_query_length=self.max_query_length)
340343

341-
all_input_ids = paddle.to_tensor(
342-
[f.input_ids for f in features], dtype="int64")
343-
all_input_mask = paddle.to_tensor(
344-
[f.input_mask for f in features], dtype="int64")
345-
all_segment_ids = paddle.to_tensor(
346-
[f.segment_ids for f in features], dtype="int64")
347-
all_bboxes = paddle.to_tensor(
348-
[f.boxes for f in features], dtype="int64")
349-
all_labels = paddle.to_tensor(
350-
[f.label for f in features], dtype="int64")
344+
all_input_ids = paddle.to_tensor([f.input_ids for f in features],
345+
dtype="int64")
346+
all_input_mask = paddle.to_tensor([f.input_mask for f in features],
347+
dtype="int64")
348+
all_segment_ids = paddle.to_tensor([f.segment_ids for f in features],
349+
dtype="int64")
350+
all_bboxes = paddle.to_tensor([f.boxes for f in features],
351+
dtype="int64")
352+
all_labels = paddle.to_tensor([f.label for f in features],
353+
dtype="int64")
351354
self.sample_list = [
352-
np.array(all_input_ids), np.array(all_input_mask),
353-
np.array(all_segment_ids), np.array(all_bboxes),
355+
np.array(all_input_ids),
356+
np.array(all_input_mask),
357+
np.array(all_segment_ids),
358+
np.array(all_bboxes),
354359
np.array(all_labels)
355360
]
356361

โ€Žapplications/doc_vqa/Extraction/model.pyโ€Ž

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
class Crf_decoding(paddle.fluid.dygraph.Layer):
10+
1011
def __init__(self, param_attr, size=None, is_test=True, dtype='float32'):
1112
super(Crf_decoding, self).__init__()
1213

@@ -38,16 +39,20 @@ def forward(self, input, label=None, length=None):
3839
}
3940
if length is not None:
4041
this_inputs['Length'] = [length]
41-
self._helper.append_op(
42-
type='crf_decoding',
43-
inputs=this_inputs,
44-
outputs={"ViterbiPath": [viterbi_path]},
45-
attrs={"is_test": self._is_test, })
42+
self._helper.append_op(type='crf_decoding',
43+
inputs=this_inputs,
44+
outputs={"ViterbiPath": [viterbi_path]},
45+
attrs={
46+
"is_test": self._is_test,
47+
})
4648
return viterbi_path
4749

4850

4951
class Chunk_eval(paddle.fluid.dygraph.Layer):
50-
def __init__(self, num_chunk_types, chunk_scheme,
52+
53+
def __init__(self,
54+
num_chunk_types,
55+
chunk_scheme,
5156
excluded_chunk_types=None):
5257
super(Chunk_eval, self).__init__()
5358
self.num_chunk_types = num_chunk_types
@@ -73,27 +78,30 @@ def forward(self, input, label, seq_length=None):
7378
if seq_length is not None:
7479
this_input["SeqLength"] = [seq_length]
7580

76-
self._helper.append_op(
77-
type='chunk_eval',
78-
inputs=this_input,
79-
outputs={
80-
"Precision": [precision],
81-
"Recall": [recall],
82-
"F1-Score": [f1_score],
83-
"NumInferChunks": [num_infer_chunks],
84-
"NumLabelChunks": [num_label_chunks],
85-
"NumCorrectChunks": [num_correct_chunks]
86-
},
87-
attrs={
88-
"num_chunk_types": self.num_chunk_types,
89-
"chunk_scheme": self.chunk_scheme,
90-
"excluded_chunk_types": self.excluded_chunk_types or []
91-
})
81+
self._helper.append_op(type='chunk_eval',
82+
inputs=this_input,
83+
outputs={
84+
"Precision": [precision],
85+
"Recall": [recall],
86+
"F1-Score": [f1_score],
87+
"NumInferChunks": [num_infer_chunks],
88+
"NumLabelChunks": [num_label_chunks],
89+
"NumCorrectChunks": [num_correct_chunks]
90+
},
91+
attrs={
92+
"num_chunk_types":
93+
self.num_chunk_types,
94+
"chunk_scheme":
95+
self.chunk_scheme,
96+
"excluded_chunk_types":
97+
self.excluded_chunk_types or []
98+
})
9299
return (precision, recall, f1_score, num_infer_chunks, num_label_chunks,
93100
num_correct_chunks)
94101

95102

96103
class Linear_chain_crf(paddle.fluid.dygraph.Layer):
104+
97105
def __init__(self, param_attr, size=None, is_test=False, dtype='float32'):
98106
super(Linear_chain_crf, self).__init__()
99107

@@ -131,29 +139,31 @@ def forward(self, input, label, length=None):
131139
}
132140
if length is not None:
133141
this_inputs['Length'] = [length]
134-
self._helper.append_op(
135-
type='linear_chain_crf',
136-
inputs=this_inputs,
137-
outputs={
138-
"Alpha": [alpha],
139-
"EmissionExps": [emission_exps],
140-
"TransitionExps": transition_exps,
141-
"LogLikelihood": log_likelihood
142-
},
143-
attrs={"is_test": self._is_test, })
142+
self._helper.append_op(type='linear_chain_crf',
143+
inputs=this_inputs,
144+
outputs={
145+
"Alpha": [alpha],
146+
"EmissionExps": [emission_exps],
147+
"TransitionExps": transition_exps,
148+
"LogLikelihood": log_likelihood
149+
},
150+
attrs={
151+
"is_test": self._is_test,
152+
})
144153
return log_likelihood
145154

146155

147156
class LayoutXLMForTokenClassification_with_CRF(LayoutXLMPretrainedModel):
157+
148158
def __init__(self, layoutxlm, num_classes, dropout=None):
149159
super(LayoutXLMForTokenClassification_with_CRF, self).__init__()
150160
self.num_classes = num_classes
151161
if isinstance(layoutxlm, dict):
152162
self.layoutxlm = LayoutXLMModel(**layoutxlm)
153163
else:
154164
self.layoutxlm = layoutxlm
155-
self.dropout = nn.Dropout(dropout if dropout is not None else
156-
self.layoutxlm.config["hidden_dropout_prob"])
165+
self.dropout = nn.Dropout(dropout if dropout is not None else self.
166+
layoutxlm.config["hidden_dropout_prob"])
157167
self.emission_classifier = nn.Linear(
158168
self.layoutxlm.config["hidden_size"], self.num_classes)
159169
self.emission_classifier.apply(self.init_weights)
@@ -198,7 +208,8 @@ def forward(self,
198208
attention_mask=attention_mask,
199209
token_type_ids=token_type_ids,
200210
position_ids=position_ids,
201-
head_mask=head_mask, )
211+
head_mask=head_mask,
212+
)
202213
seq_length = input_ids.shape[1]
203214
# sequence out and image out
204215
sequence_logits, image_output = outputs[0][:, :seq_length], outputs[
@@ -208,8 +219,9 @@ def forward(self,
208219
labels = labels.reshape([-1, seq_length, 1])
209220

210221
# standard crf loss
211-
crf_cost = self.linear_chain_crf(
212-
input=emission, label=labels, length=length)
222+
crf_cost = self.linear_chain_crf(input=emission,
223+
label=labels,
224+
length=length)
213225
crf_decode = self.crf_decoding(input=emission, length=length)
214226
if is_train:
215227
return [crf_cost]

0 commit comments

Comments
ย (0)