Bert Fine Tuning (AutoRecovered)
Bert Fine Tuning (AutoRecovered)
2.pytorch :
This section provides information on setting up Cloud Storage bucket and a Compute Engine
VM.Open a Cloud Shell window.
2. Configure gcloud command-line tool to use the project where you want to create Cloud TPU.
4. Launch a Compute Engine VM and Cloud TPU using the ctpu up command.
$ ctpu up --tpu-size=v3-8 \
--machine-type=n1-standard-8 \
--zone=us-central1-b \
--tf-version=1.15.3 \
--name=bert-tutorial
As you continue these instructions, run each command that begins with (vm)$ in your VM session
window.
From your Compute Engine virtual machine (VM), clone the BERT repository.
Download download_glue_data.py
This tutorial uses the General Language Understanding Evaluation (GLUE) benchmark to evaluate
and analyze the performance of the model. To use this benchmark, download
the download_glue_data.py script using the following git clone command:
python3 ./bert/run_classifier.py \
--task_name=${TASK_NAME} \
--do_train=true \
--do_eval=true \
--data_dir=${GLUE_DIR}/${TASK_NAME} \
--vocab_file=${BERT_BASE_DIR}/vocab.txt \
--bert_config_file=${BERT_BASE_DIR}/bert_config.json \
--init_checkpoint=${BERT_BASE_DIR}/bert_model.ckpt \
--max_seq_length=128 \
--train_batch_size=32 \
--learning_rate=2e-5 \
--num_train_epochs=3.0 \
--output_dir=${STORAGE_BUCKET}/${TASK_NAME}-output/ \
--use_tpu=True \
--tpu_name=${TPU_NAME}
The training should take less than 5 minutes. When the training completes, you should see results
similar to the following:
STEP 1:Preprocessing
The BERT layer requires in input an array of sequences with a defined max length for each sequence.Create
an instance of the BERT FullTokenizer, that requires in input the corpora used for training the BERT
Split data into training set, training labels, testing set and testing labels and Shuffling each sentence
set then Tokenized each sentence set using the tokenizer described above. Appending the tokens
which completely depends upon the dataset type. Performed one hot encoder to each label of the
label set
bert_config.json which contains all the parameters required for creating the
layer.To freeze all the original layer wrapper into the BertModelLayer class it
would be better keep all bert parameters False
import os
def createBertLayer():
global bert_layer
bert_params = bert.params_from_pretrained_ckpt(bertDir)
#imputing pretrained parmas to bert model
bert_layer.apply_adapter_freeze()
Making Model
After creating bert layer we can join sequential layers right after it,and can
use dropouts to reduce overfitting
- Dinesh Yedakula
- 4th Year
- Mechanical Engineering
- IIt Dharwad