How To Run Code From Git Repo In Google Collab GPU Notebook

In this post, I will show you how to run code BERT-Keyword-Extractor in Google Collab notebook. You can download following repo.

github.com/ibatra/BERT-Keyword-Extractor

First create a new notebook by going to File > New Python 3 Notebook

We need to turn on GPU option for this notebook. To do that go to edit > notebook settings and select GPU as hardware selector.

We need to install tensorflow-gpu to run this code. Do using following pip command.

In [2]:
!pip install tensor-gpu==2.0.0

Lets import the tensorflow now.

In [4]:
import tensorflow as tf

Now clone the repo.

In [5]:
!git clone https://github.com/ibatra/BERT-Keyword-Extractor

If you do ls, you should see BERT-Keyword-Extractor git directory.

We also need to install nltk punkt package.

In [6]:
import nltk
nltk.download('punkt')

Install following two libraries too.

In [11]:
!pip install pytorch_pretrained_bert
!pip install seqeval

Now we are ready to run the Bert code.

Lets first generate the model. Run following code.

In [12]:
cd BERT-Keyword-Extractor
!python main.py --data "maui-semeval2010-train" --lr 2e-5 --batch_size 32 --save "model.pt" --epochs 3      

Once it is completed you should see model.pt in your current directory.

Test it using following command.

In [13]:
!python keyword-extractor.py --sentence "BERT is a great model" --path "model.pt"      

Related Topics