cdqa-suite / cdQA

⛔ [NOT MAINTAINED] An End-To-End Closed Domain Question Answering System.
https://cdqa-suite.github.io/cdQA-website/
Apache License 2.0
614 stars 191 forks source link

Is it possible to convert other bert model in pytorch form or tensorflow form to joblib for cdQA using? #324

Open txz233 opened 4 years ago

txz233 commented 4 years ago

Is it possible to convert other bert model in pytorch form or tensorflow form to joblib for cdQA using?

andrelmfarias commented 4 years ago

Do you have a pytorch version of a BertForQuestionAnswering model (HuggingFace's module version)?

If you have one, yes there is a way to do it, you would just need to do the folowing:

# Let's call your pytorch model Bert for QA custom_qa_model
from cdqa.reader import BertQA

reader = BertQA()
reader.model = custom_qa_model

# You need to send the model to CPU in order to save in the joblib format
reader.model.to('cpu')
reader.device = torch.device('cpu')

# Save it in the joblib format
import joblib
import os

joblib.dump(reader, os.path.join("path_to_directory", 'custom_qa_bert.joblib'))
txz233 commented 4 years ago

Thank you for your comment! @andrelmfarias ! But I don't really sure if my model is in HuggingFace's module version. Can you provide me more details about 'HuggingFace's module version'?

andrelmfarias commented 4 years ago

Your model should be an instance of the class BertForQuestionAnswering, a class provided in HuggingFace's transformers library. It is a subclass of torch.nn.module, i.e. it's a PyTorch model class.

ZhiliWang commented 4 years ago

Do you have a pytorch version of a BertForQuestionAnswering model (HuggingFace's module version)?

If you have one, yes there is a way to do it, you would just need to do the folowing:

# Let's call your pytorch model Bert for QA custom_qa_model
from cdqa.reader import BertQA

reader = BertQA()
reader.model = custom_qa_model

# You need to send the model to CPU in order to save in the joblib format
reader.model.to('cpu')
reader.device = torch.device('cpu')

# Save it in the joblib format
import joblib
import os

joblib.dump(reader, os.path.join("path_to_directory", 'custom_qa_bert.joblib'))

Dear Andre,

Is there a way to directly convert a customized model posted in the Huggingface community? Similar to one of these: https://huggingface.co/mrm8488/t5-base-finetuned-squadv2

kriskott commented 4 years ago

Hi, I've tried to follow the steps but it give me error that my custom_qa_model is not defined.

What exactly do I have to assign to retriever.model?

VenkatGudala commented 4 years ago

@bs317

Instantiate a custom model by 1) from transformers import AutoTokenizer, AutoModelForQuestionAnswering 2) tokenizer = AutoTokenizer.from_pretrained("clagator/biobert_squad2_cased") 3) model = AutoModelForQuestionAnswering.from_pretrained("clagator/biobert_squad2_cased") Now this 'model' is your custome_qa_model and follow the rest as described by @andrelmfarias

VenkatGudala commented 4 years ago

@andrelmfarias Dear Andre,

Shall I modify and cdQA code to my needs?

kriskott commented 4 years ago

@bs317

Instantiate a custom model by 1) from transformers import AutoTokenizer, AutoModelForQuestionAnswering 2) tokenizer = AutoTokenizer.from_pretrained("clagator/biobert_squad2_cased") 3) model = AutoModelForQuestionAnswering.from_pretrained("clagator/biobert_squad2_cased") Now this 'model' is your custome_qa_model and follow the rest as described by @andrelmfarias

but the model is supposed to be my pytorch_model.bin file, I don't want to use the pre trained clagator/biobert_squad2_cased model. So I need to find a way to assign to model my pytorch_model.bin file.

Ashwith-mmtxt commented 3 years ago

@bs317

Instantiate a custom model by 1) from transformers import AutoTokenizer, AutoModelForQuestionAnswering 2) tokenizer = AutoTokenizer.from_pretrained("clagator/biobert_squad2_cased") 3) model = AutoModelForQuestionAnswering.from_pretrained("clagator/biobert_squad2_cased") Now this 'model' is your custome_qa_model and follow the rest as described by @andrelmfarias

but the model is supposed to be my pytorch_model.bin file, I don't want to use the pre trained clagator/biobert_squad2_cased model. So I need to find a way to assign to model my pytorch_model.bin file.

@bs317 Did' you find a solution for what you are looking for?

muhammadhaseebashraf commented 2 years ago

@andrelmfarias Can T5 models (like the model mentioned by @ZhiliWang ) be used with cdQA or do we need to write complete custom pipeline for those?