simit 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ """Prompts of the SIMIT synthesis pipeline (triplet synthesis, critic,
2
+ description revision), unchanged from the paper's code."""
3
+
4
+ import re
5
+
6
+ # Triplet synthesis (Appendix G.1). ``{K}`` is the number of triplets requested.
7
+ TRIPLET_PROMPT = (
8
+ "I will give you an image. "
9
+ "Generate exactly {K} diverse visual question-answering training examples.\n\n"
10
+ "Each example must have:\n"
11
+ "- A visual question (about any visual concept — NOT tied to the given image)\n"
12
+ "- A short correct answer\n"
13
+ "- A detailed description of a new image where your question and answer are correct, your description should be detailed and specific, one should be able to visualize the image perfectly from the description\n\n"
14
+ "DIVERSITY RULES:\n"
15
+ "- Cover as many different visual reasoning types as possible across the {K} examples:\n"
16
+ " counting, color/attribute, spatial position, object recognition, action/activity,\n"
17
+ " text/OCR, yes/no judgment, comparison, scene type, etc.\n"
18
+ "- Use the provided image only as inspiration for difficulty level and visual domain.\n"
19
+ " The generated examples do NOT need to match the provided image.\n"
20
+ "- Answers must be short (1-5 words).\n\n"
21
+ "Output format (blank line between examples):\n\n"
22
+ "Question: [your visual question]\n"
23
+ "Answer: [short correct answer]\n"
24
+ "Description: [detailed description of a new image where question+answer are correct]\n\n"
25
+ "Question: [another diverse visual question]\n"
26
+ "Answer: [short correct answer]\n"
27
+ "Description: [description for this example]\n\n"
28
+ "... (exactly {K} Question/Answer/Description triples)"
29
+ )
30
+
31
+ # Ablation without diversity-encouraging prompting (Table 2, "w/o DP").
32
+ TRIPLET_PROMPT_NO_DIVERSITY = (
33
+ "I will give you an image. "
34
+ "Generate exactly {K} visual question-answering training examples.\n\n"
35
+ "Each example must have:\n"
36
+ "- A visual question (about any visual concept — NOT tied to the given image)\n"
37
+ "- A short correct answer\n"
38
+ "- A detailed description of a new image where your question and answer are correct, your description should be detailed and specific, one should be able to visualize the image perfectly from the description\n\n"
39
+ " The generated examples do NOT need to match the provided image.\n"
40
+ "- Answers must be short (1-5 words).\n\n"
41
+ "Output format (blank line between examples):\n\n"
42
+ "Question: [your visual question]\n"
43
+ "Answer: [short correct answer]\n"
44
+ "Description: [detailed description of a new image where question+answer are correct]\n\n"
45
+ "Question: [another visual question]\n"
46
+ "Answer: [short correct answer]\n"
47
+ "Description: [description for this example]\n\n"
48
+ "... (exactly {K} Question/Answer/Description triples)"
49
+ )
50
+
51
+ FORMAT_REMINDER = (
52
+ "\n\nIMPORTANT: your previous response did not follow the required output "
53
+ "format. Output ONLY plain text in exactly this form, nothing else -- no "
54
+ "markdown bold, no numbering, no preamble or summary:\n\n"
55
+ "Question: ...\nAnswer: ...\nDescription: ...\n\n"
56
+ "Question: ...\nAnswer: ...\nDescription: ...\n\n(blank line between each of the {K} examples)"
57
+ )
58
+
59
+ # Tolerates "Example N:" lines and "1. " numbering between triplets.
60
+ TRIPLET_RE = re.compile(
61
+ # BAGEL doesn't always follow the literal template -- observed variants
62
+ # include a leading "Example N:" line and "1. " numbering before
63
+ # "Question:". Tolerating these in the boundary lookahead (not just the
64
+ # leading match) matters most: without it, example 1's Description
65
+ # swallows the rest of the response, since the lookahead never finds a
66
+ # bare "Question:" to stop at, silently dropping examples 2..K instead
67
+ # of just losing the formatting on one field. Markdown bold markers
68
+ # ("**Question:**", "**Question**:", ...) are stripped separately before
69
+ # matching -- they showed up wrapping the keyword in inconsistent
70
+ # positions, so stripping "**" outright is far more robust than trying
71
+ # to enumerate every position they can appear in.
72
+ r"Question:\s*(.+?)\nAnswer:\s*(.+?)\nDescription:\s*(.+?)"
73
+ r"(?=\n\n(?:\d+[.)]\s*|Example\s+\d+:?\s*\n)?Question:|\Z)",
74
+ re.DOTALL | re.IGNORECASE,
75
+ )
76
+
77
+ # Critic rubrics: strict (natural photos) and structural (rendered visuals).
78
+ CRITIC_STRICT_PROMPT = (
79
+ 'You are a strict quality-control critic scoring an AI-generated image against this brief: "{request}"\n\n'
80
+ "Go through the brief clause by clause. For each specific, checkable detail "
81
+ "(counts, colors, species, objects, setting, text, spatial relations), state "
82
+ "whether the image satisfies it, with no tolerance for approximation. List "
83
+ "every discrepancy you find, however small.\n\n"
84
+ "Then assign a single quality SCORE from 0 to 100 using this rubric:\n"
85
+ " 90-100: every checkable detail in the brief is satisfied, no discrepancies\n"
86
+ " 70-89: matches the brief overall, only minor/cosmetic discrepancies "
87
+ "(e.g. slightly off shade, imprecise count in a busy/cluttered scene)\n"
88
+ " 40-69: matches part of the brief but has at least one clear factual "
89
+ "discrepancy (wrong count, wrong object, wrong text, wrong spatial relation)\n"
90
+ " 0-39: mostly or entirely fails to match the brief\n\n"
91
+ "End your answer with exactly one line: 'SCORE: <integer 0-100>'."
92
+ )
93
+
94
+ CRITIC_STRUCTURED_PROMPT = (
95
+ 'You are a quality-control critic scoring an AI-generated chart/diagram/figure '
96
+ 'against this brief: "{request}"\n\n'
97
+ "This image is being generated as training data by first asking a model for a "
98
+ "detailed description (which may invent specific numbers/labels/statistics), then "
99
+ "asking a separate model to write code that renders that description. The exact "
100
+ "numeric values, colors, or specific labels in the brief are NOT required to match "
101
+ "precisely -- do not penalize the image for a different number, value, or label than "
102
+ "the brief states. Judge STRUCTURAL correctness only:\n"
103
+ "- Is it the right TYPE of visualization (e.g. bar chart vs line chart vs pie chart vs "
104
+ "diagram vs table), matching what the brief describes?\n"
105
+ "- Does it have the general elements the brief mentions (e.g. axis labels, a title, "
106
+ "the right number of categories/bars/nodes, a legend if described)?\n"
107
+ "- Is the image coherent and readable, with no garbled text, broken layout, or "
108
+ "rendering artifacts?\n\n"
109
+ "Then assign a single quality SCORE from 0 to 100 using this rubric:\n"
110
+ " 90-100: right visualization type, all described structural elements present, clean and readable\n"
111
+ " 70-89: right visualization type with the described elements, but missing one minor "
112
+ "structural element (e.g. no legend when one was implied) or slightly cluttered\n"
113
+ " 40-69: right general visualization type but missing a clearly-described structural "
114
+ "element, or somewhat hard to read\n"
115
+ " 0-39: wrong visualization type entirely, or broken/garbled/unreadable rendering\n\n"
116
+ "End your answer with exactly one line: 'SCORE: <integer 0-100>'."
117
+ )
118
+
119
+ REVISE_PROMPT = (
120
+ 'This image description was used to generate an image: "{request}"\n'
121
+ 'A critic reviewed the generated image and found these problems:\n"{critique}"\n\n'
122
+ "Rewrite the description, keeping everything that was already correct, but "
123
+ "adding or changing whatever is needed so the next generation avoids these "
124
+ "exact problems. Output ONLY the revised description text, nothing else."
125
+ )
126
+
127
+
128
+ # Decomposed triplet synthesis for models that only follow short single-turn
129
+ # instructions (used for Lance in the paper's cross-model study): question,
130
+ # answer and description come from three separate calls.
131
+ DECOMPOSED_TOPICS = [
132
+ "counting", "color or attribute", "spatial position", "object recognition",
133
+ "action or activity", "text or OCR", "a yes/no judgment", "comparison", "scene type",
134
+ ]
135
+
136
+ DECOMPOSED_QUESTION_PROMPT = (
137
+ "Here are examples of short visual questions used to test other pictures:\n"
138
+ "- How many birds are on the wire?\n"
139
+ "- What color is the umbrella?\n"
140
+ "- Is the door open or closed?\n\n"
141
+ "Write ONE new short visual question about {topic}, on a completely "
142
+ "different topic than this image -- the question does NOT need to match "
143
+ "this image, use it only as inspiration for difficulty level and domain. "
144
+ "Output only the question, nothing else."
145
+ )
146
+ DECOMPOSED_ANSWER_PROMPT = (
147
+ 'Give a short 1-5 word answer to this question, as if answering about '
148
+ 'some other picture: "{question}"\n{type_hint}Output only the answer, nothing else.'
149
+ )
150
+ DECOMPOSED_DESCRIPTION_PROMPT = (
151
+ 'Imagine a different picture. In that picture, the question "{question}" '
152
+ 'has the answer "{answer}". Describe that picture in detail: what it '
153
+ "shows, the setting, colors, and objects."
154
+ )
155
+
156
+ COORD_LIST_RE = re.compile(r"^[\d.,\[\]\s-]+$")
157
+
158
+ META_LEAK_RE = re.compile(
159
+ r"\bquestion (about|is)\b|excellent question|as i mentioned|short visual question|different topic than this image",
160
+ re.IGNORECASE,
161
+ )
162
+
163
+ ANSWER_TYPE_HINTS = [
164
+ (re.compile(r"^how many\b", re.IGNORECASE), "Answer with just a number. "),
165
+ (re.compile(r"^(what|which) color", re.IGNORECASE), "Answer with just a color name. "),
166
+ (re.compile(r"^(is|are|do|does|can|will|was|were|has|have)\b", re.IGNORECASE), "Answer with Yes or No. "),
167
+ ]
@@ -0,0 +1,6 @@
1
+ """Skill library: turn image descriptions into images."""
2
+
3
+ from .base import Realization, Skill, SpecError, extract_fenced_block
4
+ from .builtin import BUILTIN_SKILLS, default_skills
5
+
6
+ __all__ = ["Skill", "SpecError", "Realization", "extract_fenced_block", "BUILTIN_SKILLS", "default_skills"]
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 - 2022 Knut Sveidqvist
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.