Update README.md
Browse files
README.md
CHANGED
|
@@ -47,3 +47,93 @@ configs:
|
|
| 47 |
- split: intents
|
| 48 |
path: intents/intents-*
|
| 49 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
- split: intents
|
| 48 |
path: intents/intents-*
|
| 49 |
---
|
| 50 |
+
|
| 51 |
+
# events
|
| 52 |
+
|
| 53 |
+
This is a text classification dataset. It is intended for machine learning research and experimentation.
|
| 54 |
+
|
| 55 |
+
This dataset is obtained via formatting another publicly available data to be compatible with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html).
|
| 56 |
+
|
| 57 |
+
## Usage
|
| 58 |
+
|
| 59 |
+
It is intended to be used with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html):
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
from autointent import Dataset
|
| 63 |
+
banking77 = Dataset.from_datasets("AutoIntent/events")
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## Source
|
| 67 |
+
|
| 68 |
+
This dataset is taken from `knowledgator/events_classification_biotech` and formatted with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html):
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
"""Convert events dataset to autointent internal format and scheme."""
|
| 72 |
+
|
| 73 |
+
from datasets import Dataset as HFDataset
|
| 74 |
+
from datasets import load_dataset
|
| 75 |
+
|
| 76 |
+
from autointent import Dataset
|
| 77 |
+
from autointent.schemas import Intent, Sample
|
| 78 |
+
|
| 79 |
+
# these classes contain too few sampls
|
| 80 |
+
names_to_remove = [
|
| 81 |
+
"partnerships & alliances",
|
| 82 |
+
"patent publication",
|
| 83 |
+
"subsidiary establishment",
|
| 84 |
+
"department establishment",
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
def extract_intents_data(events_dataset: HFDataset) -> tuple[list[Intent], dict[str, int]]:
|
| 88 |
+
"""Extract intent names and assign ids to them."""
|
| 89 |
+
intent_names = sorted({name for intents in events_dataset["train"]["all_labels"] for name in intents})
|
| 90 |
+
for n in names_to_remove:
|
| 91 |
+
intent_names.remove(n)
|
| 92 |
+
name_to_id = {name: i for i, name in enumerate(intent_names)}
|
| 93 |
+
intents_data = [Intent(id=i,name=name) for i, name in enumerate(intent_names)]
|
| 94 |
+
return intents_data, name_to_id
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def converting_mapping(example: dict, name_to_id: dict[str, int]) -> dict[str, str | list[int]]:
|
| 98 |
+
"""Extract utterance and label and drop the rest."""
|
| 99 |
+
return {
|
| 100 |
+
"utterance": example["content"],
|
| 101 |
+
"label": [
|
| 102 |
+
name_to_id[intent_name] for intent_name in example["all_labels"] if intent_name not in names_to_remove
|
| 103 |
+
],
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def convert_events(events_split: HFDataset, name_to_id: dict[str, int]) -> list[Sample]:
|
| 108 |
+
"""Convert one split into desired format."""
|
| 109 |
+
events_split = events_split.map(
|
| 110 |
+
converting_mapping, remove_columns=events_split.features.keys(),
|
| 111 |
+
fn_kwargs={"name_to_id": name_to_id}
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
in_domain_samples = []
|
| 115 |
+
oos_samples = [] # actually this dataset doesn't contain oos_samples so this will stay empty
|
| 116 |
+
for sample in events_split.to_list():
|
| 117 |
+
if sample["utterance"] is None:
|
| 118 |
+
continue
|
| 119 |
+
if len(sample["label"]) == 0:
|
| 120 |
+
sample.pop("label")
|
| 121 |
+
oos_samples.append(sample)
|
| 122 |
+
else:
|
| 123 |
+
in_domain_samples.append(sample)
|
| 124 |
+
|
| 125 |
+
return [Sample(**sample) for sample in in_domain_samples + oos_samples]
|
| 126 |
+
|
| 127 |
+
if __name__ == "__main__":
|
| 128 |
+
# FYI: https://github.com/huggingface/datasets/issues/7248
|
| 129 |
+
events_dataset = load_dataset("knowledgator/events_classification_biotech", trust_remote_code=True)
|
| 130 |
+
|
| 131 |
+
intents_data, name_to_id = extract_intents_data(events_dataset)
|
| 132 |
+
|
| 133 |
+
train_samples = convert_events(events_dataset["train"], name_to_id)
|
| 134 |
+
test_samples = convert_events(events_dataset["test"], name_to_id)
|
| 135 |
+
|
| 136 |
+
events_converted = Dataset.from_dict(
|
| 137 |
+
{"train": train_samples, "test": test_samples, "intents": intents_data}
|
| 138 |
+
)
|
| 139 |
+
```
|