|
--- |
|
dataset_info: |
|
- config_name: default |
|
features: |
|
- name: utterance |
|
dtype: string |
|
- name: label |
|
dtype: int64 |
|
splits: |
|
- name: train |
|
num_bytes: 715028 |
|
num_examples: 10003 |
|
- name: test |
|
num_bytes: 204010 |
|
num_examples: 3080 |
|
download_size: 378619 |
|
dataset_size: 919038 |
|
- config_name: intents |
|
features: |
|
- name: id |
|
dtype: int64 |
|
- name: name |
|
dtype: string |
|
- name: tags |
|
sequence: 'null' |
|
- name: regexp_full_match |
|
sequence: 'null' |
|
- name: regexp_partial_match |
|
sequence: 'null' |
|
- name: description |
|
dtype: 'null' |
|
splits: |
|
- name: intents |
|
num_bytes: 3420 |
|
num_examples: 77 |
|
download_size: 4651 |
|
dataset_size: 3420 |
|
configs: |
|
- config_name: default |
|
data_files: |
|
- split: train |
|
path: data/train-* |
|
- split: test |
|
path: data/test-* |
|
- config_name: intents |
|
data_files: |
|
- split: intents |
|
path: intents/intents-* |
|
--- |
|
|
|
|
|
# banking77 |
|
|
|
This is a text classification dataset. It is intended for machine learning research and experimentation. |
|
|
|
This dataset is obtained via formatting another publicly available data to be compatible with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html). |
|
|
|
## Usage |
|
|
|
It is intended to be used with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html): |
|
|
|
```python |
|
from autointent import Dataset |
|
|
|
banking77 = Dataset.from_datasets("AutoIntent/banking77") |
|
``` |
|
|
|
## Source |
|
|
|
This dataset is taken from `PolyAI/banking77` and formatted with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html): |
|
|
|
```python |
|
"""Convert events dataset to autointent internal format and scheme.""" |
|
|
|
import json |
|
|
|
import requests |
|
from datasets import Dataset as HFDataset |
|
from datasets import load_dataset |
|
|
|
from autointent import Dataset |
|
from autointent.schemas import Intent, Sample |
|
|
|
|
|
def get_intents_data(github_file: str | None = None) -> list[Intent]: |
|
"""Load specific json from HF repo.""" |
|
github_file = github_file or "https://huggingface.co/datasets/PolyAI/banking77/resolve/main/dataset_infos.json" |
|
raw_text = requests.get(github_file, timeout=5).text |
|
dataset_description = json.loads(raw_text) |
|
intent_names = dataset_description["default"]["features"]["label"]["names"] |
|
return [Intent(id=i, name=name) for i, name in enumerate(intent_names)] |
|
|
|
|
|
def convert_banking77( |
|
banking77_split: HFDataset, intents_data: list[Intent], shots_per_intent: int | None = None |
|
) -> list[Sample]: |
|
"""Convert one split into desired format.""" |
|
all_labels = sorted(banking77_split.unique("label")) |
|
|
|
n_classes = len(intents_data) |
|
if all_labels != list(range(n_classes)): |
|
msg = "Something's wrong" |
|
raise ValueError(msg) |
|
|
|
classwise_samples = [[] for _ in range(n_classes)] |
|
|
|
for sample in banking77_split: |
|
target_list = classwise_samples[sample["label"]] |
|
if shots_per_intent is not None and len(target_list) >= shots_per_intent: |
|
continue |
|
target_list.append(Sample(utterance=sample["text"], label=sample["label"])) |
|
|
|
samples = [sample for samples_from_one_class in classwise_samples for sample in samples_from_one_class] |
|
print(f"{len(samples)=}") |
|
return samples |
|
|
|
|
|
if __name__ == "__main__": |
|
intents_data = get_intents_data() |
|
banking77 = load_dataset("PolyAI/banking77", trust_remote_code=True) |
|
|
|
train_samples = convert_banking77(banking77["train"], intents_data=intents_data) |
|
test_samples = convert_banking77(banking77["test"], intents_data=intents_data) |
|
|
|
banking77_converted = Dataset.from_dict( |
|
{"train": train_samples, "test": test_samples, "intents": intents_data} |
|
) |
|
``` |
|
|