PetarKal commited on
Commit
8605b26
verified
1 Parent(s): 9547af5

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +153 -0
  2. chat_template_adapters.jinja +30 -0
README.md CHANGED
@@ -1,3 +1,156 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ base_model: arcee-ai/Trinity-Mini
4
+ library_name: peft
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - lora
8
+ - peft
9
+ - grpo
10
+ - reinforcement-learning
11
+ - biomedical
12
+ - relation-extraction
13
+ - drug-protein
14
+ - moe
15
+ language:
16
+ - en
17
  ---
18
+
19
+ <p align="center">
20
+ <img src="assets/logo.png" alt="Trinity-Mini-DrugProt-Think" width="350" />
21
+ </p>
22
+
23
+ <p align="center">
24
+ <strong>Trinity-Mini-DrugProt-Think</strong><br/>
25
+ RLVR (GRPO) + LoRA post-training on Arcee Trinity Mini for DrugProt relation classification.
26
+ </p>
27
+
28
+ <p align="center">
29
+ <a href="index.html">馃摑 <strong>Report</strong></a> &nbsp; | &nbsp;
30
+ <a href="https://medium.com/@jakimovski_bojan/9e1c1c430ce9"><img src="https://www.sysgroup.com/wp-content/uploads/2025/02/Amazon_Web_Services-Logo.wine_.png" height="20" style="vertical-align:middle;"/> <strong>AWS deployment guide</strong></a> &nbsp; | &nbsp;
31
+ <a href="https://github.com/LokaHQ/Trinity-Mini-DrugProt-Think" aria-label="GitHub"><svg viewBox="0 0 16 16" fill="currentColor" width="20" height="20" style="vertical-align:middle;"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg> <strong>GitHub</strong></a>
32
+ </p>
33
+
34
+
35
+ # Trinity-Mini-DrugProt-Think
36
+
37
+ A LoRA adapter fine-tuned on [Arcee Trinity Mini](https://huggingface.co/arcee-ai/Trinity-Mini) using GRPO (Group Relative Policy Optimization) for **drug-protein relation extraction** on the [DrugProt (BioCreative VII)](https://huggingface.co/datasets/OpenMed/drugprot-parquet) benchmark. The model classifies 13 types of drug-protein interactions from PubMed abstracts, producing structured pharmacological reasoning traces before giving its answer.
38
+
39
+ 馃搫 **Blog post:** [Post-Training an Open MoE to Extract Drug-Protein Relations](https://github.com/Shekswess/drugprotrelrl)
40
+ 馃捇 **Code & configs:** [github.com/Shekswess/drugprotrelrl](https://github.com/Shekswess/drugprotrelrl)
41
+
42
+ ## Model Details
43
+
44
+ | Property | Value |
45
+ |---|---|
46
+ | Base Model | [arcee-ai/Trinity-Mini](https://huggingface.co/arcee-ai/Trinity-Mini) |
47
+ | Architecture | Sparse MoE (26B total / 3B active) |
48
+ | Fine-tuning Method | LoRA (Low-Rank Adaptation) |
49
+ | Training Method | GRPO (Reinforcement Learning) |
50
+ | Training Data | [maziyar/OpenMed_DrugProt](https://huggingface.co/datasets/OpenMed/drugprot-parquet) |
51
+ | Task | Drug-protein relation extraction (13-way classification) |
52
+ | Trainable Parameters | LoRA rank=16, all projection layers |
53
+ | License | Apache 2.0 |
54
+
55
+ ## Training Configuration
56
+
57
+ | Parameter | Value |
58
+ |---|---|
59
+ | LoRA Alpha (伪) | 64 |
60
+ | LoRA Rank | 16 |
61
+ | Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj + experts |
62
+ | Learning Rate | 3e-6 |
63
+ | Batch Size | 128 |
64
+ | Rollouts per Example | 8 |
65
+ | Max Generation Tokens | 2048 |
66
+ | Temperature | 0.7 |
67
+
68
+ ## Quick Start
69
+
70
+ **Installation**
71
+
72
+ ```bash
73
+ pip install transformers peft torch accelerate
74
+ ```
75
+
76
+ **Usage**
77
+
78
+ ```python
79
+ from peft import PeftModel
80
+ from transformers import AutoModelForCausalLM, AutoTokenizer
81
+ import torch
82
+
83
+ base_model_id = "arcee-ai/Trinity-Mini"
84
+ adapter_id = "lokahq/Trinity-Mini-DrugProt-Think"
85
+
86
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id)
87
+ model = AutoModelForCausalLM.from_pretrained(
88
+ base_model_id,
89
+ torch_dtype=torch.bfloat16,
90
+ device_map="auto",
91
+ trust_remote_code=True
92
+ )
93
+ model = PeftModel.from_pretrained(model, adapter_id)
94
+
95
+ messages = [
96
+ {
97
+ "role": "user",
98
+ "content": (
99
+ "Abstract: [PASTE PUBMED ABSTRACT HERE]\n\n"
100
+ "Chemical entity: [DRUG NAME]\n"
101
+ "Protein entity: [PROTEIN NAME]\n\n"
102
+ "What is the relationship between the chemical and protein entities? "
103
+ "Choose from: A) INHIBITOR B) SUBSTRATE C) INDIRECT-DOWNREGULATOR "
104
+ "D) INDIRECT-UPREGULATOR E) AGONIST F) ANTAGONIST G) ACTIVATOR "
105
+ "H) PRODUCT-OF I) AGONIST-ACTIVATOR J) INDIRECT-UPREGULATOR "
106
+ "K) PART-OF L) SUBSTRATE_PRODUCT-OF M) NOT\n\n"
107
+ "Think step by step, then provide your answer in \\boxed{} format."
108
+ )
109
+ }
110
+ ]
111
+
112
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
113
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
114
+ outputs = model.generate(**inputs, max_new_tokens=2048, temperature=0.7, top_p=0.75)
115
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
116
+ ```
117
+
118
+ ## Training Progress
119
+
120
+ Training ran for ~130 steps on Prime Intellect infrastructure. Best accuracy reward reached ~0.83 during training.
121
+
122
+ | Step | Accuracy Reward | Composite Reward |
123
+ |---|---|---|
124
+ | 0 | ~0.68 | ~0.72 |
125
+ | 25 | ~0.71 | ~0.74 |
126
+ | 50 | ~0.74 | ~0.77 |
127
+ | 75 | ~0.77 | ~0.80 |
128
+ | 100 | ~0.80 | ~0.83 |
129
+
130
+ ## Limitations
131
+
132
+ - This is a LoRA adapter and requires the base model ([arcee-ai/Trinity-Mini](https://huggingface.co/arcee-ai/Trinity-Mini)) to run
133
+ - Evaluated on training-split held-out data; not yet benchmarked on the official DrugProt test set
134
+ - Optimized specifically for 13-way DrugProt classification; may not generalize to other biomedical RE tasks
135
+
136
+ ## Citation
137
+
138
+ ```bibtex
139
+ @article{jakimovski2026drugprotrl,
140
+ title = {Post-Training an Open MoE to Extract Drug-Protein Relations},
141
+ author = {Jakimovski, Bojan and Kalinovski, Petar},
142
+ year = {2026},
143
+ url = {https://github.com/Shekswess/drugprotrelrl}
144
+ }
145
+ ```
146
+
147
+ ## Acknowledgements
148
+
149
+ - [Arcee AI](https://www.arcee.ai/) for the Trinity Mini base model
150
+ - [Prime Intellect](https://www.primeintellect.ai/) for training infrastructure
151
+ - [maziyar](https://huggingface.co/maziyar) for the OpenMed DrugProt RL environment
152
+ - [Hugging Face](https://huggingface.co/) for the PEFT library
153
+
154
+ ## Authors
155
+
156
+ [Bojan Jakimovski](mailto:bojan.jakimovski@loka.com) 路 [Petar Kalinovski](mailto:petar.kalinovski@loka.com) 路 [Loka](https://loka.com)
chat_template_adapters.jinja ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You are an expert biomedical relation extraction assistant. Your task is to identify the type of interaction between a drug/chemical and a gene/protein in biomedical text.
2
+
3
+ For each question:
4
+ 1. First, wrap your detailed biomedical reasoning inside <think></think> tags
5
+ 2. Analyze the context around both entities to understand their relationship
6
+ 3. Consider the pharmacological and molecular mechanisms involved
7
+ 4. Then provide your final answer inside \boxed{} using exactly one letter (A-M)
8
+
9
+ The 13 DrugProt relation types are:
10
+ A. INDIRECT-DOWNREGULATOR - Chemical indirectly decreases protein activity/expression
11
+ B. INDIRECT-UPREGULATOR - Chemical indirectly increases protein activity/expression
12
+ C. DIRECT-REGULATOR - Chemical directly regulates protein (mechanism unspecified)
13
+ D. ACTIVATOR - Chemical activates the protein
14
+ E. INHIBITOR - Chemical inhibits the protein
15
+ F. AGONIST - Chemical acts as an agonist of the receptor/protein
16
+ G. AGONIST-ACTIVATOR - Chemical is both agonist and activator
17
+ H. AGONIST-INHIBITOR - Chemical is agonist but inhibits downstream effects
18
+ I. ANTAGONIST - Chemical acts as an antagonist of the receptor/protein
19
+ J. PRODUCT-OF - Chemical is a product of the enzyme
20
+ K. SUBSTRATE - Chemical is a substrate of the enzyme
21
+ L. SUBSTRATE_PRODUCT-OF - Chemical is both substrate and product
22
+ M. PART-OF - Chemical is part of the protein complex
23
+
24
+ Example format:
25
+ <think>
26
+ The text describes [chemical] and [protein]. Based on the context...
27
+ - The phrase "[relevant text]" indicates that...
28
+ - This suggests a [type] relationship because...
29
+ </think>
30
+ \boxed{A}