import datasets import pandas as pd # Dataset metadata _CITATION = """""" _DESCRIPTION = """""" _HOMEPAGE = "" _LICENSE = "" # Updated URLs to dynamically handle task names _URLS = { "train": "data/LongConL-tasks/{task_name}/train.csv", "validation": "data/LongConL-tasks/{task_name}/validation.csv", "test": "data/LongConL-tasks/{task_name}/test.csv", } _CONFIGS = { "ATS-Jurisdiction": { "description": "Jurisdiction-specific legal opinions", "features": { "Citation": datasets.Value("string"), "Case Name": datasets.Value("string"), "Opinion Text": datasets.Value("string"), "Numerical Label": datasets.Value("string"), # Will be optional for some tasks "Text Label": datasets.Value("string"), }, }, "ATS-FavorableJudgment": { "description": "Description for other task 1", "features": { "Citation": datasets.Value("string"), "Case Name": datasets.Value("string"), "Opinion Text": datasets.Value("string"), "Numerical Label": datasets.Value("string"), "Text Label": datasets.Value("string"), }, } } class LongConLDataset(datasets.GeneratorBasedBuilder): """Legal opinion classification dataset for LongConL tasks""" def _info(self): """Return dataset information.""" features = datasets.Features({ "Citation": datasets.Value("string"), "Case Name": datasets.Value("string"), "Opinion Text": datasets.Value("string"), "Numerical Label": datasets.Value("string"), # Will be optional for some tasks "Text Label": datasets.Value("string"), }) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, citation=_CITATION, license=_LICENSE, ) def _split_generators(self, dl_manager): """Split the dataset into train, validation, and test.""" task_name = self.config.name # Get the current task name from the config urls = {key: val.format(task_name=task_name) for key, val in _URLS.items()} # Update URLs with the task name downloaded_files = dl_manager.download_and_extract(urls) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"file_path": downloaded_files["train"]}, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"file_path": downloaded_files["validation"]}, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"file_path": downloaded_files["test"]}, ), ] def _generate_examples(self, file_path): """Generate examples from the dataset CSV.""" data = pd.read_csv(file_path) print("Data loaded from file:", file_path) print(data.head()) # Display first few rows data_dict = data.to_dict(orient="records") for id_, row in enumerate(data_dict): yield id_, { "Citation": row["Citation"], "Case Name": row["Case Name"], "Opinion Text": row["Opinion Text"], "Numerical Label": row.get("Numerical Label", None), # Use .get() to handle missing keys "Text Label": row["Text Label"], } # Use a dynamic config BUILDER_CONFIGS = [ datasets.BuilderConfig(name=task_name, version=datasets.Version("1.0.0"), description=task_name) for task_name in ["ATS-Jurisdiction", "Other-Task-Name-1", "Other-Task-Name-2"] # Add your task names here ]