Views
No views yet
1from vllm import LLM, SamplingParams
2from vllm.lora.request import LoRARequest
3
4# Initialize vLLM Engine with LoRA support
5model_path = "unsloth/meta-llama-3.1-8b-instruct-bnb-4bit"
6lora_path = "sag-uniroma2/llama3.1_adapter_biorag_snippet_extraction"
7lora_adapter_id = 1
8
9llm = LLM(
10 model=model_path,
11 enable_lora=True,
12 max_loras=1,
13 max_lora_rank=64,
14 gpu_memory_utilization=0.85,
15 trust_remote_code=True,
16 disable_custom_all_reduce=True,
17 enforce_eager=True
18)
19
20# Setup LoRA request
21lora_request_obj = LoRARequest(
22 lora_name=str(lora_adapter_id),
23 lora_int_id=lora_adapter_id,
24 lora_path=lora_path
25)
26
27# Define sampling parameters
28sampling_params = SamplingParams(temperature=0.0, max_tokens=256)
29
30# Define instruction
31instruction = """You are an expert biomedical researcher skilled in extracting relevant information from scientific literature.
32Your task is to identify and extract key snippets from a given PubMed abstract or title that provide useful information to answer a specific biomedical question.
33
34Instructions:
35- Understand the question: Carefully analyze the biomedical question to grasp its key concepts, entities, and relationships.
36- Analyze the document: Read the provided title or abstract carefully, identifying sentences or phrases that contain relevant information.
37- Extract the snippet: If a portion of the text is relevant, extract it exactly as it appears in the original text and enclose it within the tags [BS] and [ES].
38- Handle irrelevant cases: If the document does not contain any relevant information, return only [BS] [ES] with no content inside.
39- Be precise: Ensure that extracted snippets are complete, self-contained, and directly relevant, without modifying or adding words."""
40
41# Prepare input
42question = "YOUR_BIOMEDICAL_QUESTION_HERE"
43document_text = "PUBMED_ABSTRACTS_HERE"
44
45prompt = f"{instruction}\n\n# Question: {question}\n# Abstract/Title: {document_text}\n# Snippets:"
46
47# Generate snippet extraction
48outputs = llm.generate(
49 [prompt],
50 sampling_params,
51 lora_request=lora_request_obj
52)
53
54# Parse and extract snippet
55generated_text = outputs[0].outputs[0].text
56snippet = generated_text.strip()
57
58# Remove EOS tokens
59common_eos_tokens = ["<|eot_id|>", "</s>", "<|endoftext|>"]
60for eos in common_eos_tokens:
61 if snippet.endswith(eos):
62 snippet = snippet[:-len(eos)].strip()
63
64# Extract content between tags
65import re
66extracted_snippets = re.findall(r'\[BS\](.*?)\[ES\]', snippet, re.DOTALL)
67for snippet_content in extracted_snippets:
68 clean_snippet = snippet_content.strip()
69 if clean_snippet:
70 print(f"Extracted snippet: {clean_snippet}")1@InProceedings{10.1007/978-3-032-21324-2_31,
2author="Borazio, Federico
3and Labbate, Francesco
4and Croce, Danilo
5and Basili, Roberto",
6editor="Campos, Ricardo
7and Jatowt, Adam
8and Lan, Yanyan
9and Aliannejadi, Mohammad
10and Bauer, Christine
11and MacAvaney, Sean
12and Anand, Avishek
13and Ren, Zhaochun
14and Verberne, Suzan
15and Bai, Nan
16and Mansoury, Masoud",
17title="Integrating AI and IR Paradigms for Sustainable and Trustworthy Accurate Access to Large Scale Biomedical Information",
18booktitle="Advances in Information Retrieval",
19year="2026",
20publisher="Springer Nature Switzerland",
21address="Cham",
22pages="398--412",
23isbn="978-3-032-21324-2"
24}1@inproceedings{unitor,
2 title={{UniTor at BioASQ 2025: Modular Biomedical QA with Synthetic Snippets and Multiple Task Answer Generation}},
3 author={Borazio, Federico and Shcherbakov, Andriy and Croce, Danilo and Basili, Roberto},
4 year=2025,
5 booktitle={CLEF 2025 Working Notes},
6 editor= {Faggioli, Guglielmo and Ferro, Nicola and Rosso, Paolo and Spina, Damiano}
7}