Skip to content

Commit 7fa38a4

Browse files
committed
update
1 parent 4ae8028 commit 7fa38a4

33 files changed

+21
-24
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6-
# C extensions
76
*.so
87

98
# Distribution / packaging

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ arxiv: https://arxiv.org/pdf/1909.11942.pdf
2323
* Pre-LN: 把Layer Norm换个位置,比如放在Residual的过程之中(称为`Pre-LN Transformer`
2424

2525
<p align="center"><img width="200" src="https://lonepatient-1257945978.cos.ap-chengdu.myqcloud.com/Selection_001.png" /></p>
26+
2627
paper: [On Layer Normalization in the Transformer Architecture](https://openreview.net/forum?id=B1x8anVFPr)
2728

2829
**使用方式**

README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ arxiv: https://arxiv.org/pdf/1909.11942.pdf
1616
- scikit-learn
1717
- sentencepiece
1818

19-
### Download Pre-trained Models of English
19+
## Download Pre-trained Models of English
2020

2121
Version 2 of ALBERT models is relased. TF-Hub modules are available:
2222

albert_chinese_pytorch/callback/optimizater.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
'Ranger',
2424
'BertAdam'
2525
]
26-
2726
class SGDW(Optimizer):
2827
r"""Implements stochastic gradient descent (optionally with momentum) with
2928
weight decay from the paper `Fixing Weight Decay Regularization in Adam`_.

albert_chinese_pytorch/convert_albert_tf_checkpoint_to_pytorch.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from model.modeling_albert import BertConfig, AlbertForPreTraining, load_tf_weights_in_albert
2525

2626
import logging
27+
2728
logging.basicConfig(level=logging.INFO)
2829

2930
def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file,share_type, pytorch_dump_path):
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#encoding:utf-8
1+
#encoding:utf-8

albert_chinese_pytorch/lcqmc_progressor.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def __init__(self, guid, text_a, text_b=None, label=None):
2323
self.text_b = text_b
2424
self.label = label
2525

26-
2726
class InputFeature(object):
2827
'''
2928
A single set of features of data.

albert_chinese_pytorch/metrics/glue_compute_metrics.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import csv
1818
import sys
1919
import logging
20-
2120
logger = logging.getLogger(__name__)
2221

2322
try:

albert_chinese_pytorch/model/configuration_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from __future__ import (absolute_import, division, print_function,
1919
unicode_literals)
20-
2120
import copy
2221
import json
2322
import logging
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#encoding:utf-8
1+
#encoding:utf-8

albert_chinese_pytorch/prepare_lm_data_mask.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def truncate_seq_pair(tokens_a, tokens_b, max_num_tokens):
2626
else:
2727
trunc_tokens.pop()
2828

29-
3029
def create_instances_from_document(all_documents, document_index, max_seq_length, short_seq_prob,
3130
masked_lm_prob, max_predictions_per_seq, vocab_words):
3231
"""Creates `TrainingInstance`s for a single document.

albert_chinese_pytorch/prepare_lm_data_ngram.py

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def truncate_seq_pair(tokens_a, tokens_b, max_num_tokens):
2727
else:
2828
trunc_tokens.pop()
2929

30-
3130
def create_instances_from_document(all_documents, document_index, max_seq_length, short_seq_prob,
3231
max_ngram, masked_lm_prob, max_predictions_per_seq, vocab_words):
3332
"""Creates `TrainingInstance`s for a single document.

albert_chinese_pytorch/prev_trained_model/albert_tiny/config.json

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"max_position_embeddings": 512,
1111
"num_attention_heads": 12,
1212
"num_hidden_layers": 4,
13-
1413
"pooler_fc_size": 768,
1514
"pooler_num_attention_heads": 12,
1615
"pooler_num_fc_layers": 3,

albert_chinese_pytorch/processors/glue.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
logger = logging.getLogger(__name__)
2424

25-
2625
def collate_fn(batch):
2726
"""
2827
batch should be a list of (sequence, target, length) tuples...

albert_chinese_pytorch/run_classifier.py

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
'albert': (BertConfig, AlbertForSequenceClassification, BertTokenizer)
4747
}
4848

49-
5049
def train(args, train_dataset, model, tokenizer):
5150
""" Train the model """
5251
args.train_batch_size = args.per_gpu_train_batch_size * max(1, args.n_gpu)

albert_chinese_pytorch/run_classifier_lcqmc.sh

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export BERT_BASE_DIR=$CURRENT_DIR/prev_trained_model/albert_tiny
33
export DATA_DIR=$CURRENT_DIR/dataset
44
export OUTPUR_DIR=$CURRENT_DIR/outputs
55
TASK_NAME="lcqmc"
6+
67
python run_classifier.py \
78
--model_type=albert \
89
--model_name_or_path=$BERT_BASE_DIR \

