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:
|
| 4 |
+
- HuggingFaceTB/SmolLM2-135M-Instruct
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- text-to-image-evaluation
|
| 8 |
+
- faithfulness
|
| 9 |
+
- lora
|
| 10 |
+
- tifa
|
| 11 |
+
language: en
|
| 12 |
+
---
|
| 13 |
+
# SmolLM2-135M-Instruct-TIFA
|
| 14 |
+
|
| 15 |
+
## Model Description
|
| 16 |
+
|
| 17 |
+
SmolLM2-135M-Instruct-TIFA is a fine-tuned version of [HuggingFaceTB/SmolLM2-135M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct) specifically trained for **TIFA (Text-to-Image Faithfulness Assessment)**. This model generates structured evaluation questions to assess how faithfully text-to-image models represent given text descriptions.
|
| 18 |
+
|
| 19 |
+
## Intended Use
|
| 20 |
+
|
| 21 |
+
This model is designed to automatically generate evaluation questions for text-to-image models by creating four specific types of questions:
|
| 22 |
+
|
| 23 |
+
1. **Negative question**: Should have "no" as the answer
|
| 24 |
+
2. **Object identification**: Should have a single word answer directly from the description
|
| 25 |
+
3. **Attribute identification**: Should have a single word answer directly from the description
|
| 26 |
+
4. **Positive question**: Should have "yes" as the answer
|
| 27 |
+
|
| 28 |
+
## Model Details
|
| 29 |
+
|
| 30 |
+
- **Base Model**: HuggingFaceTB/SmolLM2-135M-Instruct
|
| 31 |
+
- **Model Size**: 135M parameters
|
| 32 |
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
| 33 |
+
- **Training Framework**: Transformers + TRL + PEFT
|
| 34 |
+
- **License**: apache-2.0
|
| 35 |
+
|
| 36 |
+
## Training Details
|
| 37 |
+
|
| 38 |
+
### Training Configuration
|
| 39 |
+
- **Training Method**: Supervised Fine-Tuning (SFT) with LoRA
|
| 40 |
+
- **LoRA Configuration**:
|
| 41 |
+
- r: 16
|
| 42 |
+
- lora_alpha: 32
|
| 43 |
+
- lora_dropout: 0.05
|
| 44 |
+
- Target modules: `["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]`
|
| 45 |
+
|
| 46 |
+
- **Training Parameters**:
|
| 47 |
+
- Epochs: 4
|
| 48 |
+
- Learning Rate: 2e-4
|
| 49 |
+
- Batch Size: 8 (per device)
|
| 50 |
+
- Gradient Accumulation Steps: 2
|
| 51 |
+
- Max Sequence Length: 512
|
| 52 |
+
- Optimizer: AdamW
|
| 53 |
+
- Weight Decay: 0.01
|
| 54 |
+
- Warmup Steps: 200
|
| 55 |
+
|
| 56 |
+
### Dataset
|
| 57 |
+
The model was trained on a structured dataset containing 5,000 examples created using Gemini, formatted as conversation data in JSONL format.
|
| 58 |
+
|
| 59 |
+
## Usage
|
| 60 |
+
|
| 61 |
+
### Installation
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
pip install transformers torch
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### Basic Usage
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 71 |
+
import torch
|
| 72 |
+
|
| 73 |
+
model_path = "kawchar85/SmolLM2-135M-Instruct-TIFA"
|
| 74 |
+
|
| 75 |
+
# Load model and tokenizer
|
| 76 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 77 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 78 |
+
model_path,
|
| 79 |
+
torch_dtype=torch.float16,
|
| 80 |
+
trust_remote_code=True,
|
| 81 |
+
device_map="auto"
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
# Create pipeline
|
| 85 |
+
pipe = pipeline(
|
| 86 |
+
"text-generation",
|
| 87 |
+
model=model,
|
| 88 |
+
tokenizer=tokenizer,
|
| 89 |
+
device=0 if torch.cuda.is_available() else -1,
|
| 90 |
+
return_full_text=False,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# Generate evaluation questions
|
| 94 |
+
description = "khaki triangles and azure crescents"
|
| 95 |
+
user_msg = (
|
| 96 |
+
f"Create 4 questions to evaluate a text-to-image model's faithfulness to this description: "
|
| 97 |
+
f'"{description}".\n'
|
| 98 |
+
"The first question should have 'no' as the answer, "
|
| 99 |
+
"the second and third questions should have answers that are a single word directly taken "
|
| 100 |
+
"from the description, and the fourth question should have 'yes' as the answer."
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
messages = [{"role": "user", "content": user_msg}]
|
| 104 |
+
|
| 105 |
+
output = pipe(
|
| 106 |
+
messages,
|
| 107 |
+
max_new_tokens=256,
|
| 108 |
+
do_sample=False,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
print(output[0]["generated_text"])
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
### Example Output
|
| 115 |
+
|
| 116 |
+
For the description "khaki triangles and azure crescents", the model generates:
|
| 117 |
+
|
| 118 |
+
```
|
| 119 |
+
Q1: Are the triangles green?
|
| 120 |
+
Choices: ['no', 'yes']
|
| 121 |
+
Answer: no
|
| 122 |
+
Q2: What color are the triangles?
|
| 123 |
+
Choices: ['blue', 'red', 'khaki', 'green']
|
| 124 |
+
Answer: khaki
|
| 125 |
+
Q3: What shape are the objects?
|
| 126 |
+
Choices: ['squares', 'circles', 'crescents', 'triangles']
|
| 127 |
+
Answer: crescents
|
| 128 |
+
Q4: Are there azure crescents in the image?
|
| 129 |
+
Choices: ['no', 'yes']
|
| 130 |
+
Answer: yes
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## Limitations
|
| 134 |
+
|
| 135 |
+
- The model is specialized for TIFA evaluation and may not perform well on general conversation tasks
|
| 136 |
+
- Limited to generating 4-question evaluation sets in the trained format
|
| 137 |
+
- Performance depends on the quality and diversity of the training dataset
|
| 138 |
+
- Sometimes generates duplicated questions for Q2 and Q3 due to the small dataset used for training or model knowledge limitations
|
| 139 |
+
|
| 140 |
+
## Technical Specifications
|
| 141 |
+
|
| 142 |
+
- **Architecture**: Transformer-based language model
|
| 143 |
+
- **Precision**: FP16
|
| 144 |
+
- **Context Length**: 512 tokens
|
| 145 |
+
- **Inference Speed**: Optimized for quick question generation
|
| 146 |
+
|
| 147 |
+
## Citation
|
| 148 |
+
|
| 149 |
+
```bibtex
|
| 150 |
+
@misc{smollm2-135m-it-tifa-2025,
|
| 151 |
+
title={SmolLM2-135M-Instruct-TIFA: A Fine-tuned Model for Text-to-Image Faithfulness Assessment},
|
| 152 |
+
author={kawchar85},
|
| 153 |
+
year={2025},
|
| 154 |
+
url={https://huggingface.co/kawchar85/SmolLM2-135M-Instruct-TIFA}
|
| 155 |
+
}
|
| 156 |
+
```
|