language: el
pipeline_tag: fill-mask
thumbnail: https://github.com/nlpaueb/GreekBERT/raw/master/greek-bert-logo.png
widget:
- text: "Σήμερα είναι μια [MASK] μέρα."
希腊语BERT
一个希腊语版本的BERT预训练语言模型。
预训练语料库
bert-base-greek-uncased-v1
的预训练语料包括:
未来版本还将包括:
预训练细节
- 我们使用Google BERT的GitHub仓库(https://github.com/google-research/bert)提供的官方代码训练BERT。* 然后使用Hugging Face的Transformers转换脚本将TF检查点和词汇表转换为所需格式,以便能够用两行代码为PyTorch和TF2用户加载模型。
- 我们发布了一个类似于英语
bert-base-uncased
的模型(12层,768隐藏层,12头,1.1亿参数)。
- 我们选择了相同的训练设置:100万训练步,每批256个长度为512的序列,初始学习率为1e-4。
- 我们能够使用TensorFlow Research Cloud (TFRC)免费提供的单个Google Cloud TPU v3-8,同时利用GCP研究积分。非常感谢这两个Google项目对我们的支持!
* 您仍然可以从这个Google Drive文件夹访问原始的TensorFlow检查点。
要求
我们发布了bert-base-greek-uncased-v1
作为Hugging Face的Transformers仓库的一部分。因此,您需要通过pip安装transformers库以及PyTorch或Tensorflow 2。
pip install transformers
pip install (torch|tensorflow)
文本预处理(去重音 - 小写)
注意: 预处理现在由默认的分词器原生支持。无需包含以下代码。
为了使用bert-base-greek-uncased-v1
,您需要将文本预处理为小写字母并移除所有希腊语重音符号。
import unicodedata
def strip_accents_and_lowercase(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn').lower()
accented_string = "Αυτή είναι η Ελληνική έκδοση του BERT."
unaccented_string = strip_accents_and_lowercase(accented_string)
print(unaccented_string)
加载预训练模型
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
model = AutoModel.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
使用预训练模型作为语言模型
import torch
from transformers import *
tokenizer_greek = AutoTokenizer.from_pretrained('nlpaueb/bert-base-greek-uncased-v1')
lm_model_greek = AutoModelWithLMHead.from_pretrained('nlpaueb/bert-base-greek-uncased-v1')
text_1 = 'O ποιητής έγραψε ένα [MASK] .'
input_ids = tokenizer_greek.encode(text_1)
print(tokenizer_greek.convert_ids_to_tokens(input_ids))
outputs = lm_model_greek(torch.tensor([input_ids]))[0]
print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 5].max(0)[1].item()))
text_2 = 'Είναι ένας [MASK] άνθρωπος.'
input_ids = tokenizer_greek.encode(text_2)
print(tokenizer_greek.convert_ids_to_tokens(input_ids))
outputs = lm_model_greek(torch.tensor([input_ids]))[0]
print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 3].max(0)[1].item()))
text_3 = 'Είναι ένας [MASK] άνθρωπος και κάνει συχνά [MASK].'
input_ids = tokenizer_greek.encode(text_3)
print(tokenizer_greek.convert_ids_to_tokens(input_ids))
outputs = lm_model_greek(torch.tensor([input_ids]))[0]
print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 8].max(0)[1].item()))
下游任务评估
详细结果请阅读文章:
GREEK-BERT: The Greeks visiting Sesame Street. John Koutsikakis, Ilias Chalkidis, Prodromos Malakasiotis and Ion Androutsopoulos. 在《第11届希腊人工智能会议论文集》(SETN 2020)中。在线举行。2020年。(https://arxiv.org/abs/2008.12014)
使用希腊NER数据集进行命名实体识别
模型名称 |
微平均F1 |
BILSTM-CNN-CRF (Ma and Hovy, 2016) |
76.4 ± 2.07 |
M-BERT-UNCASED (Devlin et al., 2019) |
81.5 ± 1.77 |
M-BERT-CASED (Devlin et al., 2019) |
82.1 ± 1.35 |
XLM-R (Conneau et al., 2020) |
84.8 ± 1.50 |
GREEK-BERT (ours) |
85.7 ± 1.00 |
使用XNLI进行自然语言推理
模型名称 |
准确率 |
DAM (Parikh et al., 2016) |
68.5 ± 1.71 |
M-BERT-UNCASED (Devlin et al., 2019) |
73.9 ± 0.64 |
M-BERT-CASED (Devlin et al., 2019) |
73.5 ± 0.49 |
XLM-R (Conneau et al., 2020) |
77.3 ± 0.41 |
GREEK-BERT (ours) |
78.6 ± 0.62 |