albert_chinese_pytorch/run_pretraining.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from tools.common import seed_everything
2020

2121
InputFeatures = namedtuple("InputFeatures", "input_ids input_mask segment_ids lm_label_ids is_next")
22+
2223
def convert_example_to_features(example, tokenizer, max_seq_length):
2324
tokens = example["tokens"]
2425
segment_ids = example["segment_ids"]

albert_chinese_pytorch/tools/common.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import logging
1111

1212
logger = logging.getLogger()
13+
1314
def init_logger(log_file=None, log_file_level=logging.NOTSET):
1415
'''
1516
Example:

albert_english_pytorch/callback/progressbar.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
32
class ProgressBar(object):
43
'''
54
custom progress bar

albert_english_pytorch/convert_albert_tf_checkpoint_to_pytorch.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import argparse
2222
import torch
23-
2423
from model.modeling_albert import BertConfig, AlbertForPreTraining, load_tf_weights_in_albert
2524

2625
import logging

albert_english_pytorch/dataset/qqp/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6-
# C extensions
6+
# C extension
77
*.so
88

99
# Distribution / packaging

albert_english_pytorch/metrics/glue_compute_metrics.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import logging
2020

2121
logger = logging.getLogger(__name__)
22-
2322
try:
2423
from scipy.stats import pearsonr, spearmanr
2524
from sklearn.metrics import matthews_corrcoef, f1_score

albert_english_pytorch/model/configuration_bert.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from io import open
2424

2525
from model.configuration_utils import PretrainedConfig
26-
2726
logger = logging.getLogger(__name__)
2827

2928
BERT_PRETRAINED_CONFIG_ARCHIVE_MAP = {
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
#encoding:utf-8
1+
#encoding:utf-8
2+

albert_english_pytorch/prev_trained_model/albert_base_tf_v1/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6-
# C extensions
6+
# C extension
77
*.so
88

99
# Distribution / packaging

albert_english_pytorch/processors/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .glue import (glue_output_modes, glue_processors, glue_tasks_num_labels,
33
glue_convert_examples_to_features,collate_fn)
44

5+

albert_english_pytorch/run_classifier.py

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
from metrics.glue_compute_metrics import compute_metrics
3636
from processors import glue_output_modes as output_modes
37-
3837
from processors import glue_processors as processors
3938
from processors import glue_convert_examples_to_features as convert_examples_to_features
4039
from processors import collate_fn

albert_english_pytorch/run_classifier_cola.sh

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export BERT_BASE_DIR=$CURRENT_DIR/prev_trained_model/albert_base_v2
33
export DATA_DIR=$CURRENT_DIR/dataset
44
export OUTPUR_DIR=$CURRENT_DIR/outputs
55
TASK_NAME="cola"
6+
67
python run_classifier.py \
78
--model_type=albert \
89
--model_name_or_path=$BERT_BASE_DIR \

albert_english_pytorch/run_classifier_mnli.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ python run_classifier.py \
2020
--logging_steps=24544 \
2121
--save_steps=24544 \
2222
--output_dir=$OUTPUR_DIR/${TASK_NAME}_output/ \
23-
--overwrite_output_dir
23+
--overwrite_output_dir \
24+
--seed=42

albert_english_pytorch/run_classifier_qqp.sh

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export BERT_BASE_DIR=$CURRENT_DIR/prev_trained_model/albert_base_v2
33
export DATA_DIR=$CURRENT_DIR/dataset
44
export OUTPUR_DIR=$CURRENT_DIR/outputs
55
TASK_NAME="qqp"
6+
67
python run_classifier.py \
78
--model_type=albert \
89
--model_name_or_path=$BERT_BASE_DIR \

albert_english_pytorch/run_classifier_sst2.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ python run_classifier.py \
2020
--logging_steps=4210 \
2121
--save_steps=4210 \
2222
--output_dir=$OUTPUR_DIR/${TASK_NAME}_output/ \
23-
--overwrite_output_dir
23+
--overwrite_output_dir \
24+
--seed=42
2425

albert_english_pytorch/run_classifier_stsb.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ python run_classifier.py \
77
--model_type=albert \
88
--model_name_or_path=$BERT_BASE_DIR \
99
--task_name=$TASK_NAME \
10-
--do_train \
1110
--do_eval \
11+
--do_train \
1212
--do_lower_case \
1313
--data_dir=$DATA_DIR/${TASK_NAME}/ \
1414
--max_seq_length=128 \

albert_english_pytorch/tools/common.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import logging
1111

1212
logger = logging.getLogger()
13+
1314
def init_logger(log_file=None, log_file_level=logging.NOTSET):
1415
'''
1516
Example:

0 commit comments

Comments
 (0)