Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set dataset_text_field for more than one column #591

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions presets/tuning/text-generation/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def load_data(self):
try:
self.dataset = load_dataset(file_ext, data_files=dataset_path, split="train")
print(f"Dataset loaded successfully from {dataset_path} with file type '{file_ext}'.")

self.analyze_dataset_structure()

except Exception as e:
print(f"Error loading dataset: {e}")
raise ValueError(f"Unable to load dataset {dataset_path} with file type '{file_ext}'")
Expand All @@ -56,6 +59,22 @@ def find_valid_dataset(self, data_dir):
if ext in filename_lower:
return os.path.join(root, file)
return None

def analyze_dataset_structure(self):
if self.dataset is None:
raise ValueError("Dataset is not loaded. Please load the dataset first.")

columns = self.dataset.column_names

if len(columns) > 1:
self.dataset_text_field = self.find_text_field(columns)

def find_text_field(self, columns):
text_words = ["text", "content", "input", "question"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about

text_words = {"text", "content", "input", "question"}
for column in columns:
  if column.lower() in text_words:
    return column


for column in columns:
if any(text_word in column.lower() for text_word in text_words):
return column

def get_file_extension(self, file_path):
""" Returns the file extension based on filetype guess or filename. """
Expand Down
Loading