pengzeli commited on
Commit
f81924c
·
verified ·
1 Parent(s): f749545

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/outputs/rerank_sft/final
2
+ created_at=2026-03-18 10:26:57
3
+
4
+ files:
5
+ total 173M
6
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 140 Mar 18 10:26 PREPARE_LOG.txt
7
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 5.3K Mar 2 10:30 README_source.md
8
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 1.2K Mar 2 10:30 adapter_config.json
9
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 167M Mar 2 10:30 adapter_model.safetensors
10
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 4.1K Mar 2 10:30 chat_template.jinja
11
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 11M Mar 2 10:30 tokenizer.json
12
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 664 Mar 2 10:30 tokenizer_config.json
13
+ -rw-r--r-- 1 m327768 acl_dgx1_tao 5.6K Mar 2 10:30 training_args.bin
README.md ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ license: other
17
+ ---
18
+
19
+ # Qwen3-8B-LoRA-ContextBioEL-Reranker-SFT
20
+
21
+ This repository provides a LoRA adapter for Qwen3-8B for the reranker stage of a clinical biomedical entity linking pipeline.
22
+
23
+ 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 trained with supervised fine-tuning (SFT).
24
+
25
+ ## Model type
26
+
27
+ - Base model: Qwen/Qwen3-8B
28
+ - Adapter type: LoRA
29
+ - Stage: Reranker
30
+ - Training: SFT
31
+ - Task: Context-aware biomedical entity linking reranking
32
+
33
+ ## Intended use
34
+
35
+ Inputs:
36
+ - `rewritten_term`
37
+ - `context_marked`, where the target mention is explicitly enclosed by `<mention>...</mention>`
38
+ - `candidates`, a top-10 candidate list containing:
39
+ - `concept_id`
40
+ - `concept_name`
41
+ - `semantic_tag`
42
+
43
+ Output:
44
+ - exactly one selected `concept_id` in the `<answer>...</answer>` block
45
+
46
+ This model is intended for research use in biomedical entity linking pipelines.
47
+
48
+ ## Important decoding note
49
+
50
+ This adapter was trained with reasoning-style outputs.
51
+
52
+ Please:
53
+ - enable thinking
54
+ - do not use greedy decoding
55
+
56
+ Recommended decoding:
57
+ - `do_sample=True`
58
+ - non-greedy decoding such as temperature/top-p sampling
59
+ - parse the final prediction from the `<answer>...</answer>` span
60
+
61
+ ## Usage example
62
+
63
+ ```python
64
+ from transformers import AutoTokenizer, AutoModelForCausalLM
65
+ from peft import PeftModel
66
+ import torch
67
+ import json
68
+
69
+ base_model_path = "Qwen/Qwen3-8B"
70
+ adapter_path = "Tao-AI-Informatics/Qwen3-8B-LoRA-ContextBioEL-Reranker-SFT"
71
+
72
+ tokenizer = AutoTokenizer.from_pretrained(base_model_path, trust_remote_code=True)
73
+ base_model = AutoModelForCausalLM.from_pretrained(
74
+ base_model_path,
75
+ torch_dtype=torch.bfloat16,
76
+ device_map="auto",
77
+ trust_remote_code=True,
78
+ )
79
+ model = PeftModel.from_pretrained(base_model, adapter_path)
80
+
81
+ cands_json = json.dumps([
82
+ {"concept_id": "22298006", "concept_name": "myocardial infarction", "semantic_tag": "disorder"},
83
+ {"concept_id": "57054005", "concept_name": "acute myocardial infarction", "semantic_tag": "disorder"}
84
+ ], indent=2)
85
+
86
+ messages = [
87
+ {
88
+ "role": "system",
89
+ "content": (
90
+ "You are a clinical concept normalization model that reranks a top-10 candidate list using context and semantic tags.\n\n"
91
+ "Inputs you will receive:\n"
92
+ "- rewritten_term\n"
93
+ "- context_marked with <mention>...</mention>\n"
94
+ "- candidates: top-10 items (concept_id, concept_name, semantic_tag)\n\n"
95
+ "Think before answer\n\n"
96
+ "Output ONLY:\n"
97
+ "<think>...</think>\n"
98
+ "<answer>...</answer>\n\n"
99
+ "In <think>, write a detailed reasoning with these parts:\n"
100
+ "1) Context interpretation: what the mention means in this note (section cues, negation, experiencer, temporality).\n"
101
+ "2) Type inference: what semantic type/tag is expected (and why other tags are wrong).\n"
102
+ "3) Candidate comparison: evaluate multiple candidates. Note over-specific vs too-general, added qualifiers, and tag alignment.\n"
103
+ "4) Decision: justify the final choice.\n\n"
104
+ "In <answer>, use exactly one of:\n"
105
+ "- <answer><concept_id></answer>\n"
106
+ ),
107
+ },
108
+ {
109
+ "role": "user",
110
+ "content": (
111
+ "Task: Choose the best concept_id from candidates.\n\n"
112
+ "rewritten_term:\nacute myocardial infarction\n\n"
113
+ "context_marked:\n"
114
+ "The patient was admitted for <mention>heart attack</mention> yesterday.\n\n"
115
+ f"candidates (top10; no scores):\n{cands_json}"
116
+ ),
117
+ },
118
+ ]
119
+
120
+ text = tokenizer.apply_chat_template(
121
+ messages,
122
+ tokenize=False,
123
+ add_generation_prompt=True,
124
+ )
125
+
126
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
127
+
128
+ with torch.no_grad():
129
+ outputs = model.generate(
130
+ **inputs,
131
+ max_new_tokens=512,
132
+ do_sample=True,
133
+ temperature=0.6,
134
+ top_p=0.95,
135
+ )
136
+
137
+ print(tokenizer.decode(outputs[0], skip_special_tokens=False))
138
+ ```
139
+
140
+ ## Notes
141
+
142
+ - This is a LoRA adapter, not a standalone full model.
143
+
144
+ - The adapter is designed for the rewriting stage, not retrieval by itself.
145
+
146
+ - In downstream pipelines, the rewritten term is typically passed to a retriever or reranker.
147
+
148
+ ## Limitations
149
+
150
+ - This model is intended for research use only.
151
+
152
+ - Performance may vary across ontologies, institutions, and note styles.
153
+
154
+ - The model should be evaluated carefully before any real-world deployment.
155
+
156
+ - The final normalized term should be extracted from the <answer>...</answer> block.
157
+
158
+ ## Citation
159
+
160
+ 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
+ "down_proj",
34
+ "q_proj",
35
+ "up_proj",
36
+ "gate_proj",
37
+ "k_proj",
38
+ "v_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:e329767529c206902604a781aaf97d893a67ba5d68b33b74fc62a29749fb9225
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,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null
29
+ }