--- language: - en - zh license: other license_name: non-commercial-personal-use license_link: LICENSE base_model: Qwen/Qwen3.5-4B-Base pipeline_tag: text-generation tags: - anime - text-to-image - prompt-expansion - danbooru - qwen3_5 - non-commercial --- # PromptGacha **English** | [中文](README_zh.md) > A general-purpose anime image-generation prompt **translation & expansion** model fine-tuned from [Qwen3.5-4B-Base](https://huggingface.co/Qwen/Qwen3.5-4B-Base) (text-only, vision tower stripped). Supports flexible multi-format inputs and strict prose / structured JSON dual-mode outputs. ## Overview Rather than a rigid 1-to-1 tag-to-sentence translator, this model is designed as a **Prompt Gacha LLM** with intentional **bidirectional input–output asymmetry**: - **Sparse input → Creative expansion (Gacha mode)**: The shorter your input (even just `1girl` or a single action like `hug`), the more freely the model invents vivid composition, lighting, outfits, and scenery. Unlike general-purpose cloud LLMs that tend to collapse into repetitive templates, this model is trained to preserve high diversity across draws. - **Detailed input → Faithful translation + automatic out-of-frame clipping**: You can paste a full head-to-toe character sheet directly into the input. Whenever framing or occlusion hides certain traits (e.g., shoes/socks in an `upper body` shot, facial features in `from behind`, or eye color under `closed eyes`), the model automatically omits those invisible details so downstream image generators don't zoom out awkwardly or break anatomy. ## Model Card | Field | Details | | --- | --- | | **Base Model** | [Qwen/Qwen3.5-4B-Base](https://huggingface.co/Qwen/Qwen3.5-4B-Base) (vision tower stripped into pure-text `Qwen3_5ForCausalLM`) | | **Parameters** | 4.21B (pure-text BF16; exports cleanly to GGUF without `mmproj`) | | **Training Method** | Full-parameter BF16 SFT (`v0.1` selected at 1.0 epoch checkpoint, `eval_loss = 1.640`) | | **Dataset Scale** | 9,533 train + 212 eval samples (Mode A 78.7% / Mode B-1 9.4% / Mode B-2 12.0%; covers `g/s/q/e` ratings) | | **Supported Inputs** | Flat Danbooru tags / Multi-line text blocks / Lightweight YAML / Structured JSON / Natural-language + tags hybrid | | **Output Modes** | Mode A (default, pure English prose) / Mode B-1 (single-prompt JSON) / Mode B-2 (per-subject split JSON) | | **Target Generators** | [Anima](https://huggingface.co/circlestone-labs/Anima), [NovelAI (NAI)](https://novelai.net/), [MOSS-Image](https://huggingface.co/OpenMOSS-Team/MOSS-Image-SFT), [FLUX](https://huggingface.co/black-forest-labs), [Qwen-Image](https://huggingface.co/Qwen/Qwen-Image), and other natural-language or regional-prompting anime models | ## Input & Output Specification The model follows a **wide-in, strict-out** contract: inputs accept multiple casual or structured formats with optional controls, while outputs strictly conform to clean English prose or valid JSON. ### Optional Control Fields (All Optional) | Field | Values / Examples | Default | Description | | --- | --- | --- | --- | | `rating` | `general` / `sensitive` / `questionable` / `explicit` | Inferred from input | Content rating control | | `length` | `concise` / `standard` / `detailed` / `elaborate` | Free | Target output length tier (calibrated with Qwen3.5 tokenizer: `≤180` / `181–320` / `321–550` / `>550` tokens) | | `aspect_ratio` | `2:3`, `3:4`, `1:1`, `3:2`, `16:9`, etc. | Free | Strictly honored when provided; auto-recommended in JSON modes when omitted | | `style` | `"off"` / `"on"` / custom style phrase (e.g., `"soft watercolor"`) | `"off"` (style-neutral) | **Off by default** to avoid injecting conflicting medium/technique keywords over your artist tags or LoRAs | | `output_format` | `"json"` | Omitted (Mode A) | Outputs pure English prose by default; set `"json"` to switch to Mode B | | `split_characters` | `true` / `false` | `false` | Active only with `output_format: "json"`: `false` returns `{"aspect_ratio", "prompt"}`; `true` splits independent foreground subjects (characters, animals, mecha, key props) | ### Supported Input Formats 1. **Flat Danbooru Tags** (supports both underscores and spaces, including ultra-sparse gacha inputs): ```text 1girl, 1boy, hetero, hakurei reimu, black hair, red hair ribbon, school uniform, kissing cheek, classroom, sunset lighting ``` Optional key-value control headers can be prepended: ```text rating: sensitive length: standard aspect_ratio: 2:3 1girl, silver hair, rooftop, sunset ``` 2. **Multi-line Text Blocks (Per-Character Anchoring)**: ```text 1girl, 1boy, hetero, girl, hakurei_reimu, black_hair, red_hair_ribbon, school_uniform, leaning_down, kissing_other's_cheek, boy, short_brown_hair, school_uniform, blushing, surprised_expression, classroom, sunset_lighting, upper_body ``` 3. **Lightweight YAML**: ```yaml rating: sensitive aspect_ratio: 2:3 scene: classroom, sunset lighting, upper body characters: - hakurei_reimu [female] | black hair, red hair ribbon, school uniform, leaning down, kissing other's cheek - [male] | short brown hair, school uniform, blushing, surprised expression ``` 4. **Structured JSON**: ```json { "rating": "sensitive", "length": "standard", "aspect_ratio": "2:3", "style": "soft watercolor, delicate linework", "output_format": "json", "split_characters": true, "scene": ["classroom", "sunset lighting", "warm glow", "upper body", "window"], "characters": [ { "name": "hakurei_reimu", "gender": "female", "tags": ["black hair", "red hair ribbon", "school uniform", "white thighhighs", "black loafers", "leaning down", "kissing other's cheek", "gentle smile"] }, { "name": null, "gender": "male", "tags": ["short brown hair", "school uniform", "blushing", "surprised expression", "receiving kiss on cheek"] } ] } ``` > Even though the character card includes `white thighhighs` and `black loafers`, the `upper body` framing cues the model to omit those out-of-frame items automatically. ### Output Modes - **Mode A (Default — omit `output_format`): Pure English Prose** No Markdown wrappers, no VLM phrasing (*"The image depicts..."*), no aspect-ratio text noise—ready to paste straight into your image generator: ```text Warm late-afternoon sunlight streams through the tall windows of a quiet classroom, framing the scene from the waist up. Hakurei Reimu, her long black hair tied with a red ribbon and dressed in a neat school uniform, leans down with a gentle smile to press a soft kiss against a young man's cheek. The boy, with short brown hair and a matching school uniform, freezes in surprise with a deep blush spreading across his face. ``` - **Mode B-1 (`output_format: "json"`, `split_characters: false` or omitted): Single-Prompt JSON** ```json { "aspect_ratio": "2:3", "prompt": "Warm late-afternoon sunlight streams through the tall windows of a quiet classroom, framing the scene from the waist up. Hakurei Reimu, her long black hair tied with a red ribbon and dressed in a neat school uniform, leans down with a gentle smile to press a soft kiss against a young man's cheek. The boy, with short brown hair and a matching school uniform, freezes in surprise with a deep blush spreading across his face." } ``` - **Mode B-2 (`output_format: "json"` + `split_characters: true`): Per-Subject Split JSON** Returns `aspect_ratio`, overall `scene` prose, and an array of foreground subjects (`characters[]`, preserving Danbooru underscore tags in `name` for programmatic lookup or LoRA routing; `null` for unnamed subjects; `[]` for pure landscapes): ```json { "aspect_ratio": "2:3", "scene": "A quiet classroom bathed in warm late-afternoon sunset light streaming through tall windows, framed from the waist up with soft golden highlights across the desks.", "characters": [ { "name": "hakurei_reimu", "prompt": "hakurei reimu, long black hair, red hair ribbon, school uniform; she leans down with a gentle smile to press a soft kiss onto the boy's cheek." }, { "name": null, "prompt": "short brown hair, school uniform, blushing; the boy freezes in surprise as he receives the kiss." } ] } ``` ## Recommended Inference Settings - **Chat Template**: Standard ChatML (non-thinking), stop token `eos_token = "<|im_end|>"`. - **Sampling**: `temperature = 0.7–0.85`, `top_p = 0.90–0.92` (use `0.85–0.90` for higher gacha variance). - **Default System Prompt** (matches training verbatim): ```text You convert anime image tags or structured scene and character inputs into vivid, natural English image-generation prompts. Follow all explicit visible details, character counts, genders, named characters, rating, and optional length, aspect ratio, or style controls. When framing or occlusion hides parts of a character (such as close-up, upper body, from behind, or closed eyes), omit out-of-frame or occluded features from your output. Output pure English prose by default; when output_format is json, return a single valid JSON object with aspect_ratio and prompt (or scene and characters when split_characters is true). ``` - **Strict JSON Output Tip**: When calling Mode B (especially `split` with very long character sheets) via `llama-server` or OpenAI-compatible APIs, pass `response_format: {"type": "json_schema", ...}` to guarantee 100% valid JSON without falling back to prose. ## GGUF Quantizations Standard GGUF quantizations (without imatrix calibration) are hosted directly in this repository for `llama.cpp`, LM Studio, and Ollama: | File | Quant | Size | Notes | |---|---|---:|---| | `PromptGacha-4B-v0.1-Q8_0.gguf` | `Q8_0` | `4.17 GiB` | **Recommended default**, near-lossless, fits full GPU offload on 6GB+ VRAM | | `PromptGacha-4B-v0.1-Q6_K.gguf` | `Q6_K` | `3.23 GiB` | Very low loss, great balance for running alongside image-gen models | | `PromptGacha-4B-v0.1-Q5_K_M.gguf` | `Q5_K_M` | `2.86 GiB` | Compact low-VRAM option (below Q5 is not recommended for this 4B hybrid model) | Quick launch with `llama.cpp`: ```bash llama-server -hf hvgfgh/PromptGacha:Q8_0 -ngl 99 -c 2048 --host 127.0.0.1 --port 8080 --jinja ``` ## Companion Agent Skill This repository ships bilingual companion Agent Skills (compatible with Claude Code, Codex, Pi, Antigravity, and other Skill-enabled agents). Copy either folder into your agent's skills directory: - **English**: [`skills/promptgacha/`](skills/promptgacha/SKILL.md) - **中文 (Chinese)**: [`skills/promptgacha-zh/`](skills/promptgacha-zh/SKILL.md) Highlights: - **First-run self-updating setup**: Guides the agent to connect your local GGUF/HF model path (or pick a quantization by VRAM and install `llama.cpp`), run a smoke test, then write the verified local config into `SKILL.md` and prune the one-time setup section. - **JSON-first gacha workflow**: Ships with the exact training System Prompt, strict Mode B-1 / B-2 `json_schema` definitions, and a zero-dependency client script (`scripts/call_promptgacha.py`) for single or multi-draw gacha runs. ## Performance & Benchmarks There is no formal benchmark yet, though for anime prompt gacha specifically, it's arguably #1 in its niche (and if not, I'll just add a few more qualifiers). ## Training Notes This is my first LLM fine-tuning project—having previously trained image-model LoRAs, adapting an LLM turned out to be a very different beast. Early prototyping was done on [Google Colab](https://colab.research.google.com/), and the `v0.1` release was trained via full-parameter BF16 SFT on an RTX PRO 6000 (with the vision tower stripped prior to training). For a well-scoped task like this, **dataset design is everything**. The dataset went through multiple schema iterations and multi-round LLM auditing to balance three priorities: 1. **Consistency**: Accurate character traits, strict headcount/gender adherence, coherent multi-character interactions, and automatic clipping of out-of-frame or occluded features. 2. **Structure**: Seamless switching between pure prose and structured JSON (including aspect-ratio recommendation, per-subject splitting for [NAI](https://novelai.net/)/[MOSS-Image](https://huggingface.co/OpenMOSS-Team/MOSS-Image-SFT)/regional prompting, and 4-tier length control). 3. **Diversity**: The core of a "gacha" model—without diversity, there's no gacha. Mixing heterogeneous multi-teacher sources and stopping at 1.0 epoch (`eval_loss = 1.640`) preserves the base model's creative variance without collapsing into repetitive phrasing. ## Limitations & Notes - Built specifically for English anime/illustration image-generation prompts; not intended as a general-purpose chat assistant. - `style` defaults to `"off"` (style-neutral). Keep it off if your downstream workflow relies on artist tags or style LoRAs. - **Known `v0.1` limitation**: Out-of-frame and closed-eyes clipping works cleanly in Mode A, whereas in Mode B-2 JSON with full head-to-toe character sheets, the trait prefix before `;` may occasionally retain out-of-frame footwear. This will be addressed in the next release. ## Roadmap 1. **More human-like inputs**: Rewrite a portion of rule-assembled inputs via LLM into natural, messy, real-world user prompts. 2. **One-to-many (multi-output) distillation**: Pair identical sparse inputs with multiple distinct high-quality outputs to push sampling diversity directly at the gradient level. 3. **Dynamic multi-epoch re-rendering + curated annealing**: Prevent repetition overfitting across epochs while strengthening Mode B-2 out-of-frame clipping and custom instruction following. ## License This model is released under a **Non-Commercial Personal Use License** (see [LICENSE](LICENSE)): - **Allowed**: Free for personal, non-commercial use and research. - **Strictly Prohibited**: **Any form of commercial use is forbidden**, including deploying the model commercially, **distilling this model (or its outputs) for commercial use**, or **using prompts generated by this model for any commercial purpose**. ## Acknowledgements 1. [ZAKO-V0.1 (`Johnny-Z/zako-pe`)](https://huggingface.co/Johnny-Z/zako-pe) — inspiration and initial visual prose distillation. 2. [danbooru-tags-2016-2023 (`isek-ai/danbooru-tags-2016-2023`)](https://huggingface.co/datasets/isek-ai/danbooru-tags-2016-2023) — Danbooru tag foundation for stratified sampling. 3. [Qwen (`Qwen3.5-4B-Base`)](https://huggingface.co/Qwen/Qwen3.5-4B-Base) — open-weights base model. 4. [Google](https://www.google.com/) & [Google Colab](https://colab.research.google.com/) — early prototyping compute. 5. [Gemini](https://deepmind.google/models/gemini/) — indispensable coding, auditing, and training co-pilot throughout the project.