From 15dae3f2a8a9161fe71439db46fdb944edf451b7 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Thu, 9 Jul 2026 01:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: gokaygokay/prompt-enhancer-gemma-3-270m-it Source: Original Platform --- .gitattributes | 52 +++++++++++++++++++++++++++++++++ README.md | 65 +++++++++++++++++++++++++++++++++++++++++ added_tokens.json | 3 ++ chat_template.jinja | 47 +++++++++++++++++++++++++++++ config.json | 54 ++++++++++++++++++++++++++++++++++ configuration.json | 1 + generation_config.json | 11 +++++++ model.safetensors | 3 ++ special_tokens_map.json | 33 +++++++++++++++++++++ tokenizer.json | 3 ++ tokenizer.model | 3 ++ tokenizer_config.json | 3 ++ 12 files changed, 278 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 added_tokens.json create mode 100644 chat_template.jinja create mode 100644 config.json create mode 100644 configuration.json create mode 100644 generation_config.json create mode 100644 model.safetensors create mode 100644 special_tokens_map.json create mode 100644 tokenizer.json create mode 100644 tokenizer.model create mode 100644 tokenizer_config.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..65587e6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,52 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bin.* filter=lfs diff=lfs merge=lfs -text +*.bz2 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 + +*.msgpack 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 +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +saved_model/**/* 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 +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zstandard filter=lfs diff=lfs merge=lfs -text +*.tfevents* filter=lfs diff=lfs merge=lfs -text +*.db* filter=lfs diff=lfs merge=lfs -text +*.ark* filter=lfs diff=lfs merge=lfs -text +**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text +**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text +**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text + +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.gguf* filter=lfs diff=lfs merge=lfs -text +*.ggml filter=lfs diff=lfs merge=lfs -text +*.llamafile* filter=lfs diff=lfs merge=lfs -text +*.pt2 filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.wasm 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 +tokenizer.model filter=lfs diff=lfs merge=lfs -text +model.safetensors filter=lfs diff=lfs merge=lfs -text +tokenizer_config.json filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..00c001d --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +--- +base_model: google/gemma-3-270m-it +tags: +- text-generation +- prompt-enhancement +- gemma +- prompt-engineering +datasets: +- gokaygokay/prompt-enhancer-dataset +- gokaygokay/prompt-enhancement-75k +--- + +# Prompt Enhancer - Gemma 3 270M + +A fine-tuned model based on `google/gemma-3-270m-it` for enhancing and expanding short prompts into detailed, context-rich descriptions. + +## Usage + +```python +from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline + +model = AutoModelForCausalLM.from_pretrained("gokaygokay/prompt-enhancer-gemma-3-270m-it") +tokenizer = AutoTokenizer.from_pretrained("gokaygokay/prompt-enhancer-gemma-3-270m-it") +pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) + +messages = [ + {"role": "system", "content": "Enhance and expand the following prompt with more details and context:"}, + {"role": "user", "content": "a cat sitting on a chair"} +] + +prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) +output = pipe(prompt, max_new_tokens=256) +print(output[0]['generated_text']) +``` + +## Training Details + +- **Base Model:** google/gemma-3-270m-it +- **Training Method:** LoRA (Low-Rank Adaptation) +- **LoRA Config:** r=16, alpha=32 +- **Training Epochs:** 3 +- **Learning Rate:** 5e-5 +- **Batch Size:** 4 (with gradient accumulation) + +### MODEL COMPARISON: Base vs Fine-tuned + +**INPUT**: a cat sitting on a chair + +**FINE-TUNED OUTPUT**: +a cat sitting on a brown wooden chair, white backdrop, cat is facing the right side of the image, black background, feline features are clear and defined, cat's head and body are on the chair, background appears dark and lit, the lighting is soft and suggests a serene evening or night scene. + +**INPUT**: beautiful sunset + +**FINE-TUNED OUTPUT**: +sunset sky over a landscape, clouds visible across the sky, trees in the foreground and middle, a lone figure in the middle of the frame, silhouette of a building in the middle background, horizon line visible in the distance, clear and bright sky, a dark sky with hues of orange and purple. + +**INPUT**: futuristic city + +**FINE-TUNED OUTPUT**: +a futuristic cityscape at night, buildings with glowing neon lights, towers covered in glowing energy crystals, a large tower with glowing lights, multiple towers below, towers have glowing lights and contain glowing structures, people walking and walking, some buildings are lit up and others are dark, large, glowing lights dominate the sky, a few people are visible on the ground below, buildings are tall and tall, some skyscrapers have multiple stories, buildings appear to be floating in space, eerie and futuristic atmosphere, dense and detailed urban environment. + +**INPUT**: portrait of a woman + +**FINE-TUNED OUTPUT**: +a woman in a dress, wearing a hat and a headscarf, standing in a crowded urban space, her face is visible, wearing a black shirt and a black hat, wearing a black belt around her waist, woman is wearing glasses and a scarf, large urban city skyline visible in the background, small building in the bottom left corner below the woman, copyspace, bright sunlight. diff --git a/added_tokens.json b/added_tokens.json new file mode 100644 index 0000000..e17bde0 --- /dev/null +++ b/added_tokens.json @@ -0,0 +1,3 @@ +{ + "": 262144 +} diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..1117055 --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1,47 @@ +{{ bos_token }} +{%- if messages[0]['role'] == 'system' -%} + {%- if messages[0]['content'] is string -%} + {%- set first_user_prefix = messages[0]['content'] + ' + +' -%} + {%- else -%} + {%- set first_user_prefix = messages[0]['content'][0]['text'] + ' + +' -%} + {%- endif -%} + {%- set loop_messages = messages[1:] -%} +{%- else -%} + {%- set first_user_prefix = "" -%} + {%- set loop_messages = messages -%} +{%- endif -%} +{%- for message in loop_messages -%} + {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%} + {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }} + {%- endif -%} + {%- if (message['role'] == 'assistant') -%} + {%- set role = "model" -%} + {%- else -%} + {%- set role = message['role'] -%} + {%- endif -%} + {{ '' + role + ' +' + (first_user_prefix if loop.first else "") }} + {%- if message['content'] is string -%} + {{ message['content'] | trim }} + {%- elif message['content'] is iterable -%} + {%- for item in message['content'] -%} + {%- if item['type'] == 'image' -%} + {{ '' }} + {%- elif item['type'] == 'text' -%} + {{ item['text'] | trim }} + {%- endif -%} + {%- endfor -%} + {%- else -%} + {{ raise_exception("Invalid content type") }} + {%- endif -%} + {{ ' +' }} +{%- endfor -%} +{%- if add_generation_prompt -%} + {{'model +'}} +{%- endif -%} diff --git a/config.json b/config.json new file mode 100644 index 0000000..4e07204 --- /dev/null +++ b/config.json @@ -0,0 +1,54 @@ +{ + "_sliding_window_pattern": 6, + "architectures": [ + "Gemma3ForCausalLM" + ], + "attention_bias": false, + "attention_dropout": 0.0, + "attn_logit_softcapping": null, + "bos_token_id": 2, + "dtype": "bfloat16", + "eos_token_id": 1, + "final_logit_softcapping": null, + "head_dim": 256, + "hidden_activation": "gelu_pytorch_tanh", + "hidden_size": 640, + "initializer_range": 0.02, + "intermediate_size": 2048, + "layer_types": [ + "sliding_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "full_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "full_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "sliding_attention", + "full_attention" + ], + "max_position_embeddings": 32768, + "model_type": "gemma3_text", + "num_attention_heads": 4, + "num_hidden_layers": 18, + "num_key_value_heads": 1, + "pad_token_id": 0, + "query_pre_attn_scalar": 256, + "rms_norm_eps": 1e-06, + "rope_local_base_freq": 10000.0, + "rope_scaling": null, + "rope_theta": 1000000.0, + "sliding_window": 512, + "transformers_version": "4.57.0", + "use_bidirectional_attention": false, + "use_cache": true, + "vocab_size": 262144 +} diff --git a/configuration.json b/configuration.json new file mode 100644 index 0000000..bbeeda1 --- /dev/null +++ b/configuration.json @@ -0,0 +1 @@ +{"framework": "pytorch", "task": "text-generation", "allow_remote": true} \ No newline at end of file diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..df19824 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,11 @@ +{ + "cache_implementation": "hybrid", + "do_sample": true, + "eos_token_id": [ + 1, + 106 + ], + "top_k": 64, + "top_p": 0.95, + "transformers_version": "4.57.0" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..e668767 --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbab9eeebcebeebaabb969279a80db041530f262cff5a0bd1fcc93c4374585c0 +size 536223056 diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..1a61932 --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,33 @@ +{ + "boi_token": "", + "bos_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "eoi_token": "", + "eos_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "image_token": "", + "pad_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "unk_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + } +} diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..29401f9 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4667f2089529e8e7657cfb6d1c19910ae71ff5f28aa7ab2ff2763330affad795 +size 33384568 diff --git a/tokenizer.model b/tokenizer.model new file mode 100644 index 0000000..14f810a --- /dev/null +++ b/tokenizer.model @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c +size 4689074 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..0fef25d --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db4e9d507644beaaf7e3da1ad8184057e9f661adeb67f9473c8b6ad45141f303 +size 1155373