Skip to content

webshart: custom caption key(s) for multicaption support - #3208

Merged
bghira merged 2 commits into
mainfrom
feature/webshart-multiple-captions
Sep 6, 2026
Merged

bghira merged 2 commits into
mainfrom
feature/webshart-multiple-captions

Conversation

@bghira

@bghira bghira commented Sep 6, 2026

Copy link
Copy Markdown
Owner

This pull request introduces support for selecting specific caption fields from Webshart datasets using a new caption_key option. The change is implemented across the data backend, configuration, and documentation in multiple languages. The new feature allows users to specify which caption fields to use, supporting both single and multiple keys, with robust validation and handling in the backend code. Documentation has been updated to explain the new option and its behavior in detail.

Feature: Webshart caption key selection

  • Added a new webshart.caption_key option to the configuration (ImageBackendConfig, config parsing, and serialization) to allow users to specify one or more caption fields to extract from Webshart metadata. This includes validation to ensure the key(s) are non-empty strings or lists of non-empty strings. [1] [2] [3] [4]
  • Updated the WebshartDataBackend to accept and use the caption_key parameter. The backend now extracts the specified caption fields in priority order, normalizes them, and returns them as variants (not concatenated), with correct fallback and sidecar reading logic. [1] [2] [3] [4]
  • Ensured that the caption_key setting is included in backend instance representations and restored correctly from serialization. [1] [2]
  • Modified the backend builder to pass the caption_key from config to the backend.

Documentation updates

  • Expanded documentation in all supported languages (English, Spanish, Hindi, Japanese, Portuguese, Chinese) to describe the new webshart.caption_key option, its usage, lookup order, and effects on caching and sample selection. [1] [2] [3] [4] [5] [6]

Other minor changes

  • Added sha256 import in simpletuner/helpers/metadata/backends/webshart.py

CI regression: Webshart 0.5.3 discards unknown fields placed directly on an index entry. The failing fixture depended on unreleased Webshart support for those fields. The fixtures now store literal custom keys in json_metadata and its nested captions dictionary, and exercise direct index lookup using the supported captions field. The dataloader documentation and all translations clarify this storage requirement.

Validation: reproduced the original assertion failure using the published Webshart 0.5.3 wheel, then passed all 105 tests in tests.test_webshart_backend, tests.test_backend_builders, tests.test_prompts, and tests.test_prompthandler against that same isolated wheel. Black, isort, and the staged diff check passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It changes caption resolution and cache-file keying in the core training data pipeline and relies on external webshart reader APIs (open_shard/read_sample_json) that cannot be verified from this checkout, so human sign-off is warranted despite strong test coverage.

Pull request overview

This PR adds a webshart.caption_key dataset option that lets users select which caption field(s) to extract from Webshart metadata, supporting a single key or an ordered list of keys for multicaption training. The feature threads through configuration parsing/serialization, validation, the backend builder, both the data and metadata backends, the WebUI dataset templates, and documentation in all supported languages. Selected captions are returned as variants (not concatenated), with sidecar JSON reads on demand and cache files partitioned by a hash of the selected keys so different selections don't collide.

Changes:

  • New caption_key option with validation, config round-trip, builder pass-through, and backend resolution via _select_caption_keys (priority: JSON metadata → indexed metadata → captions dicts).
  • WebUI textarea (one key per line) plus store logic to persist single-string vs list values; cache/metadata files suffixed with a sha256 digest of the key selection.
  • Documentation (DATALOADER.md + zh/pt-BR/ja/hi/es) and comprehensive unit, integration, and E2E tests.
File summaries
File Description
simpletuner/helpers/data_backend/webshart.py Adds caption_key param, _select_caption_keys, sidecar JSON read, and instance-representation round-trip
simpletuner/helpers/metadata/backends/webshart.py Digest-based cache-file separation, caption override in _metadata_for_entry, and skip logic when keys are set
simpletuner/helpers/data_backend/config/validators.py New validate_webshart_caption_key validation
simpletuner/helpers/data_backend/config/image.py Config field, parsing, and serialization for caption_key
simpletuner/helpers/data_backend/builders/webshart.py Passes caption_key from config to the backend
simpletuner/templates/components/dataloader/webshart_caption_key.html New textarea component for caption keys
simpletuner/templates/components/dataloader/sections/storage.html, storage_body.html Include the new component in inline/modal views; extends param filter
simpletuner/static/js/dataloader-section-component.js setWebshartCaptionKeys normalizes textarea input to string/list
simpletuner/templates/trainer_htmx.html Serializes caption_key on save
documentation/DATALOADER.md (+ zh/pt-BR/ja/hi/es) Documents the new option in all languages
tests/test_webshart_backend.py, tests/test_webui_e2e.py Unit, integration, and E2E coverage
Review details
  • Files reviewed: 18/18 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bghira
bghira merged commit a6cc6a0 into main Sep 6, 2026
4 checks passed
@bghira
bghira deleted the feature/webshart-multiple-captions branch September 6, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants