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

Model: barath007183/qwen2.5-1.5b-yoda-speak
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-09-20 17:04:16 +08:00
commit 7f05ccefd1
8 changed files with 347 additions and 0 deletions

36
.gitattributes vendored Normal file
View File

@@ -0,0 +1,36 @@
*.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

146
README.md Normal file
View File

@@ -0,0 +1,146 @@
---
library_name: transformers
base_model: Qwen/Qwen2.5-1.5B-Instruct
tags:
- lora
- peft
- yoda
- style-transfer
- qwen2.5
license: apache-2.0
language:
- en
---
# Qwen2.5-1.5B Yoda-Speak Translator
A LoRA fine-tune of Qwen2.5-1.5B-Instruct that translates ordinary English sentences into Yoda-style syntax (object/verb-first reordering, e.g. "Read this you must.").
## Model Details
### Model Description
This model takes a plain English sentence and rewrites it in Yoda's speaking style — primarily through object-subject-verb reordering rather than vocabulary changes. It was trained as a hands-on learning project to understand LoRA fine-tuning mechanics end-to-end: data preparation, chat-template formatting, loss masking, hyperparameter tradeoffs, and — most importantly — why validation loss alone isn't sufficient for picking a checkpoint on a small dataset.
- **Developed by:** Barath (independent project)
- **Model type:** Causal language model, LoRA fine-tune (adapter merged into base weights)
- **Language(s):** English
- **License:** Apache 2.0 (inherited from base model)
- **Finetuned from model:** [Qwen/Qwen2.5-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct)
## Uses
### Direct Use
Prompt the model with an instruction to translate a sentence into Yoda-speak. Works best on single, self-contained declarative sentences, questions, negations, and imperatives similar in length to the training data (roughly 25-60 characters). Style transfer only — no factual knowledge was added.
### Out-of-Scope Use
- Not intended for factual Q&A, general assistance, or any task beyond stylistic sentence reordering.
- Degrades on longer multi-clause paragraphs and dialogue-heavy text (see Evaluation below) — treat output on such inputs as unreliable without manual review.
- Not evaluated for languages other than English.
## Bias, Risks, and Limitations
- Trained on only 720 source examples (576 train / 72 val / 72 test) from the `dvgodoy/yoda_sentences` dataset — a narrow, templated dataset of short declarative sentences about mundane objects. Generalization to genuinely novel sentence structures (questions, multi-clause sentences, dialogue) is measurably weaker than in-distribution performance.
- Occasionally under-transforms harder inputs (falls back toward plain English word order) rather than producing an incorrect reordering — this was the deciding factor in checkpoint selection, since it's a safer failure mode than the token-level corruption seen in more heavily-trained checkpoints.
- No safety/toxicity-specific evaluation was performed; inherits the base model's general behavior and limitations.
### Recommendations
For inputs meaningfully different from short declarative English sentences (long paragraphs, dialogue, technical text), manually review output quality before relying on it.
## How to Get Started with the Model
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_name = "barath007183/qwen2.5-1.5b-yoda-speak" # replace with actual repo id
model = AutoModelForCausalLM.from_pretrained(model_name, dtype=torch.bfloat16, device_map="cuda")
tokenizer = AutoTokenizer.from_pretrained(model_name)
messages = [
{"role": "system", "content": "You are a Yoda-speak translator."},
{"role": "user", "content": "Translate this into Yoda-speak: The cat sat on the mat."},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
output = model.generate(**inputs, max_new_tokens=60, do_sample=False)
print(tokenizer.decode(output[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True))
# "Sat on the mat, the cat did."
```
## Training Details
### Training Data
[`dvgodoy/yoda_sentences`](https://huggingface.co/datasets/dvgodoy/yoda_sentences) — 720 paired examples of plain English sentences and their Yoda-syntax translations. Split 80/10/10 (576 train / 72 validation / 72 test), stratified by random shuffle (seed 42).
Each row was formatted as a 3-turn chat example (system + user + assistant) using Qwen2.5's native ChatML template via `tokenizer.apply_chat_template()`. A fixed system prompt ("You are a Yoda-speak translator.") was paired with one of 4 randomly-rotated user instruction phrasings per row, to avoid the model overfitting to a single trigger phrase rather than the underlying task.
### Training Procedure
- **Method:** LoRA (not QLoRA — base model loaded in bf16, no quantization; unnecessary at this model size on a 24GB GPU)
- **LoRA config:** r=8, alpha=16, dropout=0.05, target modules: `q_proj`, `k_proj`, `v_proj`, `o_proj` (attention only — MLP modules were not targeted, since this task is primarily syntactic/relational rather than knowledge-based)
- **Trainable parameters:** 2,179,072 / 1,545,893,376 total (0.141%)
- **Loss masking:** `assistant_only_loss=True` (trl 1.8.0) — loss computed only on assistant-response tokens, not system/user tokens
#### Training Hyperparameters
- **Training regime:** bf16
- **Epochs:** 3 (selected after comparing checkpoints at epochs 2, 3, and 8 — see Evaluation)
- **Batch size:** 8 (train and eval)
- **Learning rate:** 2e-4
- **Optimizer:** AdamW (trl/transformers default)
#### Speeds, Sizes, Times
- **Hardware:** 1x RTX 4090 (24GB), rented via RunPod
- **Training time:** ~26 seconds for 3 epochs (576 examples, 216 steps)
- **Checkpoint size:** LoRA adapter ~9MB; merged model ~3GB (bf16)
## Evaluation
### Testing Data, Factors & Metrics
Evaluation was done in three stages, deliberately going beyond validation loss alone:
1. **Held-out test set** (72 examples, same distribution as training data)
2. **Out-of-distribution set** (27 hand-written sentences spanning longer multi-clause sentences, questions, negation, first-person, modern/tech vocabulary, cricket-specific sentences, imperatives, and conditionals — deliberately unlike the training distribution)
3. **Paragraph stress test** (a short original fantasy-narrative paragraph with dialogue, proper nouns, and a 3-clause compound sentence)
Three checkpoints (epoch 2, 3, and 8) were compared at each stage, alongside the un-fine-tuned base model as a control.
### Results
#### Summary
- **Base model control:** confirmed fine-tuning was necessary and effective — the base model, even when explicitly instructed, produced correct Yoda-syntax reordering on only ~5/72 test sentences, frequently substituting generic "old-timey" phrasing, hallucinating unrelated content, or leaving sentences unchanged.
- **Validation loss was a misleading tie-breaker at this data scale.** Epoch 2 had marginally lower validation loss (0.2385) than epoch 3 (0.2405) — a difference within noise at 72 validation examples — but epoch 3 produced clearly better outputs on both the in-distribution and out-of-distribution test sets (5/9 flagged failure cases from epoch 2 were fully fixed by epoch 3).
- **Epoch 8 showed clear overfitting**, though not in the way a naive expectation (worse everywhere) would predict: validation loss more than doubled (0.521 vs. 0.240) and training loss approached zero, with entropy collapsing (0.190 → 0.042), indicating the model became overconfident on training-distribution patterns. In practice this showed up as *inconsistent* behavior on out-of-distribution input — fixing some failure cases epoch 3 couldn't, while introducing new token-level corruption and grammatical regressions elsewhere (e.g., producing a malformed fused token on a 3-clause compound sentence).
- **Epoch 3 was selected as the final checkpoint**: across all three evaluation stages, it never produced outright broken/garbled output, only occasional "under-transformation" (falling back toward plain English on the hardest inputs) — judged the safer failure mode compared to epoch 8's occasional token-level corruption.
## Technical Specifications
### Model Architecture and Objective
Qwen2.5-1.5B-Instruct architecture (transformer decoder, SwiGLU MLP blocks), causal language modeling objective, fine-tuned via supervised fine-tuning (SFT) with LoRA adapters merged into the base weights post-training.
### Compute Infrastructure
#### Hardware
1x NVIDIA RTX 4090 (24GB VRAM), rented via RunPod (PyTorch template, CUDA 12.8 driver)
#### Software
- `transformers`
- `trl` 1.8.0
- `peft` 0.19.1
- `torch` 2.x (cu124 build)
- `datasets`
## Model Card Authors
Barath C

54
chat_template.jinja Normal file
View File

@@ -0,0 +1,54 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0]['role'] == 'system' %}
{{- messages[0]['content'] }}
{%- else %}
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
{%- endif %}
{{- "\n\n# 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' }}
{%- else %}
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- for message in messages %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{{- '<|im_start|>' + message.role }}
{%- if message.content %}
{{- '\n' + message.content }}
{%- endif %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '\n<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{{- tool_call.arguments | tojson }}
{{- '}\n</tool_call>' }}
{%- endfor %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if (loop.index0 == 0) 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' }}
{%- endif %}

61
config.json Normal file
View File

@@ -0,0 +1,61 @@
{
"architectures": [
"Qwen2ForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 151643,
"dtype": "bfloat16",
"eos_token_id": 151645,
"hidden_act": "silu",
"hidden_size": 1536,
"initializer_range": 0.02,
"intermediate_size": 8960,
"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": 32768,
"max_window_layers": 21,
"model_type": "qwen2",
"num_attention_heads": 12,
"num_hidden_layers": 28,
"num_key_value_heads": 2,
"pad_token_id": null,
"rms_norm_eps": 1e-06,
"rope_parameters": {
"rope_theta": 1000000.0,
"rope_type": "default"
},
"sliding_window": null,
"tie_word_embeddings": true,
"transformers_version": "5.13.1",
"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
],
"pad_token_id": 151643,
"repetition_penalty": 1.1,
"temperature": 0.7,
"top_k": 20,
"top_p": 0.8,
"transformers_version": "5.13.1"
}

3
model.safetensors Normal file
View File

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

3
tokenizer.json Normal file
View File

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

30
tokenizer_config.json Normal file
View File

@@ -0,0 +1,30 @@
{
"add_prefix_space": false,
"backend": "tokenizers",
"bos_token": null,
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"errors": "replace",
"extra_special_tokens": [
"<|im_start|>",
"<|im_end|>",
"<|object_ref_start|>",
"<|object_ref_end|>",
"<|box_start|>",
"<|box_end|>",
"<|quad_start|>",
"<|quad_end|>",
"<|vision_start|>",
"<|vision_end|>",
"<|vision_pad|>",
"<|image_pad|>",
"<|video_pad|>"
],
"is_local": false,
"local_files_only": false,
"model_max_length": 131072,
"pad_token": "<|endoftext|>",
"split_special_tokens": false,
"tokenizer_class": "Qwen2Tokenizer",
"unk_token": null
}