Upload loading_script.py with huggingface_hub
Browse files- loading_script.py +20 -0
loading_script.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import os
|
| 3 |
+
from datasets import Dataset, DatasetDict
|
| 4 |
+
|
| 5 |
+
class VulnAIDataset:
|
| 6 |
+
def __init__(self, data_dir):
|
| 7 |
+
self.data_dir = data_dir
|
| 8 |
+
def load(self):
|
| 9 |
+
splits = {}
|
| 10 |
+
for split in ["train", "validation", "test"]:
|
| 11 |
+
path = os.path.join(self.data_dir, "data", f"{split}.csv")
|
| 12 |
+
if os.path.exists(path):
|
| 13 |
+
with open(path, "r", encoding="utf-8") as f:
|
| 14 |
+
reader = csv.DictReader(f)
|
| 15 |
+
rows = list(reader)
|
| 16 |
+
splits[split] = Dataset.from_list(rows)
|
| 17 |
+
return DatasetDict(splits)
|
| 18 |
+
|
| 19 |
+
def load_dataset(data_dir):
|
| 20 |
+
return VulnAIDataset(data_dir).load()
|