Alon Albalak commited on
Commit
309f315
1 Parent(s): 957cb6b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -1
README.md CHANGED
@@ -25,4 +25,54 @@ Evaluated on held-out test set from XQuAD
25
  "exact_match": 79.44756554307116,
26
  "f1": 89.79318021513376,
27
  "test_samples": 2307
28
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  "exact_match": 79.44756554307116,
26
  "f1": 89.79318021513376,
27
  "test_samples": 2307
28
+ ```
29
+
30
+ # Usage
31
+
32
+ ## In Transformers
33
+ ```python
34
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
35
+
36
+ model_name = "alon-albalak/xlm-roberta-base-xquad"
37
+
38
+ # a) Get predictions
39
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
40
+ QA_input = {
41
+ 'question': 'Why is model conversion important?',
42
+ 'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.'
43
+ }
44
+ res = nlp(QA_input)
45
+
46
+ # b) Load model & tokenizer
47
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
48
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
49
+ ```
50
+
51
+ ## In FARM
52
+ ```python
53
+ from farm.modeling.adaptive_model import AdaptiveModel
54
+ from farm.modeling.tokenization import Tokenizer
55
+ from farm.infer import QAInferencer
56
+
57
+ model_name = "alon-albalak/xlm-roberta-base-xquad"
58
+
59
+ # a) Get predictions
60
+ nlp = QAInferencer.load(model_name)
61
+ QA_input = [{"questions": ["Why is model conversion important?"],
62
+ "text": "The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks."}]
63
+ res = nlp.inference_from_dicts(dicts=QA_input, rest_api_schema=True)
64
+
65
+ # b) Load model & tokenizer
66
+ model = AdaptiveModel.convert_from_transformers(model_name, device="cpu", task_type="question_answering")
67
+ tokenizer = Tokenizer.load(model_name)
68
+ ```
69
+
70
+ ## In Haystack
71
+
72
+ ```python
73
+ reader = FARMReader(model_name_or_path="alon-albalak/xlm-roberta-base-xquad")
74
+ # or
75
+ reader = TransformersReader(model="alon-albalak/xlm-roberta-base-xquad",tokenizer="alon-albalak/xlm-roberta-base-xquad")
76
+ ```
77
+
78
+ Usage instructions for FARM and Haystack were adopted from https://huggingface.co/deepset/xlm-roberta-large-squad2