Views
No views yet
1batch_size = 40
2n_epochs = 10
3max_seq_len = 384
4doc_stride = 128
5learning_rate = 3e-51"exact_match": 79.44756554307116,
2"f1": 89.79318021513376,
3"test_samples": 23071from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
2
3model_name = "alon-albalak/xlm-roberta-base-xquad"
4
5# a) Get predictions
6nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
7QA_input = {
8 'question': 'Why is model conversion important?',
9 'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.'
10}
11res = nlp(QA_input)
12
13# b) Load model & tokenizer
14model = AutoModelForQuestionAnswering.from_pretrained(model_name)
15tokenizer = AutoTokenizer.from_pretrained(model_name)1from farm.modeling.adaptive_model import AdaptiveModel
2from farm.modeling.tokenization import Tokenizer
3from farm.infer import QAInferencer
4
5model_name = "alon-albalak/xlm-roberta-base-xquad"
6
7# a) Get predictions
8nlp = QAInferencer.load(model_name)
9QA_input = [{"questions": ["Why is model conversion important?"],
10 "text": "The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks."}]
11res = nlp.inference_from_dicts(dicts=QA_input, rest_api_schema=True)
12
13# b) Load model & tokenizer
14model = AdaptiveModel.convert_from_transformers(model_name, device="cpu", task_type="question_answering")
15tokenizer = Tokenizer.load(model_name)1reader = FARMReader(model_name_or_path="alon-albalak/xlm-roberta-base-xquad")
2# or
3reader = TransformersReader(model="alon-albalak/xlm-roberta-base-xquad",tokenizer="alon-albalak/xlm-roberta-base-xquad")