Deeppavlov tuned model to hugging face model

122 Views Asked by At

I have deeppavlov fine-tuned model. Is there a way to convert to a model that transformers can work with (https://github.com/huggingface/transformers)?

1

There are 1 best solutions below

0
On

Here is the way of how to get the HF Transformers model from DeepPavlov model:

from deeppavlov import build_model, configs
m = build_model(configs.classifiers.insults_kaggle_bert_torch, download=True)

m.pipe contains all elements of the pipeline:

[(([], ['x']),
  ['bert_features'],
  <deeppavlov.models.preprocessors.torch_transformers_preprocessor.TorchTransformersPreprocessor at 0x7f9b0414e550>),
 (([], ['bert_features']),
  ['y_pred_probas'],
  <deeppavlov.models.torch_bert.torch_transformers_classifier.TorchTransformersClassifierModel at 0x7f9ae5625ac8>),
 (([], ['y_pred_probas']),
  ['y_pred_ids'],
  <deeppavlov.models.classifiers.proba2labels.Proba2Labels at 0x7f9ae56221d0>),
 (([], ['y_pred_ids']),
  ['y_pred_labels'],
  <deeppavlov.core.data.simple_vocab.SimpleVocabulary at 0x7f9abddfe470>)]

So, you can get the TorchTransformersClassifierModel with

m.pipe[1][2]

and get the HF Transformers model from it:

hf_model = m.pipe[1][2].model

hf_model is a PyTorch nn.Module and you can use it as usually.