Simple BERT implementation on R side
03:20 17 Aug 2022

I would like to implement a simple text classification using BERT model on R side. On my local side, I have no progress because of this issue. Therefore, I moved to kaggle platform. Also, I have started to replicate this kaggle kernel. However, I could not succeed to call transformer$TFBertModel because this line throws me the below error. As you might guess that there are few tutorials BERT on R side, so I am also appreciated for any simple BERT text classification tutorial based on R (over kaggle).

ERROR
Error in py_get_attr_impl(x, name, silent): RuntimeError: Failed to import transformer...

as:

library(tidyverse)
library(reticulate)
library(LiblineaR)
library(tidymodels)
library(rsample)

reticulate::py_install('transformers', pip = TRUE)

transformer = reticulate::import('transformers')
tf = reticulate::import('tensorflow')
builtins <- import_builtins()

tokenizer <- transformer$AutoTokenizer$from_pretrained('bert-base-uncased')

BERT = transformer$TFBertModel$from_pretrained("bert-base-uncased")

print("completed...")
r tensorflow bert-language-model transformer-model reticulate