--- language: - en license: apache-2.0 tags: - image-generation - contrastive-learning - noun-attributes - steering --- # Noun-Attribute Contrastive Image Dataset Contrastive noun-attribute image pairs with VLM verification. ## How Images Were Collected Images are generated using **FLUX.1-dev**. ### How it was collected - **Noun–attribute pairs**: Predefined binary contrast pairs (e.g. apple: peeled vs unpeeled, bottle: open vs closed). - **Variants for diversity**: - **Base variants**: Different subtypes of the noun (e.g. "a red apple", "a green apple"). - **Scene variants**: Different neutral contexts (e.g. "on a plain studio table", "on a wooden kitchen table"). - **Generation**: For each (noun, attr_a, attr_b) pair, two images are generated with the same seed: one expressing `attr_a`, one expressing `attr_b`. Noun-specific prompt overrides make the attribute contrast clear. ### Usage Filter by `additional_attributes` to select samples with extra visually applicable attributes beyond the target. ## Target-Attribute Verification Generated images are verified for correct target-attribute expression. ### Target verification For each contrastive pair, we verify that: - The image expressing attr_a shows attr_a and not attr_b - The image expressing attr_b shows attr_b and not attr_a ### Additional attributes verification For each image, we evaluate whether *other* candidate attributes (beyond the target) are visually applicable. The dataset is augmented with `additional_attributes` and `additional_confidence` columns for attributes that pass verification. To filter for steering: exclude attributes with <10 samples overall (and their contrastive pairs), then keep only (noun, attr) with ≥10 samples using both `attribute` and `additional_confidence`: ```python from datasets import load_dataset from collections import Counter, defaultdict ds = load_dataset("nirmalendu01/noun-attributes-contrastive", split="train", token=True) MIN_SAMPLES = 10 # Attributes with <10 samples overall and their contrastive pairs (both sides excluded) EXCLUDED_PAIRS = { frozenset({"dirty", "clean"}), frozenset({"plain", "patterned"}), frozenset({"empty", "furnished"}), frozenset({"wrinkled", "pressed"}), frozenset({"empty", "occupied"}) } excluded_attrs = {a for p in EXCLUDED_PAIRS for a in p} # Count (noun, attr) from attribute + additional_confidence noun_attr = Counter() for i in range(len(ds)): noun, attr = ds["noun"][i], ds["attribute"][i] noun_attr[(noun, attr)] += 1 for entry in (ds["additional_confidence"][i] or []): if isinstance(entry, dict) and entry.get("attr"): noun_attr[(noun, entry["attr"])] += 1 # Keep only (noun, attr) with >= MIN_SAMPLES, excluding low-count pairs filtered = {(n, a): c for (n, a), c in noun_attr.items() if c >= MIN_SAMPLES and a not in excluded_attrs} # Filter dataset: keep only rows where (noun, attribute) is in the eligible list eligible_pairs = set(filtered.keys()) keep_idx = [i for i in range(len(ds)) if (ds["noun"][i], ds["attribute"][i]) in eligible_pairs] ds_filtered = ds.select(keep_idx) print(f"Filtered: {len(ds_filtered)} / {len(ds)} rows (eligible nouns and attributes only)") ``` For steerable (attr1 → attr2) pairs, both attributes must have ≥10 samples per noun. See `style_verification_analysis.ipynb` for the full noun–attribute pair mapping (`ADDED_BINARY_BY_NOUN`) and steerable-pair computation. ## Pipeline Summary 1. **Collect** images → contrastive pairs 2. **Verify target attributes** → keep only samples where the intended attribute is correctly expressed 3. **Verify additional attributes** → augment with `additional_attributes` and filter as needed ## Steering Instructions Steering must be done on **contrastive pairs**: each attribute has an opposite (e.g. peeled vs unpeeled). ### Excluded attributes (and their contrastive pairs) Attributes with **<10 total samples** overall are excluded from steering, **along with their contrastive pairs**. This removes: dirty, patterned, furnished, pressed, occupied — and their pairs (clean, plain, empty where paired with furnished/occupied, wrinkled). Both sides of the pair are excluded because the low count makes the contrast unreliable. ### Eligibility rules - For each remaining attribute, only include nouns with **≥10 images** for that attribute. - **Steerable (attr1 → attr2) pairs**: A contrastive pair (attr1, attr2) can be steered on a noun only if **both** attr1 and attr2 have ≥10 samples for that noun. For example, barren→lush cannot be steered on desert if desert has no lush images. - Sample counts use both `attribute` (target) and `additional_confidence` (extra attrs per image). ### Steering steps 1. **Pick an attribute and anchor image**: Choose an attribute from the eligible list and an image that expresses it. 2. **Add the contrastive steering vector**: Compute the steering direction toward the contrast attribute (e.g. peeled → unpeeled). 3. **Evaluate**: - **Pa@K**: Precision at K for the contrast attribute (does the steered output show the contrast attr?). - **Pc@K**: Precision at K for noun retention (is the noun still present and recognizable?). ### Steerable (attr1 → attr2) pairs (both attrs ≥10 per noun) Using `attribute` + `additional_confidence` for sample counts: | attr1 → attr2 | nouns (min count) | |---------------|-------------------| | cluttered → tidy | garage(41), basement(15), kitchen(13) | | foggy → clear | lake(19) | | folded → unfolded | shirt(23) | | frozen → thawed | lake(13) | | open → closed | bucket(54), pot(41), bottle(27), bag(22), gate(20), road(20), street(20), door(19), garage(18), shower(16), window(15), town(14), box(12), book(11), library(10) | | peeled → unpeeled | banana(17) | | shattered → intact | glass(15), bowl(10) | | sunny → overcast | lake(18) | | toppled → upright | bottle(16), bucket(16), house(10) | Filter the dataset to keep only these steerable (noun, attr) pairs: ```python from datasets import load_dataset STEERABLE = { ("cluttered", "tidy"): ["garage", "basement", "kitchen"], ("foggy", "clear"): ["lake"], ("folded", "unfolded"): ["shirt"], ("frozen", "thawed"): ["lake"], ("open", "closed"): ["bucket", "pot", "bottle", "bag", "gate", "road", "street", "door", "garage", "shower", "window", "town", "box", "book", "library"], ("peeled", "unpeeled"): ["banana"], ("shattered", "intact"): ["glass", "bowl"], ("sunny", "overcast"): ["lake"], ("toppled", "upright"): ["bottle", "bucket", "house"], } steerable_pairs = {(n, a) for (a1, a2), nouns in STEERABLE.items() for n in nouns for a in (a1, a2)} ds = load_dataset("nirmalendu01/noun-attributes-contrastive", split="train", token=True) keep_idx = [i for i in range(len(ds)) if (ds["noun"][i], ds["attribute"][i]) in steerable_pairs] ds_steerable = ds.select(keep_idx) print(f"Steerable subset: {len(ds_steerable)} / {len(ds)} rows") ```