Datasets:
Add files using upload-large-folder tool
Browse files
README.md
CHANGED
|
@@ -153,7 +153,7 @@ Path(meta/embedding_base_path) / ref_path_vocab[ref_path_id]
|
|
| 153 |
|
| 154 |
If you only use token-class graph targets (`graph_output_mode="toks"`), these external embedding shards are not required.
|
| 155 |
|
| 156 |
-
The external token embedding shards are not included in this Hugging Face release because they are too large to upload. If you need to use `graph_output_mode="embedding"`, you can regenerate compatible embeddings with
|
| 157 |
|
| 158 |
```text
|
| 159 |
https://github.com/yuanhuang0825/cilin-simcse.git
|
|
@@ -258,85 +258,87 @@ print("dep:", dep_kind.shape, dep_parent.shape)
|
|
| 258 |
print("amr:", amr_kind.shape, amr_src.shape, amr_dst.shape, amr_edge_label.shape)
|
| 259 |
```
|
| 260 |
|
| 261 |
-
###
|
| 262 |
|
| 263 |
-
The
|
| 264 |
|
| 265 |
```python
|
|
|
|
|
|
|
| 266 |
from torch.utils.data import DataLoader
|
| 267 |
|
| 268 |
-
from utils.load_dataset import SkypileH5Dataset, make_skypile_h5_collate_fn
|
| 269 |
-
|
| 270 |
-
dataset = SkypileH5Dataset(
|
| 271 |
-
path="dataset/skypile1.5B_h5",
|
| 272 |
-
h5_pattern="skypile_*.h5",
|
| 273 |
-
vocab_dir="dataset/skypile1.5B_h5/vocabs",
|
| 274 |
-
return_meta=True,
|
| 275 |
-
graph_output_mode="toks",
|
| 276 |
-
graph_output_tok_top_n=30000,
|
| 277 |
-
tokenizer_input_mode="stored",
|
| 278 |
-
filter_by_max_node=True,
|
| 279 |
-
max_node=100,
|
| 280 |
-
)
|
| 281 |
-
|
| 282 |
-
collate_fn = make_skypile_h5_collate_fn(
|
| 283 |
-
pad_token_id=0,
|
| 284 |
-
null_id=0,
|
| 285 |
-
no_edge_id=0,
|
| 286 |
-
max_node=100,
|
| 287 |
-
)
|
| 288 |
-
|
| 289 |
-
loader = DataLoader(
|
| 290 |
-
dataset,
|
| 291 |
-
batch_size=32,
|
| 292 |
-
shuffle=True,
|
| 293 |
-
num_workers=4,
|
| 294 |
-
collate_fn=collate_fn,
|
| 295 |
-
)
|
| 296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
batch = next(iter(loader))
|
| 298 |
-
print(batch["
|
| 299 |
-
print(batch["dep"]["kind_tgt"].shape)
|
| 300 |
-
print(batch["amr"]["edge_tgt"].shape)
|
| 301 |
-
```
|
| 302 |
-
|
| 303 |
-
The loader returns:
|
| 304 |
-
|
| 305 |
-
```python
|
| 306 |
-
{
|
| 307 |
-
"tokenizer_inputs": {
|
| 308 |
-
"input_ids": "LongTensor[L]",
|
| 309 |
-
"attention_mask": "LongTensor[L]",
|
| 310 |
-
},
|
| 311 |
-
"dep": {
|
| 312 |
-
"kind_tgt": "LongTensor[N_dep]",
|
| 313 |
-
"embed_tgt": "FloatTensor[N_dep, D]",
|
| 314 |
-
"embed_mask": "BoolTensor[N_dep]",
|
| 315 |
-
"edge_tgt": "LongTensor[N_dep, N_dep]",
|
| 316 |
-
},
|
| 317 |
-
"amr": {
|
| 318 |
-
"kind_tgt": "LongTensor[N_amr]",
|
| 319 |
-
"embed_tgt": "FloatTensor[N_amr, D]",
|
| 320 |
-
"embed_mask": "BoolTensor[N_amr]",
|
| 321 |
-
"edge_tgt": "LongTensor[N_amr, N_amr]",
|
| 322 |
-
},
|
| 323 |
-
"meta": {
|
| 324 |
-
"index": "int",
|
| 325 |
-
"dataset_index": "int",
|
| 326 |
-
"source_index": "int",
|
| 327 |
-
"shard_idx": "int",
|
| 328 |
-
"local_idx": "int",
|
| 329 |
-
"ref_path_id": "int",
|
| 330 |
-
"ref_index": "int",
|
| 331 |
-
},
|
| 332 |
-
}
|
| 333 |
```
|
| 334 |
|
| 335 |
-
After
|
| 336 |
|
| 337 |
## Graph Target Modes
|
| 338 |
|
| 339 |
-
The
|
| 340 |
|
| 341 |
### `graph_output_mode="toks"`
|
| 342 |
|
|
@@ -353,7 +355,7 @@ The RGG-VAE loader supports two graph target modes.
|
|
| 353 |
- Requires local access to the path stored in `meta/embedding_base_path`.
|
| 354 |
- The external embedding shards are not uploaded with this dataset because of their size.
|
| 355 |
- Compatible embeddings can be regenerated with `https://github.com/yuanhuang0825/cilin-simcse.git`.
|
| 356 |
-
- Supports optional embedding transforms such as mean centering, PCA component removal, and L2 normalization
|
| 357 |
|
| 358 |
## Known Limitations
|
| 359 |
|
|
|
|
| 153 |
|
| 154 |
If you only use token-class graph targets (`graph_output_mode="toks"`), these external embedding shards are not required.
|
| 155 |
|
| 156 |
+
The external token embedding shards are not included in this Hugging Face release because they are too large to upload. If you need to use `graph_output_mode="embedding"`, you can regenerate compatible embeddings with:
|
| 157 |
|
| 158 |
```text
|
| 159 |
https://github.com/yuanhuang0825/cilin-simcse.git
|
|
|
|
| 258 |
print("amr:", amr_kind.shape, amr_src.shape, amr_dst.shape, amr_edge_label.shape)
|
| 259 |
```
|
| 260 |
|
| 261 |
+
### Build a PyTorch Dataset Loader
|
| 262 |
|
| 263 |
+
The following minimal example shows how to wrap one HDF5 shard as a PyTorch dataset without relying on project-specific code.
|
| 264 |
|
| 265 |
```python
|
| 266 |
+
import h5py
|
| 267 |
+
import torch
|
| 268 |
from torch.utils.data import DataLoader
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
+
class SkyGraphH5Shard(torch.utils.data.Dataset):
|
| 272 |
+
def __init__(self, h5_path):
|
| 273 |
+
self.h5_path = h5_path
|
| 274 |
+
self.h5f = None
|
| 275 |
+
|
| 276 |
+
def _file(self):
|
| 277 |
+
if self.h5f is None:
|
| 278 |
+
self.h5f = h5py.File(self.h5_path, "r")
|
| 279 |
+
return self.h5f
|
| 280 |
+
|
| 281 |
+
def __len__(self):
|
| 282 |
+
h5f = self._file()
|
| 283 |
+
return int(h5f["meta"]["num_sentences"][()])
|
| 284 |
+
|
| 285 |
+
def __getitem__(self, i):
|
| 286 |
+
h5f = self._file()
|
| 287 |
+
|
| 288 |
+
token_start = h5f["token"]["token_offsets"][i]
|
| 289 |
+
token_end = h5f["token"]["token_offsets"][i + 1]
|
| 290 |
+
|
| 291 |
+
dep_start = h5f["dep"]["node_offsets"][i]
|
| 292 |
+
dep_end = h5f["dep"]["node_offsets"][i + 1]
|
| 293 |
+
|
| 294 |
+
amr_node_start = h5f["amr"]["node_offsets"][i]
|
| 295 |
+
amr_node_end = h5f["amr"]["node_offsets"][i + 1]
|
| 296 |
+
amr_edge_start = h5f["amr"]["edge_offsets"][i]
|
| 297 |
+
amr_edge_end = h5f["amr"]["edge_offsets"][i + 1]
|
| 298 |
+
|
| 299 |
+
return {
|
| 300 |
+
"input_ids": torch.tensor(
|
| 301 |
+
h5f["token"]["tokens_flat"][token_start:token_end],
|
| 302 |
+
dtype=torch.long,
|
| 303 |
+
),
|
| 304 |
+
"dep_kind": torch.tensor(
|
| 305 |
+
h5f["dep"]["kind_tgt_flat"][dep_start:dep_end],
|
| 306 |
+
dtype=torch.long,
|
| 307 |
+
),
|
| 308 |
+
"dep_parent": torch.tensor(
|
| 309 |
+
h5f["dep"]["parent_flat"][dep_start:dep_end],
|
| 310 |
+
dtype=torch.long,
|
| 311 |
+
),
|
| 312 |
+
"amr_kind": torch.tensor(
|
| 313 |
+
h5f["amr"]["kind_tgt_flat"][amr_node_start:amr_node_end],
|
| 314 |
+
dtype=torch.long,
|
| 315 |
+
),
|
| 316 |
+
"amr_src": torch.tensor(
|
| 317 |
+
h5f["amr"]["src_flat"][amr_edge_start:amr_edge_end],
|
| 318 |
+
dtype=torch.long,
|
| 319 |
+
),
|
| 320 |
+
"amr_dst": torch.tensor(
|
| 321 |
+
h5f["amr"]["dst_flat"][amr_edge_start:amr_edge_end],
|
| 322 |
+
dtype=torch.long,
|
| 323 |
+
),
|
| 324 |
+
"amr_edge_label": torch.tensor(
|
| 325 |
+
h5f["amr"]["edge_label_flat"][amr_edge_start:amr_edge_end],
|
| 326 |
+
dtype=torch.long,
|
| 327 |
+
),
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
dataset = SkyGraphH5Shard("skypile_00000.h5")
|
| 332 |
+
loader = DataLoader(dataset, batch_size=1, shuffle=True)
|
| 333 |
batch = next(iter(loader))
|
| 334 |
+
print(batch["input_ids"].shape)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
```
|
| 336 |
|
| 337 |
+
After collation, graph and token tensors are typically padded to batch shapes such as `[B, L_max]`, `[B, N_dep_max]`, `[B, N_dep_max, N_dep_max]`, `[B, N_amr_max]`, and `[B, N_amr_max, N_amr_max]`.
|
| 338 |
|
| 339 |
## Graph Target Modes
|
| 340 |
|
| 341 |
+
The dataset schema supports two common graph target modes.
|
| 342 |
|
| 343 |
### `graph_output_mode="toks"`
|
| 344 |
|
|
|
|
| 355 |
- Requires local access to the path stored in `meta/embedding_base_path`.
|
| 356 |
- The external embedding shards are not uploaded with this dataset because of their size.
|
| 357 |
- Compatible embeddings can be regenerated with `https://github.com/yuanhuang0825/cilin-simcse.git`.
|
| 358 |
+
- Supports optional embedding transforms such as mean centering, PCA component removal, and L2 normalization.
|
| 359 |
|
| 360 |
## Known Limitations
|
| 361 |
|