File size: 3,343 Bytes
af69343
 
05330dd
af69343
 
 
 
 
 
 
 
 
f512deb
 
 
 
 
05330dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af69343
 
 
 
 
f512deb
 
05330dd
 
 
 
efaeae2
 
 
 
af69343
beef94c
 
 
 
 
 
 
 
 
 
 
 
 
 
7287d4a
beef94c
 
 
 
 
 
 
ca7b05f
 
 
beef94c
ca7b05f
beef94c
ca7b05f
 
beef94c
ca7b05f
 
beef94c
ca7b05f
 
 
 
 
 
beef94c
 
ca7b05f
 
 
 
 
 
 
 
 
beef94c
 
 
ca7b05f
 
 
 
 
 
 
 
 
beef94c
ca7b05f
efaeae2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
dataset_info:
- config_name: default
  features:
  - name: utterance
    dtype: string
  - name: label
    dtype: int64
  splits:
  - name: train
    num_bytes: 1315631
    num_examples: 13784
  - name: test
    num_bytes: 68315
    num_examples: 700
  download_size: 581872
  dataset_size: 1383946
- 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: 270
    num_examples: 7
  download_size: 3121
  dataset_size: 270
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-*
task_categories:
- text-classification
language:
- ru
---

# Russian snips

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

snips_ru = Dataset.from_hub("AutoIntent/snips_ru")
```

## Source

This dataset is taken from private github repository `LadaNikitina/Snips` and formatted with our [AutoIntent Library](https://deeppavlov.github.io/AutoIntent/index.html):

```python
"""Convert snips dataset to autointent internal format and scheme."""  # noqa: INP001

from datasets import Dataset as HFDataset
from datasets import load_from_disk

from autointent import Dataset
from autointent.schemas import Intent, Sample


def _extract_intents_data(split: HFDataset) -> tuple[dict[str, int], list[Intent]]:
    intent_names = sorted(split.unique("intent"))
    name_to_id = dict(zip(intent_names, range(len(intent_names)), strict=False))
    return name_to_id, [Intent(id=i, name=name) for i, name in enumerate(intent_names)]


def convert_rusnips(snips_split: HFDataset, name_to_id: dict[str, int]) -> list[Sample]:
    """Convert one split into desired format."""
    n_classes = len(name_to_id)

    classwise_utterance_records = [[] for _ in range(n_classes)]

    for sample in snips_split:
        txt, name = sample["text"], sample["intent"]
        intent_id = name_to_id[name]
        target_list = classwise_utterance_records[intent_id]
        target_list.append({"utterance": txt, "label": intent_id})

    return [
        Sample(**sample) for samples_from_one_class in classwise_utterance_records for sample in samples_from_one_class
    ]


if __name__ == "__main__":
    # ! git clone git@github.com:LadaNikitina/Snips data/RuSnips
    # ! rm -rf data/RuSnips/.git
    rusnips = load_from_disk("data/RuSnips")

    name_to_id, intents_data = _extract_intents_data(rusnips["train"])

    train_samples = convert_rusnips(rusnips["train"], name_to_id=name_to_id)
    test_samples = convert_rusnips(rusnips["test"], name_to_id=name_to_id)

    dataset = Dataset.from_dict({"train": train_samples, "test": test_samples, "intents": intents_data})
```