code-conflict / generate_batch.py
akanshjain37's picture
Rebuild dataset using standard train/ ImageFolder layout
ab4bfa5 verified
Raw
History Blame Contribute Delete
73 kB
import os
import sys
import csv
import subprocess
def get_templates():
templates = []
# ==========================================
# CATEGORY 1: operator_substitution (20 items)
# ==========================================
templates.extend([
{
"func_name": "calculate_total",
"code_text": "def calculate_total(price, tax):\n # Add tax to base price\n return price + tax",
"type": "operator_substitution",
"desc": "Changed addition (+) to subtraction (-)",
"original_caption": "This function calculates the total by adding tax to the price.",
"conflicting_caption": "This function calculates the total by subtracting tax from the price.",
"question": "How does the function calculate the total using price and tax?",
"image_bias": "By adding tax to the price",
"text_bias": "By subtracting tax from the price",
"distractor": "By multiplying price by tax"
},
{
"func_name": "check_even",
"code_text": "def check_even(n):\n # Return true if even\n return n % 2 == 0",
"type": "operator_substitution",
"desc": "Changed equality (==) to inequality (!=)",
"original_caption": "This function returns True if the number n is even.",
"conflicting_caption": "This function returns True if the number n is odd.",
"question": "What kind of numbers does this function return True for?",
"image_bias": "Even numbers",
"text_bias": "Odd numbers",
"distractor": "Prime numbers"
},
{
"func_name": "apply_discount",
"code_text": "def apply_discount(price, discount):\n # Subtract discount amount\n return price - discount",
"type": "operator_substitution",
"desc": "Changed subtraction (-) to addition (+)",
"original_caption": "This function reduces the price by subtracting the discount.",
"conflicting_caption": "This function increases the price by adding the discount.",
"question": "What action does this function perform on the price with the discount?",
"image_bias": "Reduces price by subtracting discount",
"text_bias": "Increases price by adding discount",
"distractor": "Multiplies price by discount percentage"
},
{
"func_name": "is_adult",
"code_text": "def is_adult(age):\n # Threshold for adulthood\n return age >= 18",
"type": "operator_substitution",
"desc": "Changed greater-than-or-equal (>=) to less-than (<)",
"original_caption": "This function checks if the user's age is 18 or older.",
"conflicting_caption": "This function checks if the user's age is under 18.",
"question": "What age group does this function check for?",
"image_bias": "18 or older",
"text_bias": "Under 18",
"distractor": "Exactly 18"
},
{
"func_name": "has_access",
"code_text": "def has_access(is_admin, is_owner):\n # Needs at least one permission\n return is_admin or is_owner",
"type": "operator_substitution",
"desc": "Changed logical 'or' to 'and'",
"original_caption": "This function allows access if the user is either an admin or the owner.",
"conflicting_caption": "This function allows access only if the user is both an admin and the owner.",
"question": "What permissions are required to gain access?",
"image_bias": "Either admin or owner",
"text_bias": "Both admin and owner",
"distractor": "Neither admin nor owner"
},
{
"func_name": "compute_ratio",
"code_text": "def compute_ratio(a, b):\n # Divide a by b\n return a / b",
"type": "operator_substitution",
"desc": "Changed division (/) to multiplication (*)",
"original_caption": "This function calculates the ratio by dividing a by b.",
"conflicting_caption": "This function calculates the product by multiplying a by b.",
"question": "What operation is performed on variables a and b?",
"image_bias": "Division",
"text_bias": "Multiplication",
"distractor": "Addition"
},
{
"func_name": "decrement_counter",
"code_text": "def decrement_counter(c):\n # Decrease counter by one\n return c - 1",
"type": "operator_substitution",
"desc": "Changed subtraction (-) to addition (+)",
"original_caption": "This function decrements the counter by subtracting 1.",
"conflicting_caption": "This function increments the counter by adding 1.",
"question": "What happens to the counter value when this function runs?",
"image_bias": "Decreases by 1",
"text_bias": "Increases by 1",
"distractor": "Doubles in value"
},
{
"func_name": "is_leap_year",
"code_text": "def is_leap_year(y):\n # Simple check for leap year\n return y % 4 == 0",
"type": "operator_substitution",
"desc": "Changed equality (==) to inequality (!=)",
"original_caption": "This function returns True if the year is divisible by 4.",
"conflicting_caption": "This function returns True if the year is not divisible by 4.",
"question": "When does this function return True?",
"image_bias": "Divisible by 4",
"text_bias": "Not divisible by 4",
"distractor": "Divisible by 100"
},
{
"func_name": "is_underage",
"code_text": "def is_underage(age):\n # Check if age is under 18\n return age < 18",
"type": "operator_substitution",
"desc": "Changed less-than (<) to greater-than-or-equal (>=)",
"original_caption": "This function returns True if the age is less than 18.",
"conflicting_caption": "This function returns True if the age is 18 or older.",
"question": "Under what condition does this function return True?",
"image_bias": "Age is under 18",
"text_bias": "Age is 18 or older",
"distractor": "Age is exactly 0"
},
{
"func_name": "check_empty",
"code_text": "def check_empty(s):\n # Return true if string is empty\n return len(s) == 0",
"type": "operator_substitution",
"desc": "Changed equality (==) to inequality (!=)",
"original_caption": "This function checks if the length of the string is exactly 0.",
"conflicting_caption": "This function checks if the length of the string is not 0.",
"question": "What string length does this function look for to return True?",
"image_bias": "Exactly 0",
"text_bias": "Not 0",
"distractor": "Greater than 10"
},
{
"func_name": "is_strict_positive",
"code_text": "def is_strict_positive(x):\n # Check if strictly positive\n return x > 0",
"type": "operator_substitution",
"desc": "Changed greater-than (>) to less-than (<)",
"original_caption": "This function returns True if x is strictly greater than 0.",
"conflicting_caption": "This function returns True if x is strictly less than 0.",
"question": "For what values of x does this function return True?",
"image_bias": "Greater than 0",
"text_bias": "Less than 0",
"distractor": "Equal to 0"
},
{
"func_name": "double_value",
"code_text": "def double_value(x):\n # Double the input\n return x * 2",
"type": "operator_substitution",
"desc": "Changed multiplication (*) to division (/)",
"original_caption": "This function doubles the value by multiplying by 2.",
"conflicting_caption": "This function halves the value by dividing by 2.",
"question": "What effect does this function have on the input value?",
"image_bias": "Multiplies by 2",
"text_bias": "Divides by 2",
"distractor": "Squares the value"
},
{
"func_name": "is_negative",
"code_text": "def is_negative(val):\n # Check negative status\n return val < 0",
"type": "operator_substitution",
"desc": "Changed less-than (<) to greater-than (>)",
"original_caption": "This function checks if the value is less than 0.",
"conflicting_caption": "This function checks if the value is greater than 0.",
"question": "What range of values does this function check for?",
"image_bias": "Less than 0",
"text_bias": "Greater than 0",
"distractor": "Exactly 0"
},
{
"func_name": "is_divisor",
"code_text": "def is_divisor(a, b):\n # Checks division remainder\n return a % b == 0",
"type": "operator_substitution",
"desc": "Changed equality (==) to inequality (!=)",
"original_caption": "This function returns True if the remainder of a divided by b is zero.",
"conflicting_caption": "This function returns True if the remainder of a divided by b is non-zero.",
"question": "Under what remainder condition does this function return True?",
"image_bias": "Remainder is zero",
"text_bias": "Remainder is non-zero",
"distractor": "Remainder is equal to a"
},
{
"func_name": "has_valid_length",
"code_text": "def has_valid_length(s):\n # Verify password length\n return len(s) >= 8",
"type": "operator_substitution",
"desc": "Changed greater-than-or-equal (>=) to less-than (<)",
"original_caption": "This function returns True if the length of the input is 8 or more.",
"conflicting_caption": "This function returns True if the length of the input is less than 8.",
"question": "What string length criteria returns True?",
"image_bias": "Length of 8 or more",
"text_bias": "Length of less than 8",
"distractor": "Length of exactly 8"
},
{
"func_name": "in_range",
"code_text": "def in_range(x):\n # Within boundaries\n return x > 0 and x < 100",
"type": "operator_substitution",
"desc": "Changed logical 'and' to 'or'",
"original_caption": "This function returns True if x is both greater than 0 and less than 100.",
"conflicting_caption": "This function returns True if x is either greater than 0 or less than 100.",
"question": "What constraint must x satisfy to return True?",
"image_bias": "Both greater than 0 and less than 100",
"text_bias": "Either greater than 0 or less than 100",
"distractor": "Exactly equal to 50"
},
{
"func_name": "increment_index",
"code_text": "def increment_index(i):\n # Move forward\n return i + 1",
"type": "operator_substitution",
"desc": "Changed addition (+) to subtraction (-)",
"original_caption": "This function increases the index by adding 1.",
"conflicting_caption": "This function decreases the index by subtracting 1.",
"question": "What is the mathematical outcome of running this function on index i?",
"image_bias": "Increases by 1",
"text_bias": "Decreases by 1",
"distractor": "Multiplies by 2"
},
{
"func_name": "is_above_threshold",
"code_text": "def is_above_threshold(val, limit):\n # Strict limit check\n return val > limit",
"type": "operator_substitution",
"desc": "Changed greater-than (>) to less-than (<)",
"original_caption": "This function returns True if the value is strictly greater than the limit.",
"conflicting_caption": "This function returns True if the value is strictly less than the limit.",
"question": "When does this function return True?",
"image_bias": "Value is greater than limit",
"text_bias": "Value is less than limit",
"distractor": "Value is equal to limit"
},
{
"func_name": "get_percentage",
"code_text": "def get_percentage(part, total):\n # Compute percentage score\n return (part / total) * 100",
"type": "operator_substitution",
"desc": "Changed multiplication (*) to addition (+)",
"original_caption": "This function calculates the percentage by dividing part by total and multiplying by 100.",
"conflicting_caption": "This function calculates the percentage by dividing part by total and adding 100.",
"question": "What operation is done to the division result?",
"image_bias": "Multiplication by 100",
"text_bias": "Addition of 100",
"distractor": "Subtraction of 100"
},
{
"func_name": "not_equal_check",
"code_text": "def not_equal_check(x, y):\n # Inequality check\n return x != y",
"type": "operator_substitution",
"desc": "Changed inequality (!=) to equality (==)",
"original_caption": "This function returns True if x is not equal to y.",
"conflicting_caption": "This function returns True if x is equal to y.",
"question": "Under what condition does this check return True?",
"image_bias": "x is not equal to y",
"text_bias": "x is equal to y",
"distractor": "x is greater than y"
}
])
# ==========================================
# CATEGORY 2: operand_order (20 items)
# ==========================================
templates.extend([
{
"func_name": "subtract_offset",
"code_text": "def subtract_offset(base, offset):\n # Apply offset correction\n return base - offset",
"type": "operand_order",
"desc": "Swapped base and offset subtraction order",
"original_caption": "This function subtracts the offset from the base value.",
"conflicting_caption": "This function subtracts the base value from the offset.",
"question": "How is the mathematical subtraction performed in this function?",
"image_bias": "base minus offset",
"text_bias": "offset minus base",
"distractor": "base plus offset"
},
{
"func_name": "divide_shares",
"code_text": "def divide_shares(total, people):\n # Distribute shares evenly\n return total / people",
"type": "operand_order",
"desc": "Swapped total and people division order",
"original_caption": "This function divides the total amount by the number of people.",
"conflicting_caption": "This function divides the number of people by the total amount.",
"question": "What is the dividend and divisor in this function?",
"image_bias": "total divided by people",
"text_bias": "people divided by total",
"distractor": "total multiplied by people"
},
{
"func_name": "compare_values",
"code_text": "def compare_values(x, y):\n # Check inequality order\n return x < y",
"type": "operand_order",
"desc": "Swapped x and y in less-than comparison",
"original_caption": "This function returns True if x is less than y.",
"conflicting_caption": "This function returns True if y is less than x.",
"question": "What relationship does this function check?",
"image_bias": "x is less than y",
"text_bias": "y is less than x",
"distractor": "x is equal to y"
},
{
"func_name": "get_difference",
"code_text": "def get_difference(a, b):\n # Simple absolute difference helper\n return a - b",
"type": "operand_order",
"desc": "Swapped a and b subtraction order",
"original_caption": "This function computes the difference of a minus b.",
"conflicting_caption": "This function computes the difference of b minus a.",
"question": "What is the calculation layout?",
"image_bias": "a minus b",
"text_bias": "b minus a",
"distractor": "a multiplied by b"
},
{
"func_name": "is_greater",
"code_text": "def is_greater(a, b):\n # Order check\n return a > b",
"type": "operand_order",
"desc": "Swapped a and b in greater-than comparison",
"original_caption": "This function checks if variable a is greater than variable b.",
"conflicting_caption": "This function checks if variable b is greater than variable a.",
"question": "What does the logic verify?",
"image_bias": "a is greater than b",
"text_bias": "b is greater than a",
"distractor": "a is equal to b"
},
{
"func_name": "modulo_op",
"code_text": "def modulo_op(a, b):\n # Remainder calculation\n return a % b",
"type": "operand_order",
"desc": "Swapped a and b modulo order",
"original_caption": "This function returns the remainder of a divided by b.",
"conflicting_caption": "This function returns the remainder of b divided by a.",
"question": "What modulo operation is being executed?",
"image_bias": "a modulo b",
"text_bias": "b modulo a",
"distractor": "a divided by b"
},
{
"func_name": "string_concat",
"code_text": "def string_concat(first, second):\n # Connect strings in order\n return first + second",
"type": "operand_order",
"desc": "Swapped first and second string order",
"original_caption": "This function concatenates 'first' followed by 'second'.",
"conflicting_caption": "This function concatenates 'second' followed by 'first'.",
"question": "In what order are the strings combined?",
"image_bias": "first followed by second",
"text_bias": "second followed by first",
"distractor": "Joined with a space in between"
},
{
"func_name": "calculate_margin",
"code_text": "def calculate_margin(revenue, cost):\n # Basic profit margin margin\n return revenue - cost",
"type": "operand_order",
"desc": "Swapped revenue and cost subtraction order",
"original_caption": "This function calculates profit by subtracting cost from revenue.",
"conflicting_caption": "This function calculates profit by subtracting revenue from cost.",
"question": "What is the subtraction formula used?",
"image_bias": "revenue minus cost",
"text_bias": "cost minus revenue",
"distractor": "revenue divided by cost"
},
{
"func_name": "scale_value",
"code_text": "def scale_value(val, factor):\n # Downscale value\n return val / factor",
"type": "operand_order",
"desc": "Swapped val and factor division order",
"original_caption": "This function scales down the value by dividing val by factor.",
"conflicting_caption": "This function scales down the value by dividing factor by val.",
"question": "What mathematical division is represented?",
"image_bias": "val divided by factor",
"text_bias": "factor divided by val",
"distractor": "val multiplied by factor"
},
{
"func_name": "get_slope",
"code_text": "def get_slope(dy, dx):\n # Calculate slope gradient\n return dy / dx",
"type": "operand_order",
"desc": "Swapped dy and dx division order",
"original_caption": "This function calculates the slope by dividing dy by dx.",
"conflicting_caption": "This function calculates the slope by dividing dx by dy.",
"question": "How is the slope computed?",
"image_bias": "dy divided by dx",
"text_bias": "dx divided by dy",
"distractor": "dy multiplied by dx"
},
{
"func_name": "is_subset",
"code_text": "def is_subset(set_a, set_b):\n # Set inclusion check\n return set_a.issubset(set_b)",
"type": "operand_order",
"desc": "Swapped set_a and set_b subset direction",
"original_caption": "This function checks if set_a is a subset of set_b.",
"conflicting_caption": "This function checks if set_b is a subset of set_a.",
"question": "What subset relationship is being tested?",
"image_bias": "set_a is subset of set_b",
"text_bias": "set_b is subset of set_a",
"distractor": "set_a and set_b are disjoint"
},
{
"func_name": "format_name",
"code_text": "def format_name(first, last):\n # String template formatting\n return f\"{first} {last}\"",
"type": "operand_order",
"desc": "Swapped first and last name template order",
"original_caption": "This function formats the name with first name followed by last name.",
"conflicting_caption": "This function formats the name with last name followed by first name.",
"question": "What is the format of the output string?",
"image_bias": "first followed by last name",
"text_bias": "last followed by first name",
"distractor": "Last name in all capital letters"
},
{
"func_name": "list_prepend",
"code_text": "def list_prepend(arr, val):\n # Add to start of list\n return [val] + arr",
"type": "operand_order",
"desc": "Swapped prepend array joining order",
"original_caption": "This function adds val before the array elements.",
"conflicting_caption": "This function adds the array elements before val.",
"question": "Where does the new value appear in relation to the list?",
"image_bias": "Before the array elements",
"text_bias": "After the array elements",
"distractor": "In the middle of the array"
},
{
"func_name": "path_join",
"code_text": "def path_join(dir, file):\n # Simple path builder\n return dir + '/' + file",
"type": "operand_order",
"desc": "Swapped dir and file concatenation order",
"original_caption": "This function concatenates dir before file with a slash.",
"conflicting_caption": "This function concatenates file before dir with a slash.",
"question": "How are the path components joined?",
"image_bias": "dir before file",
"text_bias": "file before dir",
"distractor": "Separated by a backslash"
},
{
"func_name": "power_of",
"code_text": "def power_of(base, exp):\n # Exponent arithmetic\n return base ** exp",
"type": "operand_order",
"desc": "Swapped base and exp in exponent power",
"original_caption": "This function calculates base raised to the power of exp.",
"conflicting_caption": "This function calculates exp raised to the power of base.",
"question": "What mathematical power calculation is executed?",
"image_bias": "base raised to power of exp",
"text_bias": "exp raised to power of base",
"distractor": "base multiplied by exp"
},
{
"func_name": "calc_tax_margin",
"code_text": "def calc_tax_margin(amount, tax):\n # Get net amount\n return amount - tax",
"type": "operand_order",
"desc": "Swapped amount and tax subtraction order",
"original_caption": "This function subtracts tax from the amount.",
"conflicting_caption": "This function subtracts the amount from the tax.",
"question": "What is the subtraction formula?",
"image_bias": "amount minus tax",
"text_bias": "tax minus amount",
"distractor": "amount divided by tax"
},
{
"func_name": "get_coordinates",
"code_text": "def get_coordinates(x, y):\n # Coordinate tuple\n return (x, y)",
"type": "operand_order",
"desc": "Swapped x and y in coordinate tuple return",
"original_caption": "This function returns a tuple with x in the first position and y in the second.",
"conflicting_caption": "This function returns a tuple with y in the first position and x in the second.",
"question": "What is the order of elements in the returned coordinate tuple?",
"image_bias": "x first, then y",
"text_bias": "y first, then x",
"distractor": "x and y summed together"
},
{
"func_name": "time_diff",
"code_text": "def time_diff(end, start):\n # Calculate time elapsed\n return end - start",
"type": "operand_order",
"desc": "Swapped end and start subtraction order",
"original_caption": "This function calculates the elapsed time by subtracting start from end.",
"conflicting_caption": "This function calculates the elapsed time by subtracting end from start.",
"question": "How is the time difference calculated?",
"image_bias": "end minus start",
"text_bias": "start minus end",
"distractor": "end plus start"
},
{
"func_name": "percentage_change",
"code_text": "def percentage_change(new, old):\n # Ratio change margin\n return (new - old) / old",
"type": "operand_order",
"desc": "Swapped new and old in percentage numerator",
"original_caption": "This function calculates the change as new minus old, divided by old.",
"conflicting_caption": "This function calculates the change as old minus new, divided by old.",
"question": "What formula calculates the percentage difference?",
"image_bias": "new minus old in numerator",
"text_bias": "old minus new in numerator",
"distractor": "new plus old in numerator"
},
{
"func_name": "distance_to",
"code_text": "def distance_to(target, source):\n # Relative direction vector\n return target - source",
"type": "operand_order",
"desc": "Swapped target and source subtraction order",
"original_caption": "This function calculates the vector by subtracting source from target.",
"conflicting_caption": "This function calculates the vector by subtracting target from source.",
"question": "What is the vector subtraction direction?",
"image_bias": "target minus source",
"text_bias": "source minus target",
"distractor": "target plus source"
}
])
# ==========================================
# CATEGORY 3: loop_boundary (20 items)
# ==========================================
templates.extend([
{
"func_name": "process_elements",
"code_text": "def process_elements(arr):\n # Iteration helper\n for i in range(10):\n print(arr[i])",
"type": "loop_boundary",
"desc": "Changed loop range limit from 10 to 100",
"original_caption": "This function loops exactly 10 times to process the array.",
"conflicting_caption": "This function loops exactly 100 times to process the array.",
"question": "How many times does the loop execute in this function?",
"image_bias": "10 times",
"text_bias": "100 times",
"distractor": "Infinite times"
},
{
"func_name": "retry_request",
"code_text": "def retry_request():\n # Max connections limit\n for attempt in range(3):\n try_connect()",
"type": "loop_boundary",
"desc": "Changed attempt retry count from 3 to 30",
"original_caption": "This function retries the connection up to 3 times.",
"conflicting_caption": "This function retries the connection up to 30 times.",
"question": "What is the maximum number of connection attempts in this code?",
"image_bias": "3 attempts",
"text_bias": "30 attempts",
"distractor": "5 attempts"
},
{
"func_name": "countdown",
"code_text": "def countdown(count):\n # Halt when zero is reached\n while count > 0:\n count -= 1",
"type": "loop_boundary",
"desc": "Changed while condition from strictly-greater (>) to greater-than-or-equal (>=)",
"original_caption": "The while loop runs as long as count is strictly greater than 0.",
"conflicting_caption": "The while loop runs as long as count is greater than or equal to 0.",
"question": "What is the condition for the countdown while loop to continue?",
"image_bias": "count is strictly greater than 0",
"text_bias": "count is greater than or equal to 0",
"distractor": "count is equal to 0"
},
{
"func_name": "paginate_results",
"code_text": "def paginate_results():\n # Database page cap\n limit = 20\n return fetch_data(limit)",
"type": "loop_boundary",
"desc": "Changed pagination limit variable from 20 to 200",
"original_caption": "This function sets the fetch data limit to 20.",
"conflicting_caption": "This function sets the fetch data limit to 200.",
"question": "What is the numerical limit set in this function?",
"image_bias": "20",
"text_bias": "200",
"distractor": "10"
},
{
"func_name": "fill_buffer",
"code_text": "def fill_buffer():\n # Buffer block index fill\n for i in range(5):\n write_data(i)",
"type": "loop_boundary",
"desc": "Changed loop buffer range from 5 to 50",
"original_caption": "The function writes data inside a loop that runs 5 times.",
"conflicting_caption": "The function writes data inside a loop that runs 50 times.",
"question": "What is the size limit of the buffer write loop?",
"image_bias": "5",
"text_bias": "50",
"distractor": "10"
},
{
"func_name": "read_lines",
"code_text": "def read_lines():\n # Max line reader safety\n max_lines = 50\n return read_file(max_lines)",
"type": "loop_boundary",
"desc": "Changed max_lines limit variable from 50 to 500",
"original_caption": "This function sets the maximum lines to read to 50.",
"conflicting_caption": "This function sets the maximum lines to read to 500.",
"question": "How many maximum lines will this code attempt to read?",
"image_bias": "50 lines",
"text_bias": "500 lines",
"distractor": "5 lines"
},
{
"func_name": "is_valid_grade",
"code_text": "def is_valid_grade(g):\n # Score limit validation\n return 0 <= g <= 100",
"type": "loop_boundary",
"desc": "Changed grade range check ceiling from 100 to 10",
"original_caption": "This function validates that the grade is between 0 and 100.",
"conflicting_caption": "This function validates that the grade is between 0 and 10.",
"question": "What is the maximum valid score this function accepts?",
"image_bias": "100",
"text_bias": "10",
"distractor": "50"
},
{
"func_name": "clamp_value",
"code_text": "def clamp_value(val):\n # Cap input range\n return min(max(val, 0), 10)",
"type": "loop_boundary",
"desc": "Changed clamp ceiling limit from 10 to 100",
"original_caption": "This function clamps the value to a maximum threshold of 10.",
"conflicting_caption": "This function clamps the value to a maximum threshold of 100.",
"question": "What is the upper bound value used to clamp the output?",
"image_bias": "10",
"text_bias": "100",
"distractor": "0"
},
{
"func_name": "is_in_limit",
"code_text": "def is_in_limit(x):\n # Range checker\n return x < 50",
"type": "loop_boundary",
"desc": "Changed threshold ceiling from 50 to 5",
"original_caption": "This function checks if the value of x is less than 50.",
"conflicting_caption": "This function checks if the value of x is less than 5.",
"question": "What is the value boundary for the check?",
"image_bias": "50",
"text_bias": "5",
"distractor": "100"
},
{
"func_name": "get_iterations",
"code_text": "def get_iterations():\n # Iteration counter\n for i in range(100):\n compute(i)",
"type": "loop_boundary",
"desc": "Changed range boundary from 100 to 1000",
"original_caption": "The range function inside the loop goes up to 100 iterations.",
"conflicting_caption": "The range function inside the loop goes up to 1000 iterations.",
"question": "How many iterations are configured in the range function?",
"image_bias": "100",
"text_bias": "1000",
"distractor": "10"
},
{
"func_name": "scan_ports",
"code_text": "def scan_ports():\n # Firewall port scan range\n for port in range(1024):\n test(port)",
"type": "loop_boundary",
"desc": "Changed scanned ports ceiling from 1024 to 10240",
"original_caption": "This function loops through and tests ports up to index 1024.",
"conflicting_caption": "This function loops through and tests ports up to index 10240.",
"question": "What is the upper limit of ports tested in the loop?",
"image_bias": "1024",
"text_bias": "10240",
"distractor": "80"
},
{
"func_name": "generate_ids",
"code_text": "def generate_ids():\n # Id sequence limit\n count = 10\n return make_seq(count)",
"type": "loop_boundary",
"desc": "Changed count variable from 10 to 100",
"original_caption": "This function sets the generation count variable to 10.",
"conflicting_caption": "This function sets the generation count variable to 100.",
"question": "What sequence length does the count variable specify?",
"image_bias": "10",
"text_bias": "100",
"distractor": "1000"
},
{
"func_name": "has_max_retries",
"code_text": "def has_max_retries(r):\n # Check retry cutoff limit\n return r >= 5",
"type": "loop_boundary",
"desc": "Changed retry limit ceiling from 5 to 50",
"original_caption": "This function returns True if retries are 5 or more.",
"conflicting_caption": "This function returns True if retries are 50 or more.",
"question": "What is the threshold for checking maximum retries?",
"image_bias": "5 or more",
"text_bias": "50 or more",
"distractor": "exactly 5"
},
{
"func_name": "run_batch",
"code_text": "def run_batch():\n # Thread batch size definition\n batch_size = 32\n return process(batch_size)",
"type": "loop_boundary",
"desc": "Changed batch_size constant from 32 to 320",
"original_caption": "The batch size configured in this function is 32.",
"conflicting_caption": "The batch size configured in this function is 320.",
"question": "What batch size value is passed to the process function?",
"image_bias": "32",
"text_bias": "320",
"distractor": "64"
},
{
"func_name": "check_timeout",
"code_text": "def check_timeout(t):\n # Wait limit check\n return t < 30",
"type": "loop_boundary",
"desc": "Changed timeout limit threshold from 30 to 300",
"original_caption": "This function returns True if time t is less than 30.",
"conflicting_caption": "This function returns True if time t is less than 300.",
"question": "What is the threshold value used to check the timeout?",
"image_bias": "30",
"text_bias": "300",
"distractor": "60"
},
{
"func_name": "truncate_text",
"code_text": "def truncate_text(s):\n # Character limit truncation\n max_len = 80\n return s[:max_len]",
"type": "loop_boundary",
"desc": "Changed max_len constant from 80 to 800",
"original_caption": "This function sets the maximum character length to 80.",
"conflicting_caption": "This function sets the maximum character length to 800.",
"question": "What is the character length cutoff used for truncation?",
"image_bias": "80",
"text_bias": "800",
"distractor": "100"
},
{
"func_name": "validate_ip_octet",
"code_text": "def validate_ip_octet(p):\n # Address validation range\n return 0 <= p <= 255",
"type": "loop_boundary",
"desc": "Changed maximum value range from 255 to 2550",
"original_caption": "This function checks if the octet value is at most 255.",
"conflicting_caption": "This function checks if the octet value is at most 2550.",
"question": "What is the upper limit value allowed for the ip octet?",
"image_bias": "255",
"text_bias": "2550",
"distractor": "256"
},
{
"func_name": "sleep_delay",
"code_text": "def sleep_delay():\n # Thread sleep delay\n delay = 5\n time.sleep(delay)",
"type": "loop_boundary",
"desc": "Changed delay timer variable from 5 to 50",
"original_caption": "This function triggers a sleep command for 5 seconds.",
"conflicting_caption": "This function triggers a sleep command for 50 seconds.",
"question": "How many seconds does this function delay execution?",
"image_bias": "5 seconds",
"text_bias": "50 seconds",
"distractor": "1 second"
},
{
"func_name": "is_valid_percent",
"code_text": "def is_valid_percent(p):\n # Ratio threshold\n return p <= 100",
"type": "loop_boundary",
"desc": "Changed percentage threshold limit from 100 to 1000",
"original_caption": "This function checks if value p is less than or equal to 100.",
"conflicting_caption": "This function checks if value p is less than or equal to 1000.",
"question": "What is the upper boundary check for the percent validation?",
"image_bias": "100",
"text_bias": "1000",
"distractor": "1"
},
{
"func_name": "max_capacity",
"code_text": "def max_capacity():\n # Capacity limit constants\n capacity = 500\n return capacity",
"type": "loop_boundary",
"desc": "Changed capacity variable value from 500 to 50",
"original_caption": "This function defines a capacity variable holding 500.",
"conflicting_caption": "This function defines a capacity variable holding 50.",
"question": "What value is assigned to the capacity variable?",
"image_bias": "500",
"text_bias": "50",
"distractor": "1000"
}
])
# ==========================================
# CATEGORY 4: array_indexing (20 items)
# ==========================================
templates.extend([
{
"func_name": "get_first",
"code_text": "def get_first(arr):\n # Array indexing access\n return arr[0]",
"type": "array_indexing",
"desc": "Changed target offset index from 0 (first) to -1 (last)",
"original_caption": "This function retrieves the first element at index 0 of the array.",
"conflicting_caption": "This function retrieves the last element at index -1 of the array.",
"question": "Which array element does the index position target?",
"image_bias": "First element (index 0)",
"text_bias": "Last element (index -1)",
"distractor": "Second element (index 1)"
},
{
"func_name": "get_last",
"code_text": "def get_last(arr):\n # Array indexing access\n return arr[-1]",
"type": "array_indexing",
"desc": "Changed target offset index from -1 (last) to 0 (first)",
"original_caption": "This function retrieves the last element at index -1 of the array.",
"conflicting_caption": "This function retrieves the first element at index 0 of the array.",
"question": "Which position in the list is returned by the indexing code?",
"image_bias": "Last element (index -1)",
"text_bias": "First element (index 0)",
"distractor": "Middle element"
},
{
"func_name": "get_second",
"code_text": "def get_second(arr):\n # Get secondary item\n return arr[1]",
"type": "array_indexing",
"desc": "Changed target index from 1 (second) to 0 (first)",
"original_caption": "This function retrieves the element at index 1 of the list.",
"conflicting_caption": "This function retrieves the element at index 0 of the list.",
"question": "What element index is being accessed?",
"image_bias": "Index 1",
"text_bias": "Index 0",
"distractor": "Index -1"
},
{
"func_name": "get_penultimate",
"code_text": "def get_penultimate(arr):\n # Index offset access\n return arr[-2]",
"type": "array_indexing",
"desc": "Changed target index from -2 (second-to-last) to 0 (first)",
"original_caption": "This function retrieves the second-to-last element at index -2.",
"conflicting_caption": "This function retrieves the first element at index 0.",
"question": "Which element does index position -2 retrieve?",
"image_bias": "Second-to-last element",
"text_bias": "First element",
"distractor": "Last element"
},
{
"func_name": "get_third",
"code_text": "def get_third(arr):\n # Index helper\n return arr[2]",
"type": "array_indexing",
"desc": "Changed target index from 2 (third) to -1 (last)",
"original_caption": "This function retrieves the element at index 2 of the list.",
"conflicting_caption": "This function retrieves the element at index -1 of the list.",
"question": "Which position in the list is accessed?",
"image_bias": "Index 2",
"text_bias": "Index -1",
"distractor": "Index 0"
},
{
"func_name": "slice_start",
"code_text": "def slice_start(arr):\n # Subset slicing helper\n return arr[:3]",
"type": "array_indexing",
"desc": "Changed slicing range from start-up-to-3 (:3) to starting-from-3 (3:)",
"original_caption": "This function slices the array returning elements up to index 3.",
"conflicting_caption": "This function slices the array returning elements starting from index 3.",
"question": "What sub-array range does the slicing code return?",
"image_bias": "Elements up to index 3",
"text_bias": "Elements starting from index 3",
"distractor": "Only the element at index 3"
},
{
"func_name": "slice_end",
"code_text": "def slice_end(arr):\n # Slice tail elements\n return arr[-3:]",
"type": "array_indexing",
"desc": "Changed slicing range from last-3 (-3:) to up-to-last-3 (:-3)",
"original_caption": "This function slices the list returning the last 3 elements.",
"conflicting_caption": "This function slices the list returning all elements except the last 3.",
"question": "Which elements are returned by the slice operation?",
"image_bias": "The last 3 elements",
"text_bias": "All elements except the last 3",
"distractor": "Only the first 3 elements"
},
{
"func_name": "get_nested",
"code_text": "def get_nested(matrix):\n # Access 2D grid matrix\n return matrix[0][0]",
"type": "array_indexing",
"desc": "Changed inner list column index from 0 (first) to -1 (last)",
"original_caption": "This function retrieves the first column value of the first row at matrix[0][0].",
"conflicting_caption": "This function retrieves the last column value of the first row at matrix[0][-1].",
"question": "Which cell in the matrix does the index code target?",
"image_bias": "Row 0, Column 0",
"text_bias": "Row 0, Column -1",
"distractor": "Row -1, Column 0"
},
{
"func_name": "get_header",
"code_text": "def get_header(rows):\n # Document header row\n return rows[0]",
"type": "array_indexing",
"desc": "Changed index from 0 (first) to -1 (last)",
"original_caption": "This function extracts the header at index 0 of the rows list.",
"conflicting_caption": "This function extracts the footer at index -1 of the rows list.",
"question": "Based on the index expression used on the rows list, which document row position is returned by this function?",
"image_bias": "Header (index 0)",
"text_bias": "Footer (index -1)",
"distractor": "Middle row"
},
{
"func_name": "get_footer",
"code_text": "def get_footer(rows):\n # Document footer row\n return rows[-1]",
"type": "array_indexing",
"desc": "Changed index from -1 (last) to 0 (first)",
"original_caption": "This function extracts the footer at index -1 of the rows list.",
"conflicting_caption": "This function extracts the header at index 0 of the rows list.",
"question": "Based on the index expression used on the rows list, which document row position is returned by this function?",
"image_bias": "Footer (index -1)",
"text_bias": "Header (index 0)",
"distractor": "None of the rows"
},
{
"func_name": "get_newest",
"code_text": "def get_newest(items):\n # Sorted items access\n return items[-1]",
"type": "array_indexing",
"desc": "Changed index from -1 (last) to 0 (first)",
"original_caption": "This function gets the last item at index -1 representing the newest item.",
"conflicting_caption": "This function gets the first item at index 0 representing the oldest item.",
"question": "Which item (newest or oldest) is retrieved from the list by this function?",
"image_bias": "Last item (index -1)",
"text_bias": "First item (index 0)",
"distractor": "A random item"
},
{
"func_name": "get_oldest",
"code_text": "def get_oldest(items):\n # Sorted items access\n return items[0]",
"type": "array_indexing",
"desc": "Changed index from 0 (first) to -1 (last)",
"original_caption": "This function gets the first item at index 0 representing the oldest item.",
"conflicting_caption": "This function gets the last item at index -1 representing the newest item.",
"question": "Which item (oldest or newest) is retrieved from the list by this function?",
"image_bias": "First item (index 0)",
"text_bias": "Last item (index -1)",
"distractor": "Second item"
},
{
"func_name": "get_runner_up",
"code_text": "def get_runner_up(scores):\n # Standing index access\n return scores[1]",
"type": "array_indexing",
"desc": "Changed index from 1 (runner up) to 0 (winner)",
"original_caption": "This function accesses index 1 to retrieve the runner-up score.",
"conflicting_caption": "This function accesses index 0 to retrieve the winner's score.",
"question": "Which standing score position (winner or runner-up) is retrieved by this function?",
"image_bias": "Runner-up (index 1)",
"text_bias": "Winner (index 0)",
"distractor": "Third place"
},
{
"func_name": "get_winner",
"code_text": "def get_winner(scores):\n # Standing index access\n return scores[0]",
"type": "array_indexing",
"desc": "Changed index from 0 (winner) to -1 (last place)",
"original_caption": "This function accesses index 0 to retrieve the winning score.",
"conflicting_caption": "This function accesses index -1 to retrieve the last place score.",
"question": "Which standing score position (winner or last place) is retrieved by this function?",
"image_bias": "Winner (index 0)",
"text_bias": "Last place (index -1)",
"distractor": "Runner-up"
},
{
"func_name": "get_first_two",
"code_text": "def get_first_two(arr):\n # Subarray slices\n return arr[:2]",
"type": "array_indexing",
"desc": "Changed slice range from first-two (:2) to everything-after-two (2:)",
"original_caption": "This function slices the array returning the first 2 elements.",
"conflicting_caption": "This function slices the array returning all elements except the first 2.",
"question": "Which subset of elements is returned from the array by this function?",
"image_bias": "First 2 elements",
"text_bias": "All elements except the first 2",
"distractor": "Only index 2"
},
{
"func_name": "get_last_two",
"code_text": "def get_last_two(arr):\n # Subarray slices\n return arr[-2:]",
"type": "array_indexing",
"desc": "Changed slice range from last-two (-2:) to everything-before-last-two (:-2)",
"original_caption": "This function slices the list returning the last 2 elements.",
"conflicting_caption": "This function slices the list returning all elements except the last 2.",
"question": "Which sub-list items does the slice output?",
"image_bias": "The last 2 elements",
"text_bias": "All elements except the last 2",
"distractor": "The first 2 elements"
},
{
"func_name": "get_top_left",
"code_text": "def get_top_left(grid):\n # 2D Grid positioning\n return grid[0][0]",
"type": "array_indexing",
"desc": "Changed index from [0][0] to [-1][-1] (bottom right)",
"original_caption": "This function retrieves the top-left cell at grid[0][0].",
"conflicting_caption": "This function retrieves the bottom-right cell at grid[-1][-1].",
"question": "Which grid cell coordinate is retrieved?",
"image_bias": "Top-left cell",
"text_bias": "Bottom-right cell",
"distractor": "Middle cell"
},
{
"func_name": "get_bottom_right",
"code_text": "def get_bottom_right(grid):\n # 2D Grid positioning\n return grid[-1][-1]",
"type": "array_indexing",
"desc": "Changed index from [-1][-1] to [0][0] (top left)",
"original_caption": "This function retrieves the bottom-right cell at grid[-1][-1].",
"conflicting_caption": "This function retrieves the top-left cell at grid[0][0].",
"question": "What position in the 2D grid is accessed?",
"image_bias": "Bottom-right cell",
"text_bias": "Top-left cell",
"distractor": "Bottom-left cell"
},
{
"func_name": "get_second_last",
"code_text": "def get_second_last(arr):\n # List indexing helper\n return arr[-2]",
"type": "array_indexing",
"desc": "Changed index from -2 (second-last) to -1 (last)",
"original_caption": "This function accesses index -2 to return the second-to-last item.",
"conflicting_caption": "This function accesses index -1 to return the last item.",
"question": "Which item (second-to-last or last) is retrieved from the list by this function?",
"image_bias": "Second-to-last item",
"text_bias": "Last item",
"distractor": "First item"
},
{
"func_name": "get_middle_element",
"code_text": "def get_middle_element(arr):\n # Midpoint index access\n mid = len(arr) // 2\n return arr[mid]",
"type": "array_indexing",
"desc": "Changed index variable from mid to 0 (first element)",
"original_caption": "This function retrieves the middle element of the array using index mid.",
"conflicting_caption": "This function retrieves the first element of the array using index 0.",
"question": "Which position in the array is returned by the function?",
"image_bias": "Middle element",
"text_bias": "First element",
"distractor": "Last element"
}
])
# ==========================================
# CATEGORY 5: boolean_inversion (20 items)
# ==========================================
templates.extend([
{
"func_name": "is_admin",
"code_text": "def is_admin(user):\n # Check admin privileges\n if user.role == 'admin':\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted the return values inside the condition branches",
"original_caption": "This function returns True if the user role is admin, otherwise False.",
"conflicting_caption": "This function returns False if the user role is admin, otherwise True.",
"question": "What does this function return for a user whose role is 'admin'?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "has_permission",
"code_text": "def has_permission(user):\n # Check account active status\n if user.is_active:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted active permission check return values",
"original_caption": "The function returns True if the user is active, and False otherwise.",
"conflicting_caption": "The function returns False if the user is active, and True otherwise.",
"question": "What is the return value when user.is_active is True?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_valid_email",
"code_text": "def is_valid_email(email):\n # Basic syntax presence check\n if '@' in email:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted email symbol validation check",
"original_caption": "This function returns True if the character '@' exists in the email, otherwise False.",
"conflicting_caption": "This function returns False if the character '@' exists in the email, otherwise True.",
"question": "What does the function return if the email contains '@'?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_prime",
"code_text": "def is_prime(n):\n # Small prime trigger check\n if n < 2:\n return False\n return True",
"type": "boolean_inversion",
"desc": "Inverted n < 2 prime return outcome",
"original_caption": "This function returns False if n is less than 2.",
"conflicting_caption": "This function returns True if n is less than 2.",
"question": "What does this function return if the input n is 1?",
"image_bias": "False",
"text_bias": "True",
"distractor": "None"
},
{
"func_name": "is_empty_list",
"code_text": "def is_empty_list(arr):\n # Array footprint check\n if len(arr) == 0:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted empty array check output values",
"original_caption": "This function returns True if the array has a length of 0.",
"conflicting_caption": "This function returns False if the array has a length of 0.",
"question": "What does this code output for an empty list input?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_weekend",
"code_text": "def is_weekend(day):\n # Weekend calendar check\n if day in ['Saturday', 'Sunday']:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted weekend day check outputs",
"original_caption": "This function returns True if the input day is Saturday or Sunday.",
"conflicting_caption": "This function returns False if the input day is Saturday or Sunday.",
"question": "What does this code return for the input day 'Saturday'?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_expired",
"code_text": "def is_expired(token):\n # Auth lifespan check\n if token.age > 3600:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted age expiration check outputs",
"original_caption": "This function returns True if token age exceeds 3600.",
"conflicting_caption": "This function returns False if token age exceeds 3600.",
"question": "What is the return value if the token's age is 4000?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "has_error",
"code_text": "def has_error(status):\n # Http code status check\n if status >= 400:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted error status threshold check output",
"original_caption": "This function returns True if the status code is 400 or higher.",
"conflicting_caption": "This function returns False if the status code is 400 or higher.",
"question": "What does the code return for a status code of 404?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_authenticated",
"code_text": "def is_authenticated(session):\n # Active session check\n if session.is_valid:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted session validity return values",
"original_caption": "This function returns True if the session is valid, otherwise False.",
"conflicting_caption": "This function returns False if the session is valid, otherwise True.",
"question": "What does the function output for a valid session?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_success",
"code_text": "def is_success(code):\n # Http ok success check\n if code == 200:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted code 200 ok check output values",
"original_caption": "This function returns True if the response code is exactly 200.",
"conflicting_caption": "This function returns False if the response code is exactly 200.",
"question": "What is the return value of this function when code is 200?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_digit",
"code_text": "def is_digit(char):\n # Numeric digit character check\n if char.isdigit():\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted isdigit character helper check output",
"original_caption": "This function returns True if the input character is a digit.",
"conflicting_caption": "This function returns False if the input character is a digit.",
"question": "What does this code return for the character '5'?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_lowercase",
"code_text": "def is_lowercase(s):\n # Lowercase string casing check\n if s.islower():\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted lowercase casing string check output",
"original_caption": "This function returns True if the string is all lowercase.",
"conflicting_caption": "This function returns False if the string is all lowercase.",
"question": "What does this function return for a lowercase string 'abc'?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_file",
"code_text": "def is_file(path):\n # File type verification\n if os.path.isfile(path):\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted path file check output values",
"original_caption": "This function returns True if the path points to a file.",
"conflicting_caption": "This function returns False if the path points to a file.",
"question": "What does this function return if the path is indeed a valid file?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_directory",
"code_text": "def is_directory(path):\n # Folder check verification\n if os.path.isdir(path):\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted path directory folders checks",
"original_caption": "This function returns True if the path points to a directory.",
"conflicting_caption": "This function returns False if the path points to a directory.",
"question": "What does this function return if the path is a folder?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_leap",
"code_text": "def is_leap(year):\n # Leap validation flag\n if year % 4 == 0:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted leap validation outputs",
"original_caption": "This function returns True if the input year is divisible by 4.",
"conflicting_caption": "This function returns False if the input year is divisible by 4.",
"question": "What is the output for a year that is divisible by 4?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_even_check",
"code_text": "def is_even_check(x):\n # Parity check flag\n if x % 2 == 0:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted even parity check outputs",
"original_caption": "This function returns True if the number x is even.",
"conflicting_caption": "This function returns False if the number x is even.",
"question": "What does the code return if x is 4?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_odd_check",
"code_text": "def is_odd_check(x):\n # Odd check flag\n if x % 2 != 0:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted odd parity check outputs",
"original_caption": "This function returns True if the number x is odd.",
"conflicting_caption": "This function returns False if the number x is odd.",
"question": "What does the code return if x is 5?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_uppercase",
"code_text": "def is_uppercase(s):\n # Uppercase string validation\n if s.isupper():\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted uppercase string checks",
"original_caption": "This function returns True if the string is all uppercase.",
"conflicting_caption": "This function returns False if the string is all uppercase.",
"question": "What does this function return for the uppercase string 'XYZ'?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_verified",
"code_text": "def is_verified(user):\n # User validation tag checks\n if user.verified:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted user verification return values",
"original_caption": "This function returns True if the user is verified, otherwise False.",
"conflicting_caption": "This function returns False if the user is verified, otherwise True.",
"question": "What does the code return if user.verified is True?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
},
{
"func_name": "is_complete",
"code_text": "def is_complete(task):\n # Task completion checklist\n if task.done:\n return True\n return False",
"type": "boolean_inversion",
"desc": "Inverted task completion outputs",
"original_caption": "This function returns True if the task.done flag is True.",
"conflicting_caption": "This function returns False if the task.done flag is True.",
"question": "What is the return value of this function when task.done is True?",
"image_bias": "True",
"text_bias": "False",
"distractor": "None"
}
])
return templates
def run_generation(batch_num):
dataset_dir = "/Users/akanshjain/.gemini/antigravity/scratch/code_conflict_dataset"
images_dir = os.path.join(dataset_dir, "train")
os.makedirs(images_dir, exist_ok=True)
templates = get_templates()
# Calculate start and end indices
start_idx = (batch_num - 1) * 5
end_idx = batch_num * 5
batch_templates = templates[start_idx:end_idx]
# Load existing metadata if it exists
csv_path = os.path.join(images_dir, "metadata.csv")
existing_rows = []
if os.path.exists(csv_path) and batch_num > 1:
with open(csv_path, mode="r") as f:
reader = csv.DictReader(f)
for r in reader:
existing_rows.append(r)
# Prepare batch rows
new_rows = []
pygmentize_path = "/opt/miniconda3/bin/pygmentize"
for i, t in enumerate(batch_templates):
serial_no = start_idx + i + 1
img_filename = f"code_{serial_no}.png"
img_path = os.path.join(images_dir, img_filename)
# Write temporary code file
temp_file = os.path.join(dataset_dir, "temp_code.py")
with open(temp_file, "w") as f:
f.write(t["code_text"])
# Run pygmentize to compile code block to PNG screenshot
try:
subprocess.run([
pygmentize_path,
"-f", "png",
"-O", "style=monokai,font_name=Courier New,font_size=20,line_numbers=True",
"-o", img_path,
temp_file
], check=True)
except Exception as e:
print(f"Error running pygmentize: {e}")
# Clean up temp file
if os.path.exists(temp_file):
os.remove(temp_file)
new_rows.append({
"file_name": img_filename,
"original_caption": t["original_caption"],
"conflicting_caption": t["conflicting_caption"],
"question": t["question"],
"image_bias": t["image_bias"],
"text_bias": t["text_bias"],
"distractor": t["distractor"],
"serial_no": serial_no,
"conflict type": t["type"],
"language": "english"
})
# Deduplicate rows by serial_no, keeping new ones
rows_dict = {int(r["serial_no"]): r for r in existing_rows}
for r in new_rows:
rows_dict[int(r["serial_no"])] = r
all_rows = list(rows_dict.values())
all_rows = sorted(all_rows, key=lambda x: int(x["serial_no"]))
with open(csv_path, mode="w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=[
"file_name", "original_caption", "conflicting_caption", "question",
"image_bias", "text_bias", "distractor", "serial_no", "conflict type", "language"
])
writer.writeheader()
writer.writerows(all_rows)
print(f"Successfully generated batch {batch_num} (serial_no {start_idx+1} to {end_idx})")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python3 generate_batch.py <batch_number>")
sys.exit(1)
batch_num = int(sys.argv[1])
run_generation(batch_num)