Transfer Learning: Hands On Bert πŸ˜€

Sajal Rastogi
Analytics Vidhya
Published in
3 min readOct 18, 2020

--

Hi Medium, Lets Talk about state-of-art in Natural Language Processing. We Are going to focus on only three words β†’

What ? Why ? How ?

This article will only focus on Introduction and Coding part.

WHAT is BERT ?

BERT stands for Bidirectional Encoder Representations from Transformers . It is an Open-Source project by Google AI researchers with a great power of understanding the context of sentence (language) showing high performance in various nlp tasks such as question-answer system , Named-entity-recognition, Machine Translation and many more.

WHY BERT ?

Bert is based on transformer model that uses Attention mechanism for learning contextual relationship among words of a sentence i.e. it takes positional encoding into account. Lets have a view at an example below β†’

Sentence 1: dog bites man

Sentence 2: man bites dog

What is the difference between two ? Its the position of words ! Ohh Damn ! this is what most nlp models were missing back then . Is it all Bert have ? No !

Bert has another most important feature Masked Language Modelling and Feed Forward Layer.

Feed Forward is basically for taking using of backpropagation and introducing some non-linearity in model.

MLM β€” The model then attempts to predict the original value of the masked words, based on the context provided by the other, non-masked, words in the sequence

Transfer Learning β†’ Using and modifying a pre-trained model to our needs. We are using now β†’ https://github.com/google-research/bert

HOW ?

Github Links β†’ https://github.com/r-sajal/DeepLearning-/tree/master/Natural-Language-Processing/Part%201

Model 1: Hugging face Transformer

You can find the comments for understanding the code. For any queries please comment

Following Three Pictures were For those who have multiclass classification instead of binary β†’

Folder bert

.

Click on the Bert folder on left Image

.

.

.

get_labels

.

In this image on left open run_classifier.py

.

.

.

Put as many numbers you want in the list separated by comma representing the classes of your classification.

.

.

Model 2: Ktrain

You can find the comments for understanding the code. For any queries please comment

Reference β†’

UPVOTE !!!!!! Please πŸ™‡β€β™‚οΈ

Thank you for your Precious Time .

Personal Links β†’

--

--