from datasets import load_dataset, DatasetDict # Prepare labels seeking_tenant_label = "søger lejer / seeking tenant" not_seeking_tenant_label = "søger ikke lejer / does not seek tenant" candidate_labels = [seeking_tenant_label, not_seeking_tenant_label] # Function to map boolean to a categorical label index def label_mapping(example): if example["is_seeking_tenant"]: return {"labels": candidate_labels.index(seeking_tenant_label)} else: return {"labels": candidate_labels.index(not_seeking_tenant_label)} # Load your dataset from a local JSONL file dataset = load_dataset("json", data_files="listings.jsonl") # Split the dataset into train and temp split_dataset = dataset["train"].train_test_split(test_size=0.3) train_dataset = split_dataset["train"].map(label_mapping) temp_dataset = split_dataset["test"] # Split the temp dataset into validation and test split_temp_dataset = temp_dataset.train_test_split(test_size=0.5) validation_dataset = split_temp_dataset["train"].map(label_mapping) test_dataset = split_temp_dataset["test"].map(label_mapping) # Combine all splits into a DatasetDict final_dataset = DatasetDict( {"train": train_dataset, "validation": validation_dataset, "test": test_dataset} ) final_dataset.push_to_hub("hoaj/fb-housing-posts")