Update README.md
Browse files
README.md
CHANGED
@@ -74,11 +74,11 @@ This dataset is taken from `ucirvine/reuters21578` and formatted with our [AutoI
|
|
74 |
|
75 |
```python
|
76 |
from collections import defaultdict
|
77 |
-
from datasets import load_dataset
|
78 |
from autointent import Dataset
|
|
|
79 |
|
80 |
# load original data
|
81 |
-
reuters = load_dataset("ucirvine/reuters21578", "ModHayes", trust_remote_code=True)
|
82 |
|
83 |
# remove low-resource classes
|
84 |
counter = defaultdict(int)
|
@@ -94,20 +94,19 @@ for n in names_to_remove:
|
|
94 |
name_to_id = {name: i for i, name in enumerate(intent_names)}
|
95 |
|
96 |
# extract only texts and labels
|
97 |
-
def transform(
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
sample.pop("label")
|
109 |
|
110 |
# format
|
111 |
intents = [{"id": i, "name": name} for i, name in enumerate(intent_names)]
|
112 |
-
reuters_converted = Dataset.from_dict({"intents": intents, "train":
|
113 |
```
|
|
|
74 |
|
75 |
```python
|
76 |
from collections import defaultdict
|
|
|
77 |
from autointent import Dataset
|
78 |
+
import datasets
|
79 |
|
80 |
# load original data
|
81 |
+
reuters = datasets.load_dataset("ucirvine/reuters21578", "ModHayes", trust_remote_code=True)
|
82 |
|
83 |
# remove low-resource classes
|
84 |
counter = defaultdict(int)
|
|
|
94 |
name_to_id = {name: i for i, name in enumerate(intent_names)}
|
95 |
|
96 |
# extract only texts and labels
|
97 |
+
def transform(ds: datasets.Dataset) -> list[dict]:
|
98 |
+
def _transform(example: dict):
|
99 |
+
return {
|
100 |
+
"utterance": example["text"],
|
101 |
+
"label": [int(name in example["topics"]) for name in intent_names if name not in names_to_remove]
|
102 |
+
}
|
103 |
+
ds = ds.map(_transform, remove_columns=ds.features.keys())
|
104 |
+
return [sample for sample in ds if sum(sample["label"]) != 0]
|
105 |
+
|
106 |
+
train = transform(reuters["train"])
|
107 |
+
test = transform(reuters["test"])
|
|
|
108 |
|
109 |
# format
|
110 |
intents = [{"id": i, "name": name} for i, name in enumerate(intent_names)]
|
111 |
+
reuters_converted = Dataset.from_dict({"intents": intents, "train": train, "test": test})
|
112 |
```
|