ruanchaves
commited on
Commit
·
71893f0
1
Parent(s):
009405f
Create nru_hse.py
Browse files- nru_hse.py +63 -0
nru_hse.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""HSE Russian dataset by Glushkova et al.."""
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import pandas as pd
|
5 |
+
from functools import reduce
|
6 |
+
|
7 |
+
_CITATION = """
|
8 |
+
@article{glushkova2019char,
|
9 |
+
title={Char-RNN and Active Learning for Hashtag Segmentation},
|
10 |
+
author={Glushkova, Taisiya and Artemova, Ekaterina},
|
11 |
+
journal={arXiv preprint arXiv:1911.03270},
|
12 |
+
year={2019}
|
13 |
+
}
|
14 |
+
"""
|
15 |
+
|
16 |
+
_DESCRIPTION = """
|
17 |
+
2000 real hashtags collected from several pages about civil services on vk.com (a Russian social network)
|
18 |
+
and then segmented manually.
|
19 |
+
"""
|
20 |
+
_URL = "https://raw.githubusercontent.com/glushkovato/hashtag_segmentation/master/data/test_rus.csv"
|
21 |
+
|
22 |
+
|
23 |
+
class HSE(datasets.GeneratorBasedBuilder):
|
24 |
+
|
25 |
+
VERSION = datasets.Version("1.0.0")
|
26 |
+
|
27 |
+
def _info(self):
|
28 |
+
return datasets.DatasetInfo(
|
29 |
+
description=_DESCRIPTION,
|
30 |
+
features=datasets.Features(
|
31 |
+
{
|
32 |
+
"index": datasets.Value("int32"),
|
33 |
+
"hashtag": datasets.Value("string"),
|
34 |
+
"segmentation": datasets.Value("string")
|
35 |
+
}
|
36 |
+
),
|
37 |
+
supervised_keys=None,
|
38 |
+
homepage="https://github.com/glushkovato/hashtag_segmentation",
|
39 |
+
citation=_CITATION,
|
40 |
+
)
|
41 |
+
|
42 |
+
def _split_generators(self, dl_manager):
|
43 |
+
downloaded_files = dl_manager.download(_URL)
|
44 |
+
return [
|
45 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files }),
|
46 |
+
]
|
47 |
+
|
48 |
+
def _generate_examples(self, filepath):
|
49 |
+
|
50 |
+
df = pd.read_csv(filepath)
|
51 |
+
records = df.to_dict("records")
|
52 |
+
|
53 |
+
def get_segmentation(a, b):
|
54 |
+
return "".join(reduce(lambda x,y: x + y, list(zip(a,b)))).replace("0","").replace("1"," ").strip()
|
55 |
+
|
56 |
+
for idx, row in enumerate(records):
|
57 |
+
yield idx, {
|
58 |
+
"index": idx,
|
59 |
+
"hashtag": row["hashtag"],
|
60 |
+
"segmentation": get_segmentation(
|
61 |
+
row["hashtag"],
|
62 |
+
row["true_segmentation"]
|
63 |
+
)}
|