Fine-grained emotion detectiong using BERT and GoEmotions dataset. Details in report.pdf .
The project was developed in Google Colab utilizing Google Drive as storage. To setup the running environment please follows below steps.
- Create a colab notebook and clone the project.
from google.colab import drive
drive.mount('/content/drive/')
repos_dir = '/content/drive/MyDrive/{where you want to put in google drive}'
repos = 'fine-grained-emotions-bert' # our repository name
url = "https://github.com/jsong336/fine-grained-emotions-bert.git"
%cd $repos_dir
! git clone $url
%cd $repos_dir/$repos
! git pull
- Go to Kaggle and create developer API credential.
import os
os.environ['KAGGLE_USERNAME'] = ""
os.environ['KAGGLE_KEY'] = ""
def download_from_kaggle(url, target_dir):
dataset_name = url.split('/', 1)[-1]
dirname = os.path.join(target_dir, dataset_name)
! mkdir $dirname
! kaggle datasets download -d $url
! unzip $dataset_name -d $dirname
return
input_dir = repos_dir + '/inputs'
download_from_kaggle('shivamb/go-emotions-google-emotions-dataset', input_dir)
download_from_kaggle('ishivinal/contractions', input_dir)
download_from_kaggle('bittlingmayer/spelling', input_dir)
Go to your Google Drive and make sure you have the repository cloned and datasets downloaded
-
Go to
notebooks/
and runmain_prepare_dataset.ipynb
and you should have train & test datasets splitted in theinputs/
-
Run
main_bert_gru.ipynb
andmain_bert_dense.ipynb
notebooks to train the models. (Careful, notebooks create checkpoints in your Google Drive and could easily take up a lot of space in Google Drive) -
Run
view_model_analysis.ipynb
to compare the models.
Because all of our codes were developed in google colab and archives were stored in google drive, any view_*
or main_*
codes contains following block
import os
# os.environ['GO_EMOTIONS_COLAB_WORKDIR'] = '/content/drive/MyDrive/Notebooks/Repository/go-emotions/notebooks'
colab_workdir = os.environ.get('GO_EMOTIONS_COLAB_WORKDIR')
if colab_workdir:
print('Running with colab')
from google.colab import drive
drive.mount('/content/drive')
%cd $colab_workdir
!pip install -q -r ../requirements.txt
else:
print('Running with jupyter notebook')
You might need to update os.environ['GO_EMOTIONS_COLAB_WORKDIR'] = {cloned work directory in google drive}
.