pengzeli commited on
Commit
ccb8b71
·
verified ·
1 Parent(s): e2a2e9b

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,35 +1,5 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
  *.pt filter=lfs diff=lfs merge=lfs -text
23
  *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
 
2
  *.bin filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  *.pt filter=lfs diff=lfs merge=lfs -text
4
  *.pth filter=lfs diff=lfs merge=lfs -text
5
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
PREPARE_LOG.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ source_dir=/dgx1data/aii/tao/m327768/workdir/projects/concept_normalization/rereank/rl_outputs/rl_rerank_hit1_hit10only_hardx10_ng8/final
2
+ created_at=2026-03-18 10:26:58
3
+
4
+ files:
5
+ total 173M
6
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 177 Mar 18 10:26 PREPARE_LOG.txt
7
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 2.4K Mar 5 19:30 README_source.md
8
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 1.2K Mar 5 19:30 adapter_config.json
9
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 167M Mar 5 19:30 adapter_model.safetensors
10
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 4.1K Mar 5 19:30 chat_template.jinja
11
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 11M Mar 5 19:30 tokenizer.json
12
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 688 Mar 5 19:30 tokenizer_config.json
13
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 7.0K Mar 5 19:30 training_args.bin
README.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen3-8B
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - qwen
7
+ - qwen3
8
+ - lora
9
+ - peft
10
+ - biomedical-entity-linking
11
+ - clinical-nlp
12
+ - concept-normalization
13
+ - reranking
14
+ - candidate-ranking
15
+ - reasoning
16
+ - reinforcement-learning
17
+ license: other
18
+ ---
19
+
20
+ # Qwen3-8B-LoRA-ContextBioEL-Reranker-RL
21
+
22
+ This repository provides a LoRA adapter for Qwen3-8B for the reranker stage of a clinical biomedical entity linking pipeline.
23
+
24
+ This model reranks a top-10 candidate list using the rewritten term, marked note context, and candidate semantic tags, and outputs the best concept_id. It was further optimized with reinforcement learning (RL) for entity-linking-oriented reranking behavior.
25
+
26
+ ## Model type
27
+
28
+ - Base model: Qwen/Qwen3-8B
29
+ - Adapter type: LoRA
30
+ - Stage: Reranker
31
+ - Training: RL
32
+ - Task: Context-aware biomedical entity linking reranking
33
+
34
+ ## Intended use
35
+
36
+ Inputs:
37
+ - `rewritten_term`
38
+ - `context_marked`, where the target mention is explicitly enclosed by `<mention>...</mention>`
39
+ - `candidates`, a top-10 candidate list containing:
40
+ - `concept_id`
41
+ - `concept_name`
42
+ - `semantic_tag`
43
+
44
+ Output:
45
+ - exactly one selected `concept_id` in the `<answer>...</answer>` block
46
+
47
+ This model is intended for research use in biomedical entity linking pipelines.
48
+
49
+ ## Important decoding note
50
+
51
+ This adapter was trained with reasoning-style outputs.
52
+
53
+ Please:
54
+ - enable thinking
55
+ - do not use greedy decoding
56
+
57
+ Recommended decoding:
58
+ - `do_sample=True`
59
+ - non-greedy decoding such as temperature/top-p sampling
60
+ - parse the final prediction from the `<answer>...</answer>` span
61
+
62
+ ## Usage example
63
+
64
+ ```python
65
+ from transformers import AutoTokenizer, AutoModelForCausalLM
66
+ from peft import PeftModel
67
+ import torch
68
+ import json
69
+
70
+ base_model_path = "Qwen/Qwen3-8B"
71
+ adapter_path = "Tao-AI-Informatics/Qwen3-8B-LoRA-ContextBioEL-Reranker-RL"
72
+
73
+ tokenizer = AutoTokenizer.from_pretrained(base_model_path, trust_remote_code=True)
74
+ base_model = AutoModelForCausalLM.from_pretrained(
75
+ base_model_path,
76
+ torch_dtype=torch.bfloat16,
77
+ device_map="auto",
78
+ trust_remote_code=True,
79
+ )
80
+ model = PeftModel.from_pretrained(base_model, adapter_path)
81
+
82
+ cands_json = json.dumps([
83
+ {"concept_id": "22298006", "concept_name": "myocardial infarction", "semantic_tag": "disorder"},
84
+ {"concept_id": "57054005", "concept_name": "acute myocardial infarction", "semantic_tag": "disorder"}
85
+ ], indent=2)
86
+
87
+ messages = [
88
+ {
89
+ "role": "system",
90
+ "content": (
91
+ "You are a clinical concept normalization model that reranks a top-10 candidate list using context and semantic tags.\n\n"
92
+ "Inputs you will receive:\n"
93
+ "- rewritten_term\n"
94
+ "- context_marked with <mention>...</mention>\n"
95
+ "- candidates: top-10 items (concept_id, concept_name, semantic_tag)\n\n"
96
+ "Think before answer\n\n"
97
+ "Output ONLY:\n"
98
+ "<think>...</think>\n"
99
+ "<answer>...</answer>\n\n"
100
+ "In <think>, write a detailed reasoning with these parts:\n"
101
+ "1) Context interpretation: what the mention means in this note (section cues, negation, experiencer, temporality).\n"
102
+ "2) Type inference: what semantic type/tag is expected (and why other tags are wrong).\n"
103
+ "3) Candidate comparison: evaluate multiple candidates. Note over-specific vs too-general, added qualifiers, and tag alignment.\n"
104
+ "4) Decision: justify the final choice.\n\n"
105
+ "In <answer>, use exactly one of:\n"
106
+ "- <answer><concept_id></answer>\n"
107
+ ),
108
+ },
109
+ {
110
+ "role": "user",
111
+ "content": (
112
+ "Task: Choose the best concept_id from candidates.\n\n"
113
+ "rewritten_term:\nacute myocardial infarction\n\n"
114
+ "context_marked:\n"
115
+ "The patient was admitted for <mention>heart attack</mention> yesterday.\n\n"
116
+ f"candidates (top10; no scores):\n{cands_json}"
117
+ ),
118
+ },
119
+ ]
120
+
121
+ text = tokenizer.apply_chat_template(
122
+ messages,
123
+ tokenize=False,
124
+ add_generation_prompt=True,
125
+ )
126
+
127
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
128
+
129
+ with torch.no_grad():
130
+ outputs = model.generate(
131
+ **inputs,
132
+ max_new_tokens=512,
133
+ do_sample=True,
134
+ temperature=0.6,
135
+ top_p=0.95,
136
+ )
137
+
138
+ print(tokenizer.decode(outputs[0], skip_special_tokens=False))
139
+ ```
140
+
141
+ ## Notes
142
+
143
+ - This is a LoRA adapter, not a standalone full model.
144
+
145
+ - The adapter is designed for the rewriting stage, not retrieval by itself.
146
+
147
+ - In downstream pipelines, the rewritten term is typically passed to a retriever or reranker.
148
+
149
+ ## Limitations
150
+
151
+ - This model is intended for research use only.
152
+
153
+ - Performance may vary across ontologies, institutions, and note styles.
154
+
155
+ - The model should be evaluated carefully before any real-world deployment.
156
+
157
+ - The final normalized term should be extracted from the <answer>...</answer> block.
158
+
159
+ ## Citation
160
+
161
+ If you use this model, please cite the associated paper when available.
adapter_config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "/dgx1data/aii/tao/tools/models/Qwen/Qwen3-8B/models--Qwen--Qwen3-8B/snapshots/b968826d9c46dd6066d109eabc6255188de91218",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 32,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 16,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "o_proj",
33
+ "k_proj",
34
+ "down_proj",
35
+ "gate_proj",
36
+ "up_proj",
37
+ "v_proj",
38
+ "q_proj"
39
+ ],
40
+ "target_parameters": null,
41
+ "task_type": "CAUSAL_LM",
42
+ "trainable_token_indices": null,
43
+ "use_dora": false,
44
+ "use_qalora": false,
45
+ "use_rslora": false
46
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b976cb62df75e3b535abb71d227ec51fd257569467f49fcf1564bec9e9d3981
3
+ size 174655536
chat_template.jinja ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
+ {%- for message in messages[::-1] %}
19
+ {%- set index = (messages|length - 1) - loop.index0 %}
20
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
21
+ {%- set ns.multi_step_tool = false %}
22
+ {%- set ns.last_query_index = index %}
23
+ {%- endif %}
24
+ {%- endfor %}
25
+ {%- for message in messages %}
26
+ {%- if message.content is string %}
27
+ {%- set content = message.content %}
28
+ {%- else %}
29
+ {%- set content = '' %}
30
+ {%- endif %}
31
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
32
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
33
+ {%- elif message.role == "assistant" %}
34
+ {%- set reasoning_content = '' %}
35
+ {%- if message.reasoning_content is string %}
36
+ {%- set reasoning_content = message.reasoning_content %}
37
+ {%- else %}
38
+ {%- if '</think>' in content %}
39
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
40
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
41
+ {%- endif %}
42
+ {%- endif %}
43
+ {%- if loop.index0 > ns.last_query_index %}
44
+ {%- if loop.last or (not loop.last and reasoning_content) %}
45
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
46
+ {%- else %}
47
+ {{- '<|im_start|>' + message.role + '\n' + content }}
48
+ {%- endif %}
49
+ {%- else %}
50
+ {{- '<|im_start|>' + message.role + '\n' + content }}
51
+ {%- endif %}
52
+ {%- if message.tool_calls %}
53
+ {%- for tool_call in message.tool_calls %}
54
+ {%- if (loop.first and content) or (not loop.first) %}
55
+ {{- '\n' }}
56
+ {%- endif %}
57
+ {%- if tool_call.function %}
58
+ {%- set tool_call = tool_call.function %}
59
+ {%- endif %}
60
+ {{- '<tool_call>\n{"name": "' }}
61
+ {{- tool_call.name }}
62
+ {{- '", "arguments": ' }}
63
+ {%- if tool_call.arguments is string %}
64
+ {{- tool_call.arguments }}
65
+ {%- else %}
66
+ {{- tool_call.arguments | tojson }}
67
+ {%- endif %}
68
+ {{- '}\n</tool_call>' }}
69
+ {%- endfor %}
70
+ {%- endif %}
71
+ {{- '<|im_end|>\n' }}
72
+ {%- elif message.role == "tool" %}
73
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
74
+ {{- '<|im_start|>user' }}
75
+ {%- endif %}
76
+ {{- '\n<tool_response>\n' }}
77
+ {{- content }}
78
+ {{- '\n</tool_response>' }}
79
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
80
+ {{- '<|im_end|>\n' }}
81
+ {%- endif %}
82
+ {%- endif %}
83
+ {%- endfor %}
84
+ {%- if add_generation_prompt %}
85
+ {{- '<|im_start|>assistant\n' }}
86
+ {%- if enable_thinking is defined and enable_thinking is false %}
87
+ {{- '<think>\n\n</think>\n\n' }}
88
+ {%- endif %}
89
+ {%- endif %}
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
3
+ size 11422650
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": true,
24
+ "model_max_length": 2048,
25
+ "pad_token": "<|endoftext|>",
26
+ "padding_side": "left",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }