初始化项目,由ModelHub XC社区提供模型

Model: mohar07/qwen3-0.6b-kg-triplets
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-06-27 09:43:16 +08:00
commit a1d48594f6
12 changed files with 954 additions and 0 deletions

37
.gitattributes vendored Normal file
View File

@@ -0,0 +1,37 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text
qwen3-0.6b.F16.gguf filter=lfs diff=lfs merge=lfs -text

59
Modelfile Normal file
View File

@@ -0,0 +1,59 @@
FROM qwen3-0.6b.F16.gguf
TEMPLATE """{{- if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
{{- else }}
{{- if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "<|im_start|>"
PARAMETER temperature 0.6
PARAMETER min_p 0.0
PARAMETER top_k 20
PARAMETER top_p 0.95
PARAMETER repeat_penalty 1

383
README.md Normal file
View File

@@ -0,0 +1,383 @@
---
license: mit
language:
- en
base_model: unsloth/qwen3-0.6b
tags:
- qwen3
- lora
- knowledge-graph
- relation-extraction
- information-extraction
- graph-rag
- triplet-extraction
- structured-generation
pipeline_tag: text-generation
library_name: transformers
---
# Qwen3-0.6B-KG-Triplets
Qwen3-0.6B-KG-Triplets is a LoRA finetuned version of Qwen3-0.6B specialized for ontology-constrained knowledge graph extraction.
Given a passage of text, the model generates structured triplets in the form:
```
source -> relation -> target
```
where:
- `"source"` contains an entity title and type
- `"relation"` contains a relation type and confidence weight
- `"target"` contains an entity title and type
The output is designed for direct ingestion into graph databases and GraphRAG pipelines with minimal post-processing.
---
## Motivation
Most instruction-tuned LLMs can extract entities and relations, but their outputs are difficult to ingest directly into graph databases because of:
- inconsistent entity naming
- out-of-schema relations
- poorly calibrated confidence scores
- inconsistent JSON formatting
This model was finetuned specifically to produce:
- ontology-constrained outputs
- normalized entity names
- calibrated relation confidence weights
- graph-ingestable JSON
---
## Model Details
| Property | Value |
|---|---|
| Base Model | unsloth/qwen3-0.6b |
| Finetuning | LoRA |
| Rank (r) | 32 |
| Alpha | 32 |
| Context Length | 2048 |
| Epochs | 5 |
| Optimizer | AdamW 8-bit |
| Framework | Unsloth + TRL |
| Training Type | Instruction Finetuning |
| License | MIT |
---
## Training Configuration
```python
model = FastLanguageModel.get_peft_model(
model,
r=32,
target_modules=[
"q_proj",
"k_proj",
"v_proj",
"o_proj",
"gate_proj",
"up_proj",
"down_proj",
],
lora_alpha=32,
lora_dropout=0,
bias="none",
use_gradient_checkpointing="unsloth",
)
```
| Parameter | Value |
|---|---|
| Batch size | 2 |
| Gradient accumulation | 4 |
| Learning rate | 5e-5 |
| Epochs | 5 |
| Warmup steps | 50 |
| Max sequence length | 2048 |
| Optimizer | AdamW 8-bit |
| Seed | 42 |
---
## Dataset
The model was trained on a custom instruction dataset for structured knowledge graph extraction.
### Corpus Sources
- Wikipedia
- arXiv papers
### Dataset Statistics
| Split | Examples |
|---|---|
| Train | 2575 |
| Validation | 75 |
| Test | 700 |
| **Total** | **3350** |
Additional properties:
- 20 ontology relations
- 15% hard negatives in training
- Entity-level train/test decontamination
- Curriculum ordering (easy → hard)
- Zero schema errors
---
## Relation Schema
The model predicts only the following ontology:
```
implements
trained_on
evaluates
part_of
introduces
extends
depends_on
contrasts_with
applied_to
measured_by
founded_by
developed_by
defined_as
consists_of
is_type_of
based_on
used_for
created_by
located_in
predecessor_of
```
Relations outside this ontology are intentionally not generated.
---
## Dataset Creation Pipeline
The training corpus was built using a multi-stage pipeline:
1. Corpus collection from Wikipedia and arXiv
2. Language and quality filtering
3. MinHash deduplication
4. LLM triplet generation using DeepSeek V4-Flash
5. Schema validation
6. Semantic validation
7. Hard negative generation
8. Curriculum ordering
9. Entity-level train/test decontamination
10. Train / Validation / Test split
---
## Training Example
Input:
```json
{
"role": "user",
"content": "Extract knowledge graph triplets..."
}
```
Output:
```json
[
{
"source": {
"title": "September",
"type": "entity"
},
"relation": {
"type": "part_of",
"weight": 0.92
},
"target": {
"title": "Gregorian calendar",
"type": "entity"
}
},
{
"source": {
"title": "September",
"type": "entity"
},
"relation": {
"type": "defined_as",
"weight": 0.92
},
"target": {
"title": "ninth month",
"type": "concept"
}
}
]
```
---
## Evaluation
Evaluation was performed using a custom triplet extraction benchmark with Hungarian bipartite matching alignment on 700 held-out entries.
### Metrics
| Metric | Score | Weight |
|---|---|---|
| Schema score | 1.000 | 0.30 |
| Entity F1 | 0.179 | 0.25 |
| Relation accuracy | 0.680 | 0.20 |
| Grounding | 0.969 | 0.15 |
| Weight score | 0.526 | 0.10 |
| Triplet F1 *(info only)* | 0.122 | — |
| Type agreement *(info only)* | 0.854 | — |
| Hallucination rate | 0.033 | — |
**Composite Score: 0.6583**
---
## What Finetuning Fixed
Finetuning addressed three major failure modes of the base model.
### 1. Entity Normalization
Input passage:
> *Studies of the Cambrian period document the rapid diversification of animal life and the emergence of most major animal phyla, with some researchers proposing that a celestial body impact may have triggered the extinction events that preceded this radiation.*
Base entity title extracted:
```
After a thorough research on the circumstantial changes and the great evolution of life in the Cambrian period
```
Finetuned entity title extracted:
```
Celestial body impact hypothesis
```
The finetuned model learns reusable and atomic graph nodes rather than copying passage fragments.
---
### 2. Schema Adherence
Base relations generated:
```
released
benefited_from
```
Finetuned relations generated:
```
based_on
used_for
applied_to
introduces
```
All generated relations belong to the predefined ontology.
---
### 3. Confidence Calibration
Base weights:
```
0.8
0.8
0.8
0.8
```
Finetuned weights:
```
0.23
0.41
0.59
0.77
```
The model learns meaningful confidence distributions where stronger relations receive higher scores.
---
## Intended Use
This model is intended for:
- Knowledge Graph Construction
- GraphRAG pipelines
- Structured Information Extraction
- Entity-Relation Extraction
- Automated KG population
- Document-to-Graph conversion
---
## Limitations
While the model demonstrates strong schema adherence and grounding, several limitations remain.
**Shallow Entity Abstraction**
The model favors concise and reusable entities but may miss deeper semantic abstractions or hierarchical entity relationships.
**Limited Recall**
The model prioritizes schema correctness and grounded extraction over exhaustive triplet recall. Entity F1 of 0.179 reflects strict Hungarian-matching alignment on a 20-relation ontology-constrained task; recall is intentionally traded for precision and schema adherence.
**English-Centric Training**
Training was primarily conducted on English Wikipedia and arXiv passages.
**Ontology Constrained**
Only the predefined 20 relation types are supported.
**Model Size Constraints**
Despite the relatively small size (0.6B parameters) and a modest training corpus (~3K examples), the model learns stable ontology-constrained extraction behavior. Larger models may achieve deeper entity understanding and broader relation coverage.
---
## Repository
Evaluation Pipeline: https://github.com/mohar-xe/HGR-finetuned-model-evaluation-pipeline
Model: https://huggingface.co/mohar07/qwen3-0.6b-kg-triplets
---
## Citation
```bibtex
@misc{das2026qwenkgtriplets,
title={Qwen3-0.6B-KG-Triplets},
author={Mohar Das},
year={2026},
publisher={Hugging Face},
url={https://huggingface.co/mohar07/qwen3-0.6b-kg-triplets}
}
```

52
adapter_config.json Normal file
View File

@@ -0,0 +1,52 @@
{
"alora_invocation_tokens": null,
"alpha_pattern": {},
"arrow_config": null,
"auto_mapping": {
"base_model_class": "Qwen3ForCausalLM",
"parent_library": "transformers.models.qwen3.modeling_qwen3",
"unsloth_fixed": true
},
"base_model_name_or_path": "unsloth/qwen3-0.6b-unsloth-bnb-4bit",
"bias": "none",
"corda_config": null,
"ensure_weight_tying": false,
"eva_config": null,
"exclude_modules": null,
"fan_in_fan_out": false,
"inference_mode": true,
"init_lora_weights": true,
"layer_replication": null,
"layers_pattern": null,
"layers_to_transform": null,
"loftq_config": {},
"lora_alpha": 32,
"lora_bias": false,
"lora_dropout": 0,
"lora_ga_config": null,
"megatron_config": null,
"megatron_core": "megatron.core",
"modules_to_save": null,
"peft_type": "LORA",
"peft_version": "0.19.1",
"qalora_group_size": 16,
"r": 32,
"rank_pattern": {},
"revision": null,
"target_modules": [
"v_proj",
"q_proj",
"k_proj",
"gate_proj",
"o_proj",
"up_proj",
"down_proj"
],
"target_parameters": null,
"task_type": "CAUSAL_LM",
"trainable_token_indices": null,
"use_bdlora": null,
"use_dora": false,
"use_qalora": false,
"use_rslora": false
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5d63d109bc039634570b29b4deff16253d9889bca49c27407084fd5f9b00fb32
size 80792456

99
chat_template.jinja Normal file
View File

@@ -0,0 +1,99 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0].role == 'system' %}
{{- messages[0].content + '\n\n' }}
{%- endif %}
{{- "# 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>" }}
{%- for tool in tools %}
{{- "\n" }}
{{- tool | tojson }}
{%- endfor %}
{{- "\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" }}
{%- else %}
{%- if messages[0].role == 'system' %}
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for forward_message in messages %}
{%- set index = (messages|length - 1) - loop.index0 %}
{%- set message = messages[index] %}
{%- set current_content = message.content if message.content is defined and message.content is not none else '' %}
{%- set tool_start = '<tool_response>' %}
{%- set tool_start_length = tool_start|length %}
{%- set start_of_message = current_content[:tool_start_length] %}
{%- set tool_end = '</tool_response>' %}
{%- set tool_end_length = tool_end|length %}
{%- set start_pos = (current_content|length) - tool_end_length %}
{%- if start_pos < 0 %}
{%- set start_pos = 0 %}
{%- endif %}
{%- set end_of_message = current_content[start_pos:] %}
{%- if ns.multi_step_tool and message.role == "user" and not(start_of_message == tool_start and end_of_message == tool_end) %}
{%- set ns.multi_step_tool = false %}
{%- set ns.last_query_index = index %}
{%- endif %}
{%- endfor %}
{%- for message in messages %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{%- set m_content = message.content if message.content is defined and message.content is not none else '' %}
{%- set content = m_content %}
{%- set reasoning_content = '' %}
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
{%- set reasoning_content = message.reasoning_content %}
{%- else %}
{%- if '</think>' in m_content %}
{%- set content = (m_content.split('</think>')|last).lstrip('\n') %}
{%- set reasoning_content = (m_content.split('</think>')|first).rstrip('\n') %}
{%- set reasoning_content = (reasoning_content.split('<think>')|last).lstrip('\n') %}
{%- endif %}
{%- endif %}
{%- if loop.index0 > ns.last_query_index %}
{%- if loop.last or (not loop.last and (not reasoning_content.strip() == '')) %}
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- if message.tool_calls %}
{%- for tool_call in message.tool_calls %}
{%- if (loop.first and content) or (not loop.first) %}
{{- '\n' }}
{%- endif %}
{%- if tool_call.function %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{%- if tool_call.arguments is string %}
{{- tool_call.arguments }}
{%- else %}
{{- tool_call.arguments | tojson }}
{%- endif %}
{{- '}\n</tool_call>' }}
{%- endfor %}
{%- endif %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n<tool_response>\n' }}
{{- message.content }}
{{- '\n</tool_response>' }}
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is false %}
{{- '<think>\n\n</think>\n\n' }}
{%- endif %}
{%- endif %}

64
config.json Normal file
View File

@@ -0,0 +1,64 @@
{
"architectures": [
"Qwen3ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": null,
"torch_dtype": "float16",
"eos_token_id": 151645,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 1024,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_types": [
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention"
],
"max_position_embeddings": 40960,
"max_window_layers": 28,
"model_type": "qwen3",
"num_attention_heads": 16,
"num_hidden_layers": 28,
"num_key_value_heads": 8,
"pad_token_id": 151669,
"rms_norm_eps": 1e-06,
"rope_parameters": {
"rope_theta": 1000000,
"rope_type": "default"
},
"sliding_window": null,
"tie_word_embeddings": true,
"unsloth_fixed": true,
"unsloth_version": "2026.5.10",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936
}

14
generation_config.json Normal file
View File

@@ -0,0 +1,14 @@
{
"bos_token_id": 151643,
"do_sample": true,
"eos_token_id": [
151645,
151643
],
"max_length": 40960,
"pad_token_id": 151669,
"temperature": 0.6,
"top_k": 20,
"top_p": 0.95,
"transformers_version": "5.5.0"
}

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d9f8ce2716b3e13ef963cc34daa5064282b1989b4d3d8f0726a4cb41851f8b32
size 1192135096

3
qwen3-0.6b.F16.gguf Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9e3a444995e614ad66c569346811d6315591b5529ae891022221e49b8de97a26
size 1198182976

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d7430e9138b76e93fb6f93462394d236b411111aef53cb421ba97d2691040cca
size 11423114

234
tokenizer_config.json Normal file

File diff suppressed because one or more lines are too long