Datasets:
Upload chinese_metaphor_dataset.py
Browse files- chinese_metaphor_dataset.py +85 -0
chinese_metaphor_dataset.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
# import pandas as pd
|
3 |
+
import json
|
4 |
+
|
5 |
+
_CITATION = """\
|
6 |
+
@inproceedings{li-etal-2022-cm,
|
7 |
+
title = "{CM}-Gen: A Neural Framework for {C}hinese Metaphor Generation with Explicit Context Modelling",
|
8 |
+
author = "Li, Yucheng and
|
9 |
+
Lin, Chenghua and
|
10 |
+
Guerin, Frank",
|
11 |
+
booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
|
12 |
+
month = oct,
|
13 |
+
year = "2022",
|
14 |
+
address = "Gyeongju, Republic of Korea",
|
15 |
+
publisher = "International Committee on Computational Linguistics",
|
16 |
+
url = "https://aclanthology.org/2022.coling-1.563",
|
17 |
+
pages = "6468--6479",
|
18 |
+
}
|
19 |
+
|
20 |
+
@misc{li-inlg-2022-nominal,
|
21 |
+
doi = {10.48550/ARXIV.2206.05195},
|
22 |
+
url = {https://arxiv.org/abs/2206.05195},
|
23 |
+
author = {Li, Yucheng and Lin, Chenghua and Geurin, Frank},
|
24 |
+
keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
25 |
+
title = {Nominal Metaphor Generation with Multitask Learning},
|
26 |
+
publisher = {arXiv},
|
27 |
+
year = {2022},
|
28 |
+
copyright = {arXiv.org perpetual, non-exclusive license}
|
29 |
+
}
|
30 |
+
"""
|
31 |
+
|
32 |
+
_DESCRIPTION = """\
|
33 |
+
Chinese Metaphor Corpus
|
34 |
+
|
35 |
+
The first Chinese metaphor corpus serving both metaphor identification and generation.
|
36 |
+
首个中文比喻数据集,可以用于中文比喻识别与中文比喻生成。
|
37 |
+
"""
|
38 |
+
|
39 |
+
_HOMEPAGE = "https://github.com/liyucheng09/Metaphor_Generator"
|
40 |
+
|
41 |
+
_URL = 'https://github.com/liyucheng09/Metaphor_Generator/raw/master/CMC/zh_CMC2.txt'
|
42 |
+
|
43 |
+
class CMC(datasets.GeneratorBasedBuilder):
|
44 |
+
|
45 |
+
BUILDER_CONFIG_CLASS=datasets.BuilderConfig
|
46 |
+
|
47 |
+
def _info(self):
|
48 |
+
|
49 |
+
feature = {
|
50 |
+
'sent': datasets.Value('string'),
|
51 |
+
'tenor': datasets.Value('string'),
|
52 |
+
'comparator': datasets.Value('string'),
|
53 |
+
'vehicle':datasets.Value('string'),
|
54 |
+
}
|
55 |
+
|
56 |
+
return datasets.DatasetInfo(
|
57 |
+
description=_DESCRIPTION,
|
58 |
+
features=datasets.Features(feature),
|
59 |
+
homepage=_HOMEPAGE,
|
60 |
+
citation=_CITATION
|
61 |
+
)
|
62 |
+
|
63 |
+
def _split_generators(self, dl_manager):
|
64 |
+
|
65 |
+
cmc_file = dl_manager.download(_URL)
|
66 |
+
|
67 |
+
return datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'cmc_file': cmc_file}),
|
68 |
+
# return [
|
69 |
+
# datasets.SplitGenerator(name='hard', gen_kwargs={'filepath': self.config.data_path}),
|
70 |
+
# ]
|
71 |
+
|
72 |
+
def _generate_examples(self, cmc_file):
|
73 |
+
with open(cmc_file, encoding='utf-8') as f:
|
74 |
+
count = 0
|
75 |
+
for line in f:
|
76 |
+
if not line:
|
77 |
+
continue
|
78 |
+
data = json.loads(line)
|
79 |
+
yield count, {
|
80 |
+
'sent': data['sent'],
|
81 |
+
'tenor': data['tenor'],
|
82 |
+
'comparator': data['comparator'],
|
83 |
+
'vehicle': data['vehicle']
|
84 |
+
}
|
85 |
+
count+=1
|