I’m looking through https://docs.fast.ai/ to try to make use of the fastai utilities we’ve been learning about with my own PyTorch model (e.g., how to turn it into a Learner), and not finding that.
I see the occasional forum posts using code that no longer work with v1 of fastai…
…I feel like I’m missing something big by not turning up anything significant in my searches – I really have searched before posting this, so, sorry about this. Presumably people do this all the time. Can anyone point me to the right place in the docs or an up-to-date explanation? Thanks.
Update 1 See docs for the Learner class. “Train model using data to minimize loss_func with optimizer opt_func.” To use your PyTorch Module with a Learner, it looks like you just pass it in as the second argument when you instantiate the Learner class.
from fastai import *
from fastai.text import *
# using BertModel class with Google AI's pretrained BERT base uncased model
from pytorch_pretrained_bert import BertModel
# create model. check the PyTorch BERT README
# load pre-trained model (weights). model is a type of torch.nn.Module
model = BertModel.from_pretrained('bert-base-uncased')
# create a DataBunch
data = TextDataBunch.from_folder(path)
# define a Learner object
# this is where the basic training loop is defined
learn = Learner(data, model)
# train
learn.fit(10)
I still have to play around with BERT but I guess for BERT the standard text dataset and/or training loop will not do it, as you have the masked language model and the next sentence prediction training modes, which are quite different from the traditional approaches.
Right now it looks like there is only the Wikitext-103 and the OpenAI_Transformer (not sure if this is GPT-1 or 2) pre-trained model. The TransformerXL does not have any model saved.
The models are pulled using the get_language_model method. I just don’t know how much of the logic in that method would need to change for different pre-trained models though…or maybe it is as simple as saving a new pre-trained model e.g. bert_base_uncased and updating the dictionary?