Enhancing Biomedical NER and RE with RAG-ICL and DFPO: Novel Approaches for Dual Learning Paradigms

Use with transformers

See the snippet below for usage with Transformers:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = 'liyinghong/DFPO-Gemma2'
tokenizer = AutoTokenizer.from_pretrained(mode_path, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(mode_path,
                                             torch_dtype=torch.bfloat16,
                                             device_map="auto")

def predict(user_input):
    messages = [
        {"role": "user", "content": f"{user_input}"},
        ]
    
    input_ids = tokenizer.apply_chat_template(
        messages,
        add_generation_prompt=True,
        return_tensors="pt"
    ).to(model.device)   

    terminators = [tokenizer.eos_token_id]
    
    with torch.no_grad():

        outputs = model.generate(
            input_ids,
            max_new_tokens=512,
            eos_token_id=terminators,
            do_sample=True,
            temperature=0.5,
            top_p=0.9,
        )
        response = outputs[0][input_ids.shape[-1]:]
        
    return tokenizer.decode(response, skip_special_tokens=True)

prompt = """Extract and list the names of all chemicals mentioned in the following text. Provide the output as a single Python list containing the chemicals names as strings. 
Do not output anything except for the extracted information. Do not add any clarifying information.\n\n"""
prompt += """Input: Naloxone reverses the antihypertensive effect of clonidine. In unanesthetized, spontaneously hypertensive rats the decrease in blood pressure and heart rate produced by intravenous clonidine, 5 to 20 micrograms/kg, was inhibited or reversed by nalozone, 0.2 to 2 mg/kg. The hypotensive effect of 100 mg/kg alpha-methyldopa was also partially reversed by naloxone. Naloxone alone did not affect either blood pressure or heart rate. In brain membranes from spontaneously hypertensive rats clonidine, 10(-8) to 10(-5) M, did not influence stereoselective binding of [3H]-naloxone (8 nM), and naloxone, 10(-8) to 10(-4) M, did not influence clonidine-suppressible binding of [3H]-dihydroergocryptine (1 nM). These findings indicate that in spontaneously hypertensive rats the effects of central alpha-adrenoceptor stimulation involve activation of opiate receptors. As naloxone and clonidine do not appear to interact with the same receptor site, the observed functional antagonism suggests the release of an endogenous opiate by clonidine or alpha-methyldopa and the possible role of the opiate in the central control of sympathetic tone.
Output:"""

predict(prompt)
Downloads last month
6
Safetensors
Model size
9.24B params
Tensor type
BF16
·
Inference Providers NEW
This model is not currently available via any of the supported third-party Inference Providers, and the model is not deployed on the HF Inference API.

Model tree for liyinghong/DFPO-Gemma2

Base model

google/gemma-2-9b
Finetuned
(125)
this model