当前位置:   article > 正文

谷歌ALBERT模型V2+中文版来了:之前刷新NLP各大基准,现在GitHub热榜第二

google大模型 中文评测集 gethub

点击上方“AI遇见机器学习”,选择“星标”公众号

重磅干货,第一时间送达

作者:十三、发自、凹非寺

转自:量子位(QbitAI),未经允许不得二次转载

BERT模型参数小18倍,性能还超越了它。

这就是谷歌前不久发布的轻量级BERT模型——ALBERT

不仅如此,还横扫各大“性能榜”,在SQuAD和RACE测试上创造了新的SOTA。

而最近,谷歌开源了中文版本和Version 2,项目还登上了GitHub热榜第二

ALBERT 2性能再次提升

在这个版本中,“no dropout”、“additional training data”、“long training time”策略将应用到所有的模型。

与初代ALBERT性能相比结果如下。

从性能的比较来说,对于ALBERT-base、ALBERT-large和ALBERT-xlarge,v2版要比v1版好得多。

说明采用上述三个策略的重要性。

平均来看,ALBERT-xxlarge比v1略差一些,原因有以下2点:

额外训练了1.5M步(两个模型的唯一区别就是训练1.5M和3M步);
对于v1,在BERT、Roberta和XLnet给出的参数集中做了一点超参数搜索;对于v2,只是采用除RACE之外的V1参数,其中使用的学习率为1e-5和0 ALBERT DR。

总的来说,Albert是BERT的轻量版, 使用减少参数的技术,允许大规模的配置,克服以前的内存限制。

Albert使用了一个单模型设置,在 GLUE 基准测试中的性能:

Albert-xxl使用了一个单模型设置,在SQuaD和RACE基准测试中的性能:

中文版下载地址

Base
https://storage.googleapis.com/albert_models/albert_base_zh.tar.gz

Large
https://storage.googleapis.com/albert_models/albert_large_zh.tar.gz

XLarge
https://storage.googleapis.com/albert_models/albert_xlarge_zh.tar.gz

Xxlarge
https://storage.googleapis.com/albert_models/albert_xxlarge_zh.tar.gz

ALBERT v2下载地址

Base
[Tar File]:
https://storage.googleapis.com/albert_models/albert_base_v2.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_base/2

Large
[Tar File]:
https://storage.googleapis.com/albert_models/albert_large_v2.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_large/2

XLarge
[Tar File]:
https://storage.googleapis.com/albert_models/albert_xlarge_v2.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_xlarge/2

Xxlarge
[Tar File]:
https://storage.googleapis.com/albert_models/albert_xxlarge_v2.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_xxlarge/2

预训练模型

可以使用 TF-Hub 模块:

Base
[Tar File]:
https://storage.googleapis.com/albert_models/albert_base_v1.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_base/1

Large
[Tar File]:
https://storage.googleapis.com/albert_models/albert_large_v1.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_large/1

XLarge
[Tar File]:
https://storage.googleapis.com/albert_models/albert_xlarge_v1.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_xlarge/1

Xxlarge
[Tar File]:
https://storage.googleapis.com/albert_models/albert_xxlarge_v1.tar.gz
[TF-Hub]:
https://tfhub.dev/google/albert_xxlarge/1

TF-Hub模块使用示例:

  1. tags = set()
  2. if is_training:
  3.   tags.add("train")
  4. albert_module = hub.Module("https://tfhub.dev/google/albert_base/1", tags=tags,
  5.                            trainable=True)
  6. albert_inputs = dict(
  7.     input_ids=input_ids,
  8.     input_mask=input_mask,
  9.     segment_ids=segment_ids)
  10. albert_outputs = albert_module(
  11.     inputs=albert_inputs,
  12.     signature="tokens",
  13.     as_dict=True)
  14. # If you want to use the token-level output, use
  15. # albert_outputs["sequence_output"] instead.
  16. output_layer = albert_outputs["pooled_output"]

预训练说明

要预训练ALBERT,可以使用run_pretraining.py:

  1. pip install -r albert/requirements.txt
  2. python -m albert.run_pretraining 
  3.     --input_file=... 
  4.     --output_dir=... 
  5.     --init_checkpoint=... 
  6.     --albert_config_file=... 
  7.     --do_train 
  8.     --do_eval 
  9.     --train_batch_size=4096 
  10.     --eval_batch_size=64 
  11.     --max_seq_length=512 
  12.     --max_predictions_per_seq=20 
  13.     --optimizer= lamb  
  14.     --learning_rate=.00176 
  15.     --num_train_steps=125000 
  16.     --num_warmup_steps=3125 
  17.     --save_checkpoints_steps=5000

