liveBook · Manning

DistilmBERT

As explained in Transfer Learning for Natural Language Processing

DistilmBERT is the multilingual distilled BERT model referred to in this section, corresponding to multilingual DistilBERT.

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

How Transfer Learning for Natural Language Processing covers it

How deep it goes
Walks through tokenizer setup, dataset preparation, masked-language-model training, and a fill-mask check.
Examples
Uses Twi text from JW300 and demonstrates a fill-mask prediction whose top completion is “fie.”
What you can do after
Apply DistilmBERT via Transformers to fine-tune a masked-language model on Twi text and test predictions.
How it connects
Connects DistilBERT with BERT, mBERT, masked language modeling, and transfer learning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transfer Learning for Natural Language Processing. The section links point to the parts of the book it draws on.