CoolFace
Modelpublic

mkdiscovery/Pharma-DrugInteraction-Qwen-0.5B

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes
Model Card

๐Ÿ’Š Pharma-DrugInteraction-Qwen-0.5B

Pharmaceutical Drug-Interaction Learning Prototype

A small domain-specific language model prototype created by fine-tuning Qwen/Qwen2.5-0.5B-Instruct with LoRA (Low-Rank Adaptation) on a curated pharmaceutical drug-interaction dataset.

Version: v1.0 Base Model: Qwen/Qwen2.5-0.5B-Instruct Fine-Tuning: LoRA Model Size: 0.5B parameters Purpose: Educational / Research Status: Learning Prototype

Usage

python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch

BASE_MODEL = "Qwen/Qwen2.5-0.5B-Instruct"
ADAPTER = "mkdiscovery/Pharma-DrugInteraction-Qwen-0.5B"

device = "cuda" if torch.cuda.is_available() else "cpu"

print("Loading model...")

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)

model = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL,
    torch_dtype=torch.float16 if device == "cuda" else torch.float32,
    device_map="auto" if device == "cuda" else None,
)

model = PeftModel.from_pretrained(model, ADAPTER)
model.eval()

print("Model loaded!")
print("Ask questions below. Type 'exit' to quit.\n")


while True:

    question = input("You: ")

    if question.lower() in ["exit", "quit", "q"]:
        print("Bye!")
        break

    messages = [
        {
            "role": "user",
            "content": question
        }
    ]

    text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
    )

    inputs = tokenizer(
        text,
        return_tensors="pt"
    ).to(model.device)

    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=256,
            temperature=0.2,
            do_sample=True,
        )

    response = tokenizer.decode(
        outputs[0][inputs["input_ids"].shape[1]:],
        skip_special_tokens=True
    )

    print(f"Model: {response}\n")

๐Ÿš€ What is this?

This project explores how a small Large Language Model (LLM) can be adapted toward the pharmaceutical drug-interaction domain using parameter-efficient fine-tuning.

Instead of training an LLM from scratch, this project takes an existing instruction-tuned model:

text
Qwen/Qwen2.5-0.5B-Instruct

and trains a small set of additional LoRA parameters using pharmaceutical drug-interaction examples.

Architecture

text
                 Qwen 0.5B
                    โ”‚
                    โ”‚
                    โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚   LoRA Adapter   โ”‚
          โ”‚   Fine-Tuning    โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
        Pharma-DrugInteraction
               Qwen-0.5B
                   โ”‚
                   โ–ผ
          Drug Interaction
             Questions
                   โ”‚
                   โ–ผ
              Response

๐ŸŽฏ Project Goal

The goal of V1 was not to build a clinical-grade medical system.

The goal was to practically understand:

  • โ€”How LLMs work
  • โ€”How datasets are prepared for fine-tuning
  • โ€”How pharmaceutical data can be normalized
  • โ€”How different datasets can be combined
  • โ€”How conversational training data is generated
  • โ€”How LoRA fine-tuning works
  • โ€”How a fine-tuned model behaves compared with the original model
  • โ€”What limitations appear when using a very small model

This is primarily a hands-on AI/ML learning project.


๐Ÿง  Model

Base Model

Qwen/Qwen2.5-0.5B-Instruct

The base model provides the general language understanding and generation capabilities.

Fine-Tuning Method

LoRA โ€” Low-Rank Adaptation

Instead of updating all parameters of the Qwen model, LoRA adds trainable low-rank matrices to selected layers.

Conceptually:

text
Original Qwen Model
       โ”‚
       โ”œโ”€โ”€ Frozen Parameters
       โ”‚
       โ””โ”€โ”€ LoRA Parameters
                 โ”‚
                 โ–ผ
        Pharmaceutical Domain

This makes the training process significantly lighter than full-model fine-tuning.


๐Ÿ“Š Dataset

The training data was created from pharmaceutical/drug-interaction datasets.

The preparation pipeline included:

text
Raw Pharmaceutical Data
          โ”‚
          โ–ผ
Drug Name Normalization
          โ”‚
          โ–ผ
Drug Matching
          โ”‚
          โ–ผ