GLUE上的微调

要对 GLUE 进行微调和评估,可以参阅该项目中的run_glue.sh文件。

底层的用例可能希望直接使用run_classifier.py脚本。

run_classifier.py可对各个 GLUE 基准测试任务进行微调和评估。

比如 MNLI:

  1. pip install -r albert/requirements.txt
  2. python -m albert.run_classifier 
  3.   --vocab_file=... 
  4.   --data_dir=... 
  5.   --output_dir=... 
  6.   --init_checkpoint=... 
  7.   --albert_config_file=... 
  8.   --spm_model_file=... 
  9.   --do_train 
  10.   --do_eval 
  11.   --do_predict 
  12.   --do_lower_case 
  13.   --max_seq_length=128 
  14.   --optimizer=adamw 
  15.   --task_name=MNLI 
  16.   --warmup_step=1000 
  17.   --learning_rate=3e-5 
  18.   --train_step=10000 
  19.   --save_checkpoints_steps=100 
  20.   --train_batch_size=128

可以在run_glue.sh中找到每个GLUE任务的default flag。

从TF-Hub模块开始微调模型:

albert_hub_module_handle==https://tfhub.dev/google/albert_base/1

在评估之后,脚本应该报告如下输出:

  1. ***** Eval results *****
  2.   global_step = ...
  3.   loss = ...
  4.   masked_lm_accuracy = ...
  5.   masked_lm_loss = ...
  6.   sentence_order_accuracy = ...
  7.   sentence_order_loss = ...

在SQuAD上微调

要对 SQuAD v1上的预训练模型进行微调和评估,请使用 run SQuAD v1.py 脚本:

  1. pip install -r albert/requirements.txt
  2. python -m albert.run_squad_v1 
  3.   --albert_config_file=... 
  4.   --vocab_file=... 
  5.   --output_dir=... 
  6.   --train_file=... 
  7.   --predict_file=... 
  8.   --train_feature_file=... 
  9.   --predict_feature_file=... 
  10.   --predict_feature_left_file=... 
  11.   --init_checkpoint=... 
  12.   --spm_model_file=... 
  13.   --do_lower_case 
  14.   --max_seq_length=384 
  15.   --doc_stride=128 
  16.   --max_query_length=64 
  17.   --do_train=true 
  18.   --do_predict=true 
  19.   --train_batch_size=48 
  20.   --predict_batch_size=8 
  21.   --learning_rate=5e-5 
  22.   --num_train_epochs=2.0 
  23.   --warmup_proportion=.1 
  24.   --save_checkpoints_steps=5000 
  25.   --n_best_size=20 
  26.   --max_answer_length=30

对于 SQuAD v2,使用 run SQuAD v2.py 脚本:

  1. pip install -r albert/requirements.txt
  2. python -m albert.run_squad_v2 
  3.   --albert_config_file=... 
  4.   --vocab_file=... 
  5.   --output_dir=... 
  6.   --train_file=... 
  7.   --predict_file=... 
  8.   --train_feature_file=... 
  9.   --predict_feature_file=... 
  10.   --predict_feature_left_file=... 
  11.   --init_checkpoint=... 
  12.   --spm_model_file=... 
  13.   --do_lower_case 
  14.   --max_seq_length=384 
  15.   --doc_stride=128 
  16.   --max_query_length=64 
  17.   --do_train 
  18.   --do_predict 
  19.   --train_batch_size=48 
  20.   --predict_batch_size=8 
  21.   --learning_rate=5e-5 
  22.   --num_train_epochs=2.0 
  23.   --warmup_proportion=.1 
  24.   --save_checkpoints_steps=5000 
  25.   --n_best_size=20 
  26.   --max_answer_length=30

传送门

GitHub项目地址:
https://github.com/google-research/ALBERT

作者系网易新闻·网易号“各有态度”签约作者

  1. 推荐阅读
  2. 干货|学术论文怎么写
  3. 资源|NLP书籍及课程推荐(附资料下载)
  4. 干货|全面理解N-Gram语言模型
  5. 资源|《Machine Learning for OpenCV》书籍推荐
  6. 欢迎关注我们,看通俗干货!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/46992
推荐阅读
相关标签
  

闽ICP备14008679号