DistilmBERT is the multilingual counterpart of DistilBERT, analogous to multilingual BERT (mBERT). A pretrained multilingual checkpoint can be adapted to Twi even though Twi was not included in its original training. The adaptation uses monolingual Twi text from JW300 and masked language modeling. section 9.2.1
from transformers import DistilBertTokenizerFast #1
tokenizer = DistilBertTokenizerFast.from_pretrained("distilbert-base-multilingual-cased") #2
Load the cased multilingual tokenizer for the pretrained checkpoint. section 9.2.1
from transformers import LineByLineTextDataset
dataset = LineByLineTextDataset(
tokenizer=tokenizer,
file_path="../input/jw300entw/jw300.en-tw.tw", #1
block_size=128) #2
Prepare line-by-line Twi text from JW300 as training data. section 9.2.1
A Transformers data collator masks 15% of input words for prediction; a Trainer then fine-tunes the masked-language model. The checkpoint has 135.5 million parameters, about 76% of the equivalent BERT model’s 178.6 million. section 9.2.1
Try a fill-mask prediction
After saving the fine-tuned model, use a fill-mask pipeline on “Eyi de ɔhaw kɛse baa [MASK] hɔ.” The top listed completion is “fie.” section 9.2.1
