README.md
| 1 | --- |
| 2 | language: multilingual |
| 3 | license: cc-by-4.0 |
| 4 | tags: |
| 5 | - question-answering |
| 6 | datasets: |
| 7 | - squad_v2 |
| 8 | model-index: |
| 9 | - name: deepset/xlm-roberta-large-squad2 |
| 10 | results: |
| 11 | - task: |
| 12 | type: question-answering |
| 13 | name: Question Answering |
| 14 | dataset: |
| 15 | name: squad_v2 |
| 16 | type: squad_v2 |
| 17 | config: squad_v2 |
| 18 | split: validation |
| 19 | metrics: |
| 20 | - type: exact_match |
| 21 | value: 81.8281 |
| 22 | name: Exact Match |
| 23 | verified: true |
| 24 | verifyToken: eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJoYXNoIjoiNzVhZDE2NTg5NmUwOWRkMmI2MGUxYjFlZjIzNmMyNDQ2MDY2MDNhYzE0ZjY5YTkyY2U4ODc3ODFiZjQxZWQ2YSIsInZlcnNpb24iOjF9.f_rN3WPMAdv-OBPz0T7N7lOxYz9f1nEr_P-vwKhi3jNdRKp_JTy18MYR9eyJM2riKHC6_ge-8XwfyrUf51DSDA |
| 25 | - type: f1 |
| 26 | value: 84.8886 |
| 27 | name: F1 |
| 28 | verified: true |
| 29 | verifyToken: eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJoYXNoIjoiZGE5MWJmZGUxMGMwNWFhYzVhZjQwZGEwOWQ4N2Q2Yjg5NzdjNDFiNDhiYTQ1Y2E5ZWJkOTFhYmI1Y2Q2ZGYwOCIsInZlcnNpb24iOjF9.TIdH-tOx3kEMDs5wK1r6iwZqqSjNGlBrpawrsE917j1F3UFJVnQ7wJwaj0OIgmC4iw8OQeLZL56ucBcLApa-AQ |
| 30 | --- |
| 31 | |
| 32 | # Multilingual XLM-RoBERTa large for Extractive QA on various languages |
| 33 | |
| 34 | ## Overview |
| 35 | **Language model:** xlm-roberta-large |
| 36 | **Language:** Multilingual |
| 37 | **Downstream-task:** Extractive QA |
| 38 | **Training data:** SQuAD 2.0 |
| 39 | **Eval data:** SQuAD dev set - German MLQA - German XQuAD |
| 40 | **Training run:** [MLFlow link](https://public-mlflow.deepset.ai/#/experiments/124/runs/3a540e3f3ecf4dd98eae8fc6d457ff20) |
| 41 | **Code:** See [an example extractive QA pipeline built with Haystack](https://haystack.deepset.ai/tutorials/34_extractive_qa_pipeline) |
| 42 | **Infrastructure**: 4x Tesla v100 |
| 43 | |
| 44 | ## Hyperparameters |
| 45 | |
| 46 | ``` |
| 47 | batch_size = 32 |
| 48 | n_epochs = 3 |
| 49 | base_LM_model = "xlm-roberta-large" |
| 50 | max_seq_len = 256 |
| 51 | learning_rate = 1e-5 |
| 52 | lr_schedule = LinearWarmup |
| 53 | warmup_proportion = 0.2 |
| 54 | doc_stride=128 |
| 55 | max_query_length=64 |
| 56 | ``` |
| 57 | |
| 58 | ## Usage |
| 59 | |
| 60 | ### In Haystack |
| 61 | Haystack is an AI orchestration framework to build customizable, production-ready LLM applications. You can use this model in Haystack to do extractive question answering on documents. |
| 62 | To load and run the model with [Haystack](https://github.com/deepset-ai/haystack/): |
| 63 | ```python |
| 64 | # After running pip install haystack-ai "transformers[torch,sentencepiece]" |
| 65 | |
| 66 | from haystack import Document |
| 67 | from haystack.components.readers import ExtractiveReader |
| 68 | |
| 69 | docs = [ |
| 70 | Document(content="Python is a popular programming language"), |
| 71 | Document(content="python ist eine beliebte Programmiersprache"), |
| 72 | ] |
| 73 | |
| 74 | reader = ExtractiveReader(model="deepset/xlm-roberta-large-squad2") |
| 75 | reader.warm_up() |
| 76 | |
| 77 | question = "What is a popular programming language?" |
| 78 | result = reader.run(query=question, documents=docs) |
| 79 | # {'answers': [ExtractedAnswer(query='What is a popular programming language?', score=0.5740374326705933, data='python', document=Document(id=..., content: '...'), context=None, document_offset=ExtractedAnswer.Span(start=0, end=6),...)]} |
| 80 | ``` |
| 81 | For a complete example with an extractive question answering pipeline that scales over many documents, check out the [corresponding Haystack tutorial](https://haystack.deepset.ai/tutorials/34_extractive_qa_pipeline). |
| 82 | |
| 83 | ### In Transformers |
| 84 | ```python |
| 85 | from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline |
| 86 | |
| 87 | model_name = "deepset/xlm-roberta-large-squad2" |
| 88 | |
| 89 | # a) Get predictions |
| 90 | nlp = pipeline('question-answering', model=model_name, tokenizer=model_name) |
| 91 | QA_input = { |
| 92 | 'question': 'Why is model conversion important?', |
| 93 | 'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.' |
| 94 | } |
| 95 | res = nlp(QA_input) |
| 96 | |
| 97 | # b) Load model & tokenizer |
| 98 | model = AutoModelForQuestionAnswering.from_pretrained(model_name) |
| 99 | tokenizer = AutoTokenizer.from_pretrained(model_name) |
| 100 | ``` |
| 101 | |
| 102 | ## Performance |
| 103 | Evaluated on the SQuAD 2.0 English dev set with the [official eval script](https://worksheets.codalab.org/rest/bundles/0x6b567e1cf2e041ec80d7098f031c5c9e/contents/blob/). |
| 104 | ``` |
| 105 | "exact": 79.45759285774446, |
| 106 | "f1": 83.79259828925511, |
| 107 | "total": 11873, |
| 108 | "HasAns_exact": 71.96356275303644, |
| 109 | "HasAns_f1": 80.6460053117963, |
| 110 | "HasAns_total": 5928, |
| 111 | "NoAns_exact": 86.93019343986543, |
| 112 | "NoAns_f1": 86.93019343986543, |
| 113 | "NoAns_total": 5945 |
| 114 | ``` |
| 115 | |
| 116 | Evaluated on German [MLQA: test-context-de-question-de.json](https://github.com/facebookresearch/MLQA) |
| 117 | ``` |
| 118 | "exact": 49.34691166703564, |
| 119 | "f1": 66.15582561674236, |
| 120 | "total": 4517, |
| 121 | ``` |
| 122 | |
| 123 | Evaluated on German [XQuAD: xquad.de.json](https://github.com/deepmind/xquad) |
| 124 | ``` |
| 125 | "exact": 61.51260504201681, |
| 126 | "f1": 78.80206098332569, |
| 127 | "total": 1190, |
| 128 | ``` |
| 129 | |
| 130 | ## Usage |
| 131 | |
| 132 | ### In Haystack |
| 133 | For doing QA at scale (i.e. many docs instead of single paragraph), you can load the model also in [haystack](https://github.com/deepset-ai/haystack/): |
| 134 | ```python |
| 135 | reader = FARMReader(model_name_or_path="deepset/xlm-roberta-large-squad2") |
| 136 | # or |
| 137 | reader = TransformersReader(model="deepset/xlm-roberta-large-squad2",tokenizer="deepset/xlm-roberta-large-squad2") |
| 138 | ``` |
| 139 | |
| 140 | ### In Transformers |
| 141 | ```python |
| 142 | from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline |
| 143 | |
| 144 | model_name = "deepset/xlm-roberta-large-squad2" |
| 145 | |
| 146 | # a) Get predictions |
| 147 | nlp = pipeline('question-answering', model=model_name, tokenizer=model_name) |
| 148 | QA_input = { |
| 149 | 'question': 'Why is model conversion important?', |
| 150 | 'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.' |
| 151 | } |
| 152 | res = nlp(QA_input) |
| 153 | |
| 154 | # b) Load model & tokenizer |
| 155 | model = AutoModelForQuestionAnswering.from_pretrained(model_name) |
| 156 | tokenizer = AutoTokenizer.from_pretrained(model_name) |
| 157 | ``` |
| 158 | |
| 159 | ## Authors |
| 160 | **Branden Chan:** branden.chan@deepset.ai |
| 161 | **Timo Möller:** timo.moeller@deepset.ai |
| 162 | **Malte Pietsch:** malte.pietsch@deepset.ai |
| 163 | **Tanay Soni:** tanay.soni@deepset.ai |
| 164 | |
| 165 | ## About us |
| 166 | |
| 167 | <div class="grid lg:grid-cols-2 gap-x-4 gap-y-3"> |
| 168 | <div class="w-full h-40 object-cover mb-2 rounded-lg flex items-center justify-center"> |
| 169 | <img alt="" src="https://raw.githubusercontent.com/deepset-ai/.github/main/deepset-logo-colored.png" class="w-40"/> |
| 170 | </div> |
| 171 | <div class="w-full h-40 object-cover mb-2 rounded-lg flex items-center justify-center"> |
| 172 | <img alt="" src="https://raw.githubusercontent.com/deepset-ai/.github/main/haystack-logo-colored.png" class="w-40"/> |
| 173 | </div> |
| 174 | </div> |
| 175 | |
| 176 | [deepset](http://deepset.ai/) is the company behind the production-ready open-source AI framework [Haystack](https://haystack.deepset.ai/). |
| 177 | |
| 178 | Some of our other work: |
| 179 | - [Distilled roberta-base-squad2 (aka "tinyroberta-squad2")](https://huggingface.co/deepset/tinyroberta-squad2) |
| 180 | - [German BERT](https://deepset.ai/german-bert), [GermanQuAD and GermanDPR](https://deepset.ai/germanquad), [German embedding model](https://huggingface.co/mixedbread-ai/deepset-mxbai-embed-de-large-v1) |
| 181 | - [deepset Cloud](https://www.deepset.ai/deepset-cloud-product), [deepset Studio](https://www.deepset.ai/deepset-studio) |
| 182 | |
| 183 | ## Get in touch and join the Haystack community |
| 184 | |
| 185 | <p>For more info on Haystack, visit our <strong><a href="https://github.com/deepset-ai/haystack">GitHub</a></strong> repo and <strong><a href="https://docs.haystack.deepset.ai">Documentation</a></strong>. |
| 186 | |
| 187 | We also have a <strong><a class="h-7" href="https://haystack.deepset.ai/community">Discord community open to everyone!</a></strong></p> |
| 188 | |
| 189 | [Twitter](https://twitter.com/Haystack_AI) | [LinkedIn](https://www.linkedin.com/company/deepset-ai/) | [Discord](https://haystack.deepset.ai/community) | [GitHub Discussions](https://github.com/deepset-ai/haystack/discussions) | [Website](https://haystack.deepset.ai/) | [YouTube](https://www.youtube.com/@deepset_ai) |
| 190 | |
| 191 | By the way: [we're hiring!](http://www.deepset.ai/jobs) |