初始化项目,由ModelHub XC社区提供模型
Model: rizwan261/smollm2-135m-text2cypher Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
*.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
|
||||
107
README.md
Normal file
107
README.md
Normal file
@@ -0,0 +1,107 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
base_model: HuggingFaceTB/SmolLM2-135M-Instruct
|
||||
datasets:
|
||||
- RomanTeucher/text2cypher-curated
|
||||
language:
|
||||
- en
|
||||
library_name: transformers
|
||||
pipeline_tag: text-generation
|
||||
tags:
|
||||
- text2cypher
|
||||
- cypher
|
||||
- neo4j
|
||||
- lora
|
||||
---
|
||||
|
||||
# SmolLM2-135M-text2cypher
|
||||
|
||||
A fine-tune of [`HuggingFaceTB/SmolLM2-135M-Instruct`](https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct)
|
||||
that turns a natural-language question + a graph schema into a **Cypher** query.
|
||||
Trained with LoRA on [`RomanTeucher/text2cypher-curated`](https://huggingface.co/datasets/RomanTeucher/text2cypher-curated)
|
||||
(1000 train / 75 val / 50 test); the adapters are **merged into the base weights**,
|
||||
so this is a standalone full model that loads like any HF checkpoint — no PEFT needed.
|
||||
**This model is a submission for an interview.**
|
||||
|
||||
## Usage
|
||||
|
||||
The model expects the same ChatML prompt it was trained on: a fixed system message
|
||||
plus a user turn of `Schema:` + `Question:`.
|
||||
|
||||
```python
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
|
||||
model_id = "rizwan261/smollm2-135m-text2cypher"
|
||||
tok = AutoTokenizer.from_pretrained(model_id)
|
||||
model = AutoModelForCausalLM.from_pretrained(model_id)
|
||||
|
||||
SYSTEM = ("You are a text-to-Cypher engine for Neo4j. Given a graph schema and a "
|
||||
"question, output a single valid Cypher query that answers the question. "
|
||||
"Use only labels, relationship types and properties that appear in the "
|
||||
"schema. Output the Cypher query and nothing else: no explanation, no "
|
||||
"comments, no markdown code fences.")
|
||||
|
||||
schema = "Graph schema: Relevant node labels and their properties (with datatypes) are:\nUpdateDate {update_date: DATE}"
|
||||
question = "Which nodes are connected to UpdateDate where update_date is 2008-01-29, and also to another node?"
|
||||
messages = [
|
||||
{"role": "system", "content": SYSTEM},
|
||||
{"role": "user", "content": f"Schema:\n{schema}\n\nQuestion:\n{question}"},
|
||||
]
|
||||
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
|
||||
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
|
||||
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
||||
|
||||
```
|
||||
|
||||
## Training
|
||||
|
||||
LoRA (r=16, α=32, dropout=0.05) on the attention + MLP projections, completion-only
|
||||
loss (the prompt is masked, loss is on the target Cypher only), then merged.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| epochs | 20 |
|
||||
| learning rate | 5e-5, cosine, 5% warmup |
|
||||
| effective batch | 16 (bs 4 × grad-accum 4) |
|
||||
| max length | 1024 |
|
||||
| best val loss | ~0.32 (by `eval_loss`) |
|
||||
|
||||
## Evaluation
|
||||
|
||||
Test split (n=50), greedy decoding. **Translation / structural metrics** over the
|
||||
whole split — surface proxies for correctness:
|
||||
|
||||
| metric | base | this model |
|
||||
| --- | ---: | ---: |
|
||||
| exact_match | 0.00 | 0.26 |
|
||||
| structural_f1 | 0.18 | 0.81 |
|
||||
| google_bleu | 0.07 | 0.70 |
|
||||
| well_formed | 0.00 | 0.98 |
|
||||
|
||||
**Execution-based** evaluation against the live Neo4j demo databases, on the 18/50
|
||||
samples that carry a database reference — predicted and gold queries are run and
|
||||
their *result sets* compared. This is the honest measure, and each stricter layer
|
||||
peels back the previous one's optimism:
|
||||
|
||||
| how strict | metric | base | this model |
|
||||
| --- | --- | ---: | ---: |
|
||||
| real parser + live schema | CyVer KG-Valid-Query | 0.00 | 0.61 |
|
||||
| runs on the DB | query executes | 0.00 | 0.72 |
|
||||
| **returns the right rows** | exec ExactMatch (non-trivial) | 0.00 | **0.00** |
|
||||
|
||||
The surface metrics jump, but execution accuracy stays at zero: the model writes
|
||||
well-formed, schema-valid, runnable Cypher that returns the *wrong data*.
|
||||
|
||||
## Limitations
|
||||
|
||||
A 135M model produces Cypher that often *looks* right but isn't: only ~26% are
|
||||
exact matches, and **non-trivial execution accuracy is ~0** — well-formed,
|
||||
runnable queries that return the wrong rows. It reliably gets node labels, clauses
|
||||
and the query skeleton, but struggles with same-node/co-reference patterns,
|
||||
multi-stage aggregation, and occasionally hallucinates functions. Execution
|
||||
numbers come from a small (n=18) subset run against live demo databases, so they
|
||||
can drift.
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0, inherited from the SmolLM2 base model.
|
||||
6
chat_template.jinja
Normal file
6
chat_template.jinja
Normal file
@@ -0,0 +1,6 @@
|
||||
{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system
|
||||
You are a helpful AI assistant named SmolLM, trained by Hugging Face<|im_end|>
|
||||
' }}{% endif %}{{'<|im_start|>' + message['role'] + '
|
||||
' + message['content'] + '<|im_end|>' + '
|
||||
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
||||
' }}{% endif %}
|
||||
40
config.json
Normal file
40
config.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"architectures": [
|
||||
"LlamaForCausalLM"
|
||||
],
|
||||
"attention_bias": false,
|
||||
"attention_dropout": 0.0,
|
||||
"bos_token_id": 1,
|
||||
"dtype": "bfloat16",
|
||||
"eos_token_id": 2,
|
||||
"head_dim": 64,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 576,
|
||||
"initializer_range": 0.041666666666666664,
|
||||
"intermediate_size": 1536,
|
||||
"is_llama_config": true,
|
||||
"max_position_embeddings": 8192,
|
||||
"mlp_bias": false,
|
||||
"model_type": "llama",
|
||||
"num_attention_heads": 9,
|
||||
"num_hidden_layers": 30,
|
||||
"num_key_value_heads": 3,
|
||||
"pad_token_id": 2,
|
||||
"pretraining_tp": 1,
|
||||
"rms_norm_eps": 1e-05,
|
||||
"rope_interleaved": false,
|
||||
"rope_parameters": {
|
||||
"rope_theta": 100000,
|
||||
"rope_type": "default"
|
||||
},
|
||||
"tie_word_embeddings": true,
|
||||
"transformers.js_config": {
|
||||
"kv_cache_dtype": {
|
||||
"fp16": "float16",
|
||||
"q4f16": "float16"
|
||||
}
|
||||
},
|
||||
"transformers_version": "5.12.1",
|
||||
"use_cache": true,
|
||||
"vocab_size": 49152
|
||||
}
|
||||
9
generation_config.json
Normal file
9
generation_config.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"_from_model_config": true,
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": [
|
||||
2
|
||||
],
|
||||
"pad_token_id": 2,
|
||||
"transformers_version": "5.12.1"
|
||||
}
|
||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:532d759c2ac6bab59e737f61eadf8a2111f277bc8106eabb33a1be84c5d2d5d4
|
||||
size 269060552
|
||||
244965
tokenizer.json
Normal file
244965
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
19
tokenizer_config.json
Normal file
19
tokenizer_config.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"add_prefix_space": false,
|
||||
"backend": "tokenizers",
|
||||
"bos_token": "<|im_start|>",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|im_end|>",
|
||||
"errors": "replace",
|
||||
"extra_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>"
|
||||
],
|
||||
"is_local": false,
|
||||
"local_files_only": false,
|
||||
"model_max_length": 8192,
|
||||
"pad_token": "<|im_end|>",
|
||||
"tokenizer_class": "GPT2Tokenizer",
|
||||
"unk_token": "<|endoftext|>",
|
||||
"vocab_size": 49152
|
||||
}
|
||||
54
train_summary.json
Normal file
54
train_summary.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"config": {
|
||||
"model_name": "HuggingFaceTB/SmolLM2-135M-Instruct",
|
||||
"dataset_name": "RomanTeucher/text2cypher-curated",
|
||||
"output_dir": "outputs/smollm2-135m-text2cypher",
|
||||
"max_length": 1024,
|
||||
"epochs": 20.0,
|
||||
"learning_rate": 5e-05,
|
||||
"weight_decay": 0.01,
|
||||
"warmup_ratio": 0.05,
|
||||
"warmup_steps": null,
|
||||
"lr_scheduler_type": "cosine",
|
||||
"train_batch_size": 4,
|
||||
"eval_batch_size": 4,
|
||||
"gradient_accumulation_steps": 4,
|
||||
"max_grad_norm": 1.0,
|
||||
"bf16": null,
|
||||
"fp16": null,
|
||||
"use_lora": true,
|
||||
"lora_r": 16,
|
||||
"lora_alpha": 32,
|
||||
"lora_dropout": 0.05,
|
||||
"logging_steps": 10,
|
||||
"eval_strategy": "epoch",
|
||||
"save_strategy": "epoch",
|
||||
"save_total_limit": 1,
|
||||
"load_best_model_at_end": true,
|
||||
"metric_for_best_model": "eval_loss",
|
||||
"greater_is_better": false,
|
||||
"seed": 42,
|
||||
"cpu_threads": null,
|
||||
"push_to_hub": false,
|
||||
"hub_model_id": null
|
||||
},
|
||||
"tokenization": {
|
||||
"train": {
|
||||
"n": 1000,
|
||||
"truncated": 0,
|
||||
"empty_target": 0
|
||||
},
|
||||
"val": {
|
||||
"n": 75,
|
||||
"truncated": 0,
|
||||
"empty_target": 0
|
||||
}
|
||||
},
|
||||
"final_eval": {
|
||||
"eval_loss": 0.3248527944087982,
|
||||
"eval_runtime": 2.1616,
|
||||
"eval_samples_per_second": 34.696,
|
||||
"eval_steps_per_second": 8.79,
|
||||
"epoch": 20.0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user