Views
No views yet

bert-base-greek-uncased-v1 include:bert-base-uncased model (12-layer, 768-hidden, 12-heads, 110M parameters).bert-base-greek-uncased-v1 as part of Hugging Face's Transformers repository. So, you need to install the transformers library through pip along with PyTorch or Tensorflow 2.pip install transformers
pip install (torch|tensorflow)bert-base-greek-uncased-v1, you have to pre-process texts to lowercase letters and remove all Greek diacritics.1
2import unicodedata
3
4def strip_accents_and_lowercase(s):
5 return ''.join(c for c in unicodedata.normalize('NFD', s)
6 if unicodedata.category(c) != 'Mn').lower()
7
8accented_string = "Αυτή είναι η Ελληνική έκδοση του BERT."
9unaccented_string = strip_accents_and_lowercase(accented_string)
10
11print(unaccented_string) # αυτη ειναι η ελληνικη εκδοση του bert.
121from transformers import AutoTokenizer, AutoModel
2
3tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
4model = AutoModel.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")1import torch
2from transformers import *
3
4# Load model and tokenizer
5tokenizer_greek = AutoTokenizer.from_pretrained('nlpaueb/bert-base-greek-uncased-v1')
6lm_model_greek = AutoModelWithLMHead.from_pretrained('nlpaueb/bert-base-greek-uncased-v1')
7
8# ================ EXAMPLE 1 ================
9text_1 = 'O ποιητής έγραψε ένα [MASK] .'
10# EN: 'The poet wrote a [MASK].'
11input_ids = tokenizer_greek.encode(text_1)
12print(tokenizer_greek.convert_ids_to_tokens(input_ids))
13# ['[CLS]', 'o', 'ποιητης', 'εγραψε', 'ενα', '[MASK]', '.', '[SEP]']
14outputs = lm_model_greek(torch.tensor([input_ids]))[0]
15print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 5].max(0)[1].item()))
16# the most plausible prediction for [MASK] is "song"
17
18# ================ EXAMPLE 2 ================
19text_2 = 'Είναι ένας [MASK] άνθρωπος.'
20# EN: 'He is a [MASK] person.'
21input_ids = tokenizer_greek.encode(text_2)
22print(tokenizer_greek.convert_ids_to_tokens(input_ids))
23# ['[CLS]', 'ειναι', 'ενας', '[MASK]', 'ανθρωπος', '.', '[SEP]']
24outputs = lm_model_greek(torch.tensor([input_ids]))[0]
25print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 3].max(0)[1].item()))
26# the most plausible prediction for [MASK] is "good"
27
28# ================ EXAMPLE 3 ================
29text_3 = 'Είναι ένας [MASK] άνθρωπος και κάνει συχνά [MASK].'
30# EN: 'He is a [MASK] person he does frequently [MASK].'
31input_ids = tokenizer_greek.encode(text_3)
32print(tokenizer_greek.convert_ids_to_tokens(input_ids))
33# ['[CLS]', 'ειναι', 'ενας', '[MASK]', 'ανθρωπος', 'και', 'κανει', 'συχνα', '[MASK]', '.', '[SEP]']
34outputs = lm_model_greek(torch.tensor([input_ids]))[0]
35print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 8].max(0)[1].item()))
36# the most plausible prediction for the second [MASK] is "trips"| Model name | Micro 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 |
| Model name | Accuracy |
|---|---|
| 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 |
@inproceedings{greek-bert,
author = {Koutsikakis, John and Chalkidis, Ilias and Malakasiotis, Prodromos and Androutsopoulos, Ion},
title = {GREEK-BERT: The Greeks Visiting Sesame Street},
year = {2020},
isbn = {9781450388788},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3411408.3411440},
booktitle = {11th Hellenic Conference on Artificial Intelligence},
pages = {110–117},
numpages = {8},
location = {Athens, Greece},
series = {SETN 2020}
}