Views
No views yet
batch_size = 12
n_epochs = 4
base_LM_model = "deberta-v3-base"
max_seq_len = 512
learning_rate = 2e-5
lr_schedule = LinearWarmup
warmup_proportion = 0.2
doc_stride = 128
max_query_length = 641# 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/roberta-base-squad2")
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/roberta-base-squad2"
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)
