Downloads · 30 days
19
13% of all-time downloads
Elldreth/danbooru-tag-implications-flan-t5
danbooru-tag-implications-flan-t5 is a machine learning model from Elldreth. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
A FLAN-T5 Base model fine-tuned to predict Danbooru tag implications. Given a tag, the model outputs all tags that it implies according to Danbooru's tag implication system.
Downloads · 30 days
19
13% of all-time downloads
All-time downloads
152
Public
Parameters
248M
991 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors990 MB · 99%
From the Hugging Face model README
A FLAN-T5 Base model fine-tuned to predict Danbooru tag implications. Given a tag, the model outputs all tags that it implies according to Danbooru's tag implication system.
This model learns the structured relationships between Danbooru tags, specifically the "implication" relationships where one tag automatically implies another. For example:
bikini implies swimsuitcat_ears implies animal_earsstriped_panties implies both panties and striped_clothesBase Model: google/flan-t5-base (248M parameters)
Training Data: 32,331 tag implication pairs from Danbooru
Task Format: implications: <tag> <implied_tag1>, <implied_tag2>, ...
Seq2SeqTrainingArguments(
per_device_train_batch_size=16,
per_device_eval_batch_size=16,
learning_rate=5e-5,
num_train_epochs=3,
bf16=True,
predict_with_generate=True,
generation_max_length=128,
generation_num_beams=4,
)
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_name = "Elldreth/danbooru-tag-implications-flan-t5"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
def get_implications(tag):
input_text = f"implications: {tag}"
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=128, num_beams=4)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Examples
print(get_implications("bikini")) # Output: swimsuit
print(get_implications("cat_ears")) # Output: animal_ears
print(get_implications("striped_panties")) # Output: panties, striped_clothes
def expand_tags(tags_string):
"""Expand all tags in a comma-separated string"""
tags = [t.strip() for t in tags_string.split(',')]
expanded = set(tags)
for tag in tags:
implications = get_implications(tag)
if implications:
expanded.update([t.strip() for t in implications.split(',')])
return ', '.join(sorted(expanded))
# Example
input_tags = "1girl, bikini, cat_ears"
expanded_tags = expand_tags(input_tags)
print(expanded_tags)
# Output: 1girl, animal_ears, bikini, cat_ears, swimsuit
The model was trained on specific Danbooru tags. For production use, you should only query tags that exist in the training data to avoid hallucinations:
import json
# Load the training dataset to get valid tags
tags_with_implications = set()
with open('tag_implications_dataset.jsonl', 'r') as f:
for line in f:
data = json.loads(line)
tag = data['input'].replace('implications: ', '')
tags_with_implications.add(tag)
def get_implications_safe(tag):
if tag not in tags_with_implications:
return "" # Tag has no known implications
return get_implications(tag)
| Input | Output |
|---|---|
bikini | swimsuit |
school_swimsuit | swimsuit |
sleeveless_dress | dress, sleeveless |
striped_panties | panties, striped_clothes |
| Input | Output |
|---|---|
cat_ears | animal_ears |
dog_ears | animal_ears |
fox_tail | tail |
| Input | Output |
|---|---|
striped_bikini | bikini, striped_clothes, swimsuit |
black_dress | dress |
To prevent generic tags from suggesting series-specific tags, we applied this rule:
bikini won't suggest swimsuit_(series_name)If you use this model, please cite the Danbooru tag implications data:
Danbooru Tag Implications Database
https://danbooru.donmai.us/
Apache 2.0 - Same as the base FLAN-T5 model
Created as part of the Danbooru Tag Expander project for ComfyUI.