Downloads · 30 days
22
24% of all-time downloads
DNivalis/Llama-3.1-8B-Health-21Level-Complexity
Llama-3.1-8B-Health-21Level-Complexity is a text generation model from DNivalis. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
A fine-tuned 8B-parameter Llama 3.1 model that generates medical answers at precise complexity levels, using control codes ranging from <COMPLEXITY0 (very simple) to <COMPLEXITY100 (highly technical).
Downloads · 30 days
22
24% of all-time downloads
All-time downloads
93
Public
Repo size
2.2 GB
Likes
0
Public
Click a slice to open those files.
.safetensors2.2 GB · 99%
From the Hugging Face model README
A fine-tuned 8B-parameter Llama 3.1 model that generates medical answers at precise complexity levels, using control codes ranging from <COMPLEXITY_0> (very simple) to <COMPLEXITY_100> (highly technical).
meta-llama/Meta-Llama-3.1-8B-Instructunsloth/meta-llama-3.1-8b-instruct-bnb-4bit (4-bit, LoRA-ready)<COMPLEXITY_XX> tokenfrom transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch
# 1. Load tokenizer that contains the extra control tokens
tokenizer = AutoTokenizer.from_pretrained("DNivalis/Llama-3.1-8B-Health-21Level-Complexity")
# 2. Load base model (4-bit, ~7 GB VRAM)
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16)
base = AutoModelForCausalLM.from_pretrained(
"unsloth/meta-llama-3.1-8b-instruct-bnb-4bit",
quantization_config=bnb,
device_map="auto"
)
# 3. Resize tokenizer to include new tokens
base.resize_token_embeddings(len(tokenizer))
# 4. Load the LoRA adapter
model = PeftModel.from_pretrained(base, "DNivalis/Llama-3.1-8B-Health-21Level-Complexity")
# 5. Helper function
def ask(question, level=None):
prompt = f"<COMPLEXITY_{level}> {question}" if level else question
messages = [{"role": "user", "content": prompt}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7, pad_token_id=tokenizer.eos_token_id)
answer = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
return answer.strip()
# 6. Go!
print(ask("What is asthma?", level=10))
print(ask("What is asthma?", level=50))
print(ask("What is asthma?", level=90))
print(ask("What is asthma?")) # No complexity control
Trained on 184,843 question-answer pairs rewritten at 21 levels of complexity
Levels derived from a data-driven scoring formula based on 13 linguistic features
Control codes: <COMPLEXITY_0> through <COMPLEXITY_100>, every 5 points
Formula incorporates:
Multi-source QA from:
Each question paired with 5 rewritten answers for different education levels
All variants scored and categorized into 21 distinct complexity levels
meta-llama/Meta-Llama-3.1-8B-Instructunsloth/meta-llama-3.1-8b-instruct-bnb-4bit<COMPLEXITY_XX> tokens initialized semanticallyIf you use this model or the associated datasets, please cite:
...
Licensed under Apache 2.0.
For issues, feedback, or collaboration requests, open an issue on the model repository.