Interaction Records
          โ”‚
          โ–ผ
Conversational Training Examples
          โ”‚
          โ–ผ
train.jsonl

For this V1 prototype, the pharmaceutical drug selection was intentionally limited to a smaller subset because of available compute resources.

V1 scope

  • โ€”Top 100 drugs
  • โ€”13,534 matched interaction records
  • โ€”Multiple conversational question variations were generated for the interaction records
  • โ€”Final training file: train.jsonl

The smaller scope was intentional so the project could be trained and tested on available hardware.


๐Ÿงช Training Format

The training examples use a conversational format compatible with instruction-tuned models.

Example:

json
{
  "messages": [
    {
      "role": "user",
      "content": "Does Zolpidem Tartrate interact with Itraconazole?"
    },
    {
      "role": "assistant",
      "content": "Interaction: increase drug exposure.\n\nItraconazole increased the exposure of zolpidem..."
    }
  ]
}

Multiple question formulations were generated for interaction records to expose the model to different ways a user might ask about the same drug interaction.


โš™๏ธ Training Configuration

ParameterValue
Base modelQwen/Qwen2.5-0.5B-Instruct
Fine-tuningLoRA
LoRA rank (r)16
LoRA alpha32
LoRA dropout0.05
BiasNone
TaskCausal Language Modeling
Target modulesq_proj, k_proj, v_proj, o_proj
Epochs1
Batch size1
Gradient accumulation4
Learning rate2e-4
PrecisionFP32

๐Ÿ”ฌ Before vs After Fine-Tuning

One of the main objectives of this project was to compare the base model with the fine-tuned model.

Before Fine-Tuning

The original Qwen model could generate general pharmaceutical-looking responses, but it could also:

  • โ€”misunderstand drug names
  • โ€”confuse medications
  • โ€”generate unsupported explanations
  • โ€”produce generic responses

After Fine-Tuning

The model became more aligned with the structure and terminology of the drug-interaction training data.

It learned patterns such as:

text
User:
Does Drug A interact with Drug B?

Model:
Interaction: <interaction category>

<supporting pharmaceutical text>

However, the V1 model can still produce incorrect or mismatched evidence.

This is an important limitation of using fine-tuning alone for precise pharmaceutical knowledge retrieval.


โš ๏ธ Limitations

This model is a learning/research prototype.

It should not be considered a reliable medical information system.

Known limitations include:

  • โ€”Small model size: 0.5B parameters
  • โ€”Limited V1 drug coverage
  • โ€”Limited training compute
  • โ€”Possible hallucinations
  • โ€”Possible incorrect drug-pair associations
  • โ€”Fine-tuning does not guarantee exact factual retrieval
  • โ€”Training data may contain inconsistencies
  • โ€”No retrieval/database verification layer
  • โ€”No clinical validation
  • โ€”No medical professional verification of generated responses

The model should therefore not be used for diagnosis, prescribing, dosage decisions, or clinical decision-making.

Always verify drug-interaction information using authoritative pharmaceutical references and qualified healthcare professionals.


๐Ÿ’ป Quick Start

1. Install dependencies

bash
pip install torch transformers peft

Depending on the environment, compatible versions of the Hugging Face ecosystem may also be required.


2. Download the base model

The model is based on:

text
Qwen/Qwen2.5-0.5B-Instruct

The LoRA repository contains the adapter rather than a complete copy of the base model.


3. Load the LoRA adapter

The included inference.py loads:

text
Qwen/Qwen2.5-0.5B-Instruct
             +
     LoRA Adapter
             โ†“
Pharma-DrugInteraction-Qwen-0.5B

Run:

bash
python3 inference.py

๐Ÿง‘โ€๐Ÿ’ป Example

text
๐Ÿ’Š You: Does Zolpidem Tartrate interact with Itraconazole?

๐Ÿค– Assistant:

Interaction: increase drug exposure.

Itraconazole increased the exposure of zolpidem...

Type:

text
exit

to close the application.


๐Ÿ“ Repository Structure

