fix: detect list-of-strings text columns and pick random element for VLM conversion
Handles datasets like phiyodr/coco2017 where captions is a list of strings.
This commit is contained in:
parent
095a051ee0
commit
698c9564ef
2 changed files with 9 additions and 2 deletions
|
|
@ -332,8 +332,11 @@ def convert_to_vlm_format(
|
|||
else:
|
||||
image_data = Image.open(image_data).convert("RGB")
|
||||
|
||||
# Get text
|
||||
# Get text (if list of strings, pick a random one — e.g. multiple captions)
|
||||
text_data = sample[text_column]
|
||||
if isinstance(text_data, list) and len(text_data) > 0:
|
||||
import random
|
||||
text_data = random.choice(text_data)
|
||||
|
||||
# Get instruction (static or dynamic)
|
||||
if uses_dynamic and instruction_column:
|
||||
|
|
|
|||
|
|
@ -645,7 +645,7 @@ def detect_vlm_dataset_structure(dataset):
|
|||
image_keywords = ['image', 'img', 'photo', 'picture', 'pic', 'visual', 'scan', 'file_name', 'filename']
|
||||
|
||||
# Text-related keywords
|
||||
text_keywords = ['text', 'caption', 'description', 'answer', 'output', 'response', 'label']
|
||||
text_keywords = ['text', 'caption', 'captions', 'description', 'answer', 'output', 'response', 'label']
|
||||
|
||||
def is_metadata_column(col_name):
|
||||
"""Check if column name looks like metadata."""
|
||||
|
|
@ -711,6 +711,10 @@ def detect_vlm_dataset_structure(dataset):
|
|||
# Longer text = higher priority (likely content, not just a label)
|
||||
priority = min(len(sample_value), 1000) # Cap at 1000
|
||||
candidates.append((col, priority))
|
||||
elif isinstance(sample_value, list) and len(sample_value) > 0 and isinstance(sample_value[0], str):
|
||||
# List of strings (e.g. captions list) — lower priority than plain strings
|
||||
priority = min(len(sample_value[0]), 1000) // 2
|
||||
candidates.append((col, priority))
|
||||
|
||||
# Return highest priority candidate
|
||||
if candidates:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue