Views
No views yet
["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]pip install transformers torch1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2import torch
3
4model_path = "kawchar85/SmolLM2-1.7B-Instruct-TIFA-Random"
5
6# Load model and tokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
8tokenizer.pad_token = tokenizer.eos_token
9tokenizer.padding_side = "right"
10
11model = AutoModelForCausalLM.from_pretrained(
12 model_path,
13 torch_dtype=torch.float16,
14 trust_remote_code=True,
15 device_map="auto"
16)
17
18# Create pipeline
19chat_pipe = pipeline(
20 "text-generation",
21 model=model,
22 tokenizer=tokenizer,
23 return_full_text=False,
24)
25
26def get_message(description):
27 system = """\
28You are a TIFA (Text-to-Image Faithfulness evaluation with question Answering) question generator. Given an image description, create exactly 4 visual verification questions with multiple choice answers. Each question should test different visual aspects that can be verified by looking at the image.
29
30Guidelines:
31- Focus on colors, shapes, objects, materials, spatial relationships, and other visually verifiable elements
32- Mix yes/no questions (2 choices: "no", "yes") and multiple choice questions (4 choices)
33- Each question should test a DIFFERENT aspect of the description
34- Ensure questions can be answered by visual inspection of the image
35- Use elements explicitly mentioned in the description
36- Include both positive verification (testing presence, answer: "yes") and negative verification (testing absence, answer: "no")
37- Make distractors realistic and relevant to the domain
38
39Format each question as:
40Q[number]: [question text]
41C: [comma-separated choices]
42A: [correct answer]
43
44Generate questions that test visual faithfulness between the description and image."""
45
46 user_msg = f'Create 4 visual verification questions for this description: "{description}"'
47 return [
48 {"role": "system", "content": system},
49 {"role": "user", "content": user_msg}
50 ]
51
52# Generate evaluation questions
53description = "a lighthouse overlooking the ocean"
54messages = get_message(description)
55
56output = chat_pipe(
57 messages,
58 max_new_tokens=256,
59 do_sample=False,
60)
61
62print(output[0]["generated_text"])Q1: What type of structure is prominently featured?
C: windmill, lighthouse, tower, castle
A: lighthouse
Q2: What body of water is visible?
C: lake, river, ocean, pond
A: ocean
Q3: Is the lighthouse positioned above the water?
C: no, yes
A: yes
Q4: Are there any mountains in the scene?
C: no, yes
A: no1@misc{smollm2-1-7b-it-tifa-random-2025,
2 title={SmolLM2-1.7B-Instruct-TIFA-Random: Flexible Question Generation for Text-to-Image Faithfulness Assessment},
3 author={kawchar85},
4 year={2025},
5 url={https://huggingface.co/kawchar85/SmolLM2-1.7B-Instruct-TIFA-Random}
6}