text
Pharma-DrugInteraction-Qwen-0.5B/
โ”‚
โ”œโ”€โ”€ adapter_config.json
โ”œโ”€โ”€ adapter_model.safetensors
โ”‚
โ”œโ”€โ”€ tokenizer_config.json
โ”œโ”€โ”€ tokenizer.json
โ”œโ”€โ”€ special_tokens_map.json
โ”œโ”€โ”€ added_tokens.json
โ”œโ”€โ”€ merges.txt
โ”œโ”€โ”€ vocab.json
โ”‚
โ”œโ”€โ”€ inference.py
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ LICENSE

Important

adapter_model.safetensors contains the trained LoRA adapter weights.

The complete Qwen base model is not duplicated in this repository.


๐Ÿ”ง How the Model Works

At inference time:

text
User Question
      โ”‚
      โ–ผ
Qwen Tokenizer
      โ”‚
      โ–ผ
Qwen 0.5B Base Model
      โ”‚
      +
      โ”‚
LoRA Adapter
      โ”‚
      โ–ผ
Generated Response

The LoRA adapter modifies the behavior of the base model toward patterns learned from the pharmaceutical training examples.


๐Ÿงช Why LoRA?

Full fine-tuning would require updating the entire model.

LoRA instead trains a relatively small number of additional parameters while keeping the original model largely frozen.

This makes it particularly useful for:

  • โ€”learning experiments
  • โ€”smaller compute environments
  • โ€”domain adaptation
  • โ€”rapid prototyping
  • โ€”parameter-efficient fine-tuning

๐Ÿ›ฃ๏ธ Future Work

Possible future versions could explore:

V2 โ€” Larger Dataset

Increase drug coverage beyond the V1 top-100 selection.

V3 โ€” Retrieval-Augmented Generation

Introduce a retrieval layer so that the model can retrieve the exact drug-interaction record instead of relying entirely on information encoded during fine-tuning.

text
Question
   โ†“
Drug Pair Retrieval
   โ†“
Relevant Evidence
   โ†“
LLM
   โ†“
Answer

V4 โ€” Evaluation

Build a dedicated evaluation dataset and measure:

  • โ€”Exact-match accuracy
  • โ€”Interaction-category accuracy
  • โ€”Drug-pair coverage
  • โ€”Hallucination rate
  • โ€”Seen vs unseen pair performance

๐Ÿ“Œ Model Card Summary

PropertyDetails
ProjectPharma Drug Interaction
Versionv1.0
Base LLMQwen/Qwen2.5-0.5B-Instruct
Parameters0.5B base model
Fine-tuningLoRA
DomainPharmaceutical drug interactions
V1 Drug ScopeTop 100
Interaction Records13,534
Training FormatConversational JSONL
Primary PurposeEducational / Research
Clinical UseโŒ Not recommended

๐Ÿ™ Acknowledgements

This project was created as a hands-on exploration of LLMs, pharmaceutical datasets, data preprocessing, and parameter-efficient fine-tuning.

The project builds upon the capabilities of:

  • โ€”Qwen
  • โ€”Hugging Face Transformers
  • โ€”Hugging Face Datasets
  • โ€”PEFT / LoRA

โš–๏ธ Disclaimer

Educational and research purposes only.

This model is not a medical device and has not been clinically validated.

Generated responses may be inaccurate, incomplete, or misleading. Do not use this model as a substitute for professional medical advice, prescribing information, official drug labels, or validated drug-interaction databases.

For real-world medical decisions, consult qualified healthcare professionals and authoritative pharmaceutical references.

๐Ÿ‘ฅ Contributors

This project was a collaborative effort combining pharmaceutical research and AI engineering.

Ayushi Nair

Concept, Research, Data Collection & Validation

  • โ€”Led the project concept and research direction
  • โ€”Collected and curated pharmaceutical datasets
  • โ€”Validated data quality and interaction records

LinkedIn: <https://www.linkedin.com/in/ayushi--nair/>

Midhun Krishna

Engineering & Infrastructure

  • โ€”Dataset preprocessing and preparation
  • โ€”LoRA fine-tuning pipeline
  • โ€”Model training and inference
  • โ€”Hugging Face model packaging and deployment
  • โ€”Repository development and documentation

LinkedIn: <https://www.linkedin.com/in/midhunvellarakkad/>