Datasets:
|
Download README.md from Man1103/OpenJev-Refactored: direct link, hf CLI and curl.
- Browser
- Download file 7.9 kB
-
https://huggingface.co/datasets/Man1103/OpenJev-Refactored/resolve/main/README.md
- Command line
-
hf download hf://datasets/Man1103/OpenJev-Refactored/README.md
-
curl -L -o README.md https://huggingface.co/datasets/Man1103/OpenJev-Refactored/resolve/main/README.md
7.9 kB
| dataset_info: | |
| features: | |
| - name: id | |
| dtype: string | |
| - name: gid | |
| dtype: string | |
| - name: state | |
| dtype: string | |
| - name: common_question | |
| dtype: string | |
| - name: qno-target | |
| list: | |
| - name: kind | |
| dtype: string | |
| - name: metadata | |
| dtype: string | |
| - name: options | |
| list: string | |
| - name: question | |
| dtype: string | |
| - name: question_id | |
| dtype: string | |
| - name: target | |
| list: float64 | |
| splits: | |
| - name: train | |
| num_bytes: 89607430 | |
| num_examples: 7256 | |
| - name: validation | |
| num_bytes: 4296681 | |
| num_examples: 452 | |
| - name: test | |
| num_bytes: 11883647 | |
| num_examples: 893 | |
| download_size: 100359264 | |
| dataset_size: 105787758 | |
| configs: | |
| - config_name: default | |
| data_files: | |
| - split: train | |
| path: data/train-* | |
| - split: test | |
| path: data/test-* | |
| - split: validation | |
| path: data/validation-* | |
| language: | |
| - en | |
| pretty_name: open-jev-refactored | |
| task_categories: | |
| - text-classification | |
| tags: | |
| - Jev | |
| - Decision-modelling | |
| - Curated-Dataset | |
| ### Sample script to tokenize the dataset: | |
| ``` | |
| import datasets | |
| from nltk.tokenize import wordpunct_tokenize | |
| hf_openjev_dataset_id = "Man1103/OpenJev-Refactored" | |
| hf_openjev_dataset = datasets.load_dataset(path=hf_openjev_dataset_id, cache_dir="/content/data/jev/curated") | |
| def get_corpus(dataset): | |
| total_corpus_list = [] | |
| for data in dataset: | |
| state = data["state"] | |
| for qno_target in data["qno-target"]: | |
| question = qno_target["question"] | |
| options = ",".join([option for option in qno_target["options"]]) | |
| total_corpus_list.append(question + options + state) | |
| return total_corpus_list | |
| curated_dataset_train = hf_openjev_dataset["train"] | |
| train_list = get_corpus(curated_dataset_train) | |
| curated_dataset_test = hf_openjev_dataset["test"] | |
| test_list = get_corpus(curated_dataset_test) | |
| curated_dataset_val = hf_openjev_dataset["validation"] | |
| val_list = get_corpus(curated_dataset_val) | |
| total_corpus = train_list + test_list + val_list | |
| total_corpus = ",".join(total_corpus) | |
| tokens = wordpunct_tokenize(total_corpus) | |
| vocab = set(tokens) | |
| token2idx = {token: idx for idx, token in enumerate(vocab)} | |
| idx2token = {idx: token for idx, token in enumerate(vocab)} | |
| print(f"Token count: {len(tokens)}, Vocab size: {len(vocab)}") | |
| ``` | |
| ### Sample script to build training dataloader from the dataset: | |
| ``` | |
| import numpy as np | |
| import torch | |
| from torch.utils.data import DataLoader | |
| from nltk.tokenize import wordpunct_tokenize | |
| from datasets import Dataset | |
| padding_token_id = token2idx["[PAD]"] | |
| unk_token_id = token2idx["[UNK]"] | |
| context_window = 1024 | |
| target_window = 20 | |
| def preprocess_function(batch): | |
| # Lists to store batch outputs | |
| all_states = [] | |
| all_qnos = [] | |
| all_targets = [] | |
| # Process multiple samples in the batch efficiently | |
| for i in range(len(batch["state"])): | |
| state_str = batch["state"][i] | |
| # Look up key safely if naming changed slightly (e.g., options vs qno-target) | |
| qno_targets = batch.get("qno-target", batch.get("options", []))[i] | |
| for qno_target in qno_targets: | |
| question = qno_target["question"] | |
| options = ",".join([option for option in qno_target["options"]]) | |
| qno_str = question + options | |
| target = qno_target["target"] | |
| # 1. Tokenize into raw strings first | |
| state_tokens = wordpunct_tokenize(state_str) | |
| qno_tokens = wordpunct_tokenize(qno_str) | |
| # 2. Convert to integer IDs FIRST (safely using UNK) | |
| state_ids = [token2idx.get(t, unk_token_id) for t in state_tokens] | |
| qno_ids = [token2idx.get(t, unk_token_id) for t in qno_tokens] | |
| # 3. NOW apply numerical truncation or padding safely | |
| if len(state_ids) < context_window: | |
| state_ids += [padding_token_id] * (context_window - len(state_ids)) | |
| else: | |
| state_ids = state_ids[:context_window] | |
| if len(qno_ids) < context_window: | |
| qno_ids += [padding_token_id] * (context_window - len(qno_ids)) | |
| else: | |
| qno_ids = qno_ids[:context_window] | |
| if len(target) < target_window: | |
| target = list(target) + [0] * (target_window - len(target)) | |
| else: | |
| target = list(target)[:target_window] | |
| all_states.append(state_ids) | |
| all_qnos.append(qno_ids) | |
| all_targets.append(target) | |
| return {"state_ids": all_states, "qno_ids": all_qnos, "target_ids": all_targets} | |
| # NATIVE HUGGING FACE PIPELINE | |
| # Map your curated dataset over your preprocessing function (batched is fast!) | |
| curated_dataset_train = hf_openjev_dataset["train"] | |
| processed_dataset = curated_dataset_train.map( | |
| preprocess_function, | |
| batched=True, | |
| remove_columns=curated_dataset_train.column_names | |
| ) | |
| # Set format directly to PyTorch tensors so it mimics a TensorDataset | |
| processed_dataset.set_format(type="torch", columns=["state_ids", "qno_ids", "target_ids"]) | |
| # Use the native PyTorch DataLoader directly with the HF Dataset | |
| training_dataloader = DataLoader( | |
| dataset=processed_dataset, | |
| batch_size=32, | |
| shuffle=True, | |
| num_workers=2 | |
| ) | |
| print(f"Total processed samples: {len(processed_dataset)}") | |
| print(f"Total batches: {len(training_dataloader)}") | |
| ``` | |
| ### For researchers only - this is the script used to clone and curate this dataset from original dataset `TypeSafeAI/Open-Jev`: | |
| ``` | |
| def create_curated_dataset(dataset, max_samples: int): | |
| selected_dataset = dataset.select(range(max_sample)) if hasattr(dataset, "select") else dataset.select(range(min(max_sample, len(dataset)))) | |
| # 2. OPTIMIZATION: Group by 'group_id' in O(N) time instead of using .filter() in a loop | |
| grouped_data = defaultdict(list) | |
| for row in selected_dataset: | |
| grouped_data[row["group_id"]].append(row) | |
| curated_list = [] | |
| # 3. Process grouped data | |
| for gid, rows in grouped_data.items(): | |
| full_gid_sample = {} | |
| options_list = [] | |
| for data in rows: | |
| id = data["id"] | |
| sample_kind = data["kind"] | |
| state = data["state_json"].strip('"').strip("'") | |
| question_id = data["id"] | |
| question = data["question"].strip('"').strip("'") | |
| options = [option.strip('"').strip("'") for option in data["options"]] | |
| target = data["target"] | |
| metadata = data["metadata_json"] | |
| qno_dict = { | |
| "question_id": question_id, | |
| "kind": sample_kind, | |
| "question": question, | |
| "options": options, | |
| "target": target, | |
| "metadata": metadata | |
| } | |
| full_gid_sample["id"] = id | |
| full_gid_sample["gid"] = gid | |
| full_gid_sample["state"] = state | |
| full_gid_sample["common_question"] = question | |
| options_list.append(qno_dict) | |
| full_gid_sample["qno-target"] = options_list | |
| curated_list.append(full_gid_sample) | |
| # 4. FINAL CONVERSION: Cast your curated list back to a Hugging Face Dataset | |
| curated_dataset = Dataset.from_list(curated_list) | |
| return curated_dataset | |
| # 1. FIX: Grab the first 10 elements consistently using select | |
| train_set = jev_dataset["train"] | |
| max_sample = len(train_set) | |
| curated_dataset_train = create_curated_dataset(train_set, max_sample) | |
| val_set = jev_dataset["validation"] | |
| max_sample = len(val_set) | |
| curated_dataset_val = create_curated_dataset(val_set, max_sample) | |
| test_set = jev_dataset["test"] | |
| max_sample = len(test_set) | |
| curated_dataset_test = create_curated_dataset(test_set, max_sample) | |
| hf_curated_dataset = datasets.DatasetDict({ | |
| "train": curated_dataset_train, | |
| "validation": curated_dataset_val, | |
| "test": curated_dataset_test | |
| }) | |
| # Inspect your new standard Hugging Face dataset | |
| print(hf_curated_dataset) | |
| ``` |