Datasets:
File size: 7,897 Bytes
2bf7886 12751c1 2bf7886 c92b038 2bf7886 c92b038 2bf7886 2786546 2bf7886 1e130fb 2bf7886 12751c1 2bf7886 096d113 12751c1 096d113 2bf7886 12751c1 2bf7886 12751c1 2bf7886 096d113 bfdf60b 2bf7886 bfdf60b 249fc6d bfdf60b 249fc6d bfdf60b 373aab9 bfdf60b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | ---
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)
``` |