I Left Home For Alaska

I will never forget the three am drive through the abnormally quiet city. Dallas was my home all my life and suddenly I’m being transported away to take a chance on an unknown land with a bunch of…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Using BERT with Pytorch

A super-easy practical guide to build you own fine tuned BERT based architecture using Pytorch.

Bert image — sesame street

If you understand BERT you might identify you will need to take these two steps in your code: tokenize the samples and build your own fine-tuned architecture.

BERT uses a special tokenization (BPE) of the words. In addition, depending on your task, each sentence can be padded with [CLS] at the beginning of the first sentence and [SEP] tokens at the end of each sentence.
The [CLS] token is used mainly for classification tasks, and the [SEP] token is used for multiple sentences for tasks such as SNLI or question answering.

BERT input presentation [1]

2. Build your own architecture based on BERT

Unlike traditional embeddings, BERT embeddings are context related, therefore we need to rely on a pretrained BERT architecture. In full sentence classification tasks we add a classification layer on top of the output for the [CLS] token. In sequence tagging we will need the full output of the sequence. This simple example is a sequence tagging one.

3. How it all comes together

I hope this makes working with pre-trained BERT model in Pytorch easier.

Become a ML Writer

Add a comment

Related posts:

An Ethnographic Masterpiece or just another Orientalist view of the East?

The documentary opens with the line “The way of the world is the west.” (Grass: A Nation’s Battle for Life, 1925) serves as a preparation for a heavily Orientalist approach in both filming and…

XCrypt Exchange Platform Will Redefine Crypto Trading

Everyone knows that in modern times it is already difficult to find that sphere where the cryptocurrency would not get. But the popularity and relevance of cryptocurrency makes you think about ways…

TraDove Completes Version 1 of B2B Blockchain Payment Solution

As the month of May came to a close, we were happy to announce the exciting news that so too did development on the beta version of TraDove’s B2B Blockchain Payment Solution. This beta, officially…