Views
No views yet
batch_size = 6
n_epochs = 2
max_seq_len = 384
learning_rate = 3e-5
lr_schedule = LinearWarmup
embeds_dropout_prob = 0.1
temperature = 5
distillation_loss_weight = 11# After running pip install haystack-ai "transformers[torch,sentencepiece]"
2
3from haystack import Document
4from haystack.components.readers import ExtractiveReader
5
6docs = [
7 Document(content="Python is a popular programming language"),
8 Document(content="python ist eine beliebte Programmiersprache"),
9]
10
11reader = ExtractiveReader(model="deepset/bert-medium-squad2-distilled")
12reader.warm_up()
13
14question = "What is a popular programming language?"
15result = reader.run(query=question, documents=docs)
16# {'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),...)]}1from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
2
3model_name = "deepset/bert-medium-squad2-distilled"
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)"exact": 68.6431398972458
"f1": 72.7637083790805timo.moeller [at] deepset.aijulian.risch [at] deepset.aimalte.pietsch [at] deepset.aimichel.bartels [at] deepset.ai
