Views
No views yet
meta-llama/Meta-Llama-3-8B-Instruct specifically adapted for Named Entity Recognition (NER) in the biomedical domain.tner/bionlp2004 dataset. The entire training process was accelerated and memory-optimized using Unsloth.DNARNAproteincell_typecell_line1pip install "unsloth[kaggle-torch] @ git+[https://github.com/unslothai/unsloth.git](https://github.com/unslothai/unsloth.git)"
2pip install "trl>=0.8.6" "peft>=0.10.0" "accelerate>=0.28.0"1from unsloth import FastLanguageModel
2from transformers import pipeline
3import torch
4
5# Load the fine-tuned model from the Hub
6model, tokenizer = FastLanguageModel.from_pretrained(
7 model_name = "Arnic/llama-3-8b-bionlp-ner",
8 max_seq_length = 2048,
9 dtype = None,
10 load_in_4bit = True,
11)
12
13# Configure the model for inference
14FastLanguageModel.for_inference(model)
15
16# The Alpaca prompt template used during training
17alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
18
19### Instruction:
20{}
21
22### Input:
23{}
24
25### Response:
26{}"""
27
28# The instruction for the NER task
29instruction = "You are an expert in medical text analysis. Your task is to identify and extract specific biological entities from the given text. The entity types to extract are: DNA, RNA, protein, cell_type, and cell_line."
30
31# Your input text
32input_text = "Interactions between the N-terminal domains of p53 and the human papillomavirus E6 protein."
33
34# Format the prompt
35prompt = alpaca_prompt.format(instruction, input_text, "")
36
37# Use the text-generation pipeline
38fast_pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
39
40# Define terminators to stop generation cleanly
41terminators = [
42 tokenizer.eos_token_id,
43 tokenizer.convert_tokens_to_ids("<|eot_id|>")
44]
45
46# Get the model's response
47outputs = fast_pipe(
48 prompt,
49 max_new_tokens=128,
50 do_sample=False,
51 eos_token_id=terminators,
52)
53
54# Print the clean response
55print(outputs[0]['generated_text'].split("### Response:")[1].strip())
56# Expected output: [('protein', 'p53'), ('protein', 'human papillomavirus E6 protein')]
57