Datasets:
Tasks:
Text Classification
Sub-tasks:
sentiment-classification
Languages:
Chinese
Size:
100K - 1M
Tags:
jd
License:
wangsong
commited on
Commit
·
8b359ff
1
Parent(s):
b8d6196
Upload jd21.py
Browse files
jd21.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from datasets import Value, ClassLabel,Sequence
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
|
6 |
+
_JD21_CITATION = """\
|
7 |
+
|
8 |
+
"""
|
9 |
+
|
10 |
+
_JD21_DESCRIPTION = """\
|
11 |
+
GLUE, the General Language Understanding Evaluation benchmark
|
12 |
+
(https://gluebenchmark.com/) is a collection of resources for training,
|
13 |
+
evaluating, and analyzing natural language understanding systems.
|
14 |
+
"""
|
15 |
+
|
16 |
+
class JD21Config(datasets.BuilderConfig):
|
17 |
+
|
18 |
+
def __init__(
|
19 |
+
self,
|
20 |
+
text_features,
|
21 |
+
label_column,
|
22 |
+
data_url,
|
23 |
+
data_dir,
|
24 |
+
citation,
|
25 |
+
url,
|
26 |
+
label_classes=None,
|
27 |
+
process_label=lambda x: x,
|
28 |
+
**kwargs,
|
29 |
+
):
|
30 |
+
super(JD21Config, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
31 |
+
|
32 |
+
self.text_features = text_features
|
33 |
+
self.label_column = label_column
|
34 |
+
self.label_classes = label_classes
|
35 |
+
self.data_url = data_url
|
36 |
+
self.data_dir = data_dir
|
37 |
+
self.citation = citation
|
38 |
+
self.url = url
|
39 |
+
self.process_label = process_label
|
40 |
+
|
41 |
+
class JD21(datasets.GeneratorBasedBuilder):
|
42 |
+
domain_list = ['褪黑素', '维生素', '无线耳机', '蛋白粉', '游戏机', '电视', 'MacBook', '洗面奶', '智能手表', '吹风机', '小米手机', '红米手机', '护肤品',
|
43 |
+
'电动牙刷', 'iPhone', '海鲜', '酒', '平板电脑', '修复霜', '运动鞋', '智能手环']
|
44 |
+
|
45 |
+
BUILDER_CONFIGS = [
|
46 |
+
JD21Config(name=domain_name,
|
47 |
+
description= f'comments of JD {domain_name}.',
|
48 |
+
text_features={'sentence':'sentence', 'domain':'domain'},
|
49 |
+
label_classes=['POS','NEG'],
|
50 |
+
label_column='label',
|
51 |
+
citation="",
|
52 |
+
data_dir= r"D:\Personal\CodeBase\Continual Learning\continual-learning-framework-for-NLP\datasets\jd21\\",
|
53 |
+
data_url = "",
|
54 |
+
url='https://github.com/ws719547997/LNB-DA')
|
55 |
+
for domain_name in domain_list
|
56 |
+
]
|
57 |
+
|
58 |
+
def _info(self):
|
59 |
+
features = {'id':Value(dtype='int32', id=None),
|
60 |
+
'domain':Value(dtype='string', id=None),
|
61 |
+
'label':ClassLabel(num_classes=2, names=['POS', 'NEG'], names_file=None, id=None),
|
62 |
+
'rank':Value(dtype='int32', id=None),
|
63 |
+
'sentence':Value(dtype='string', id=None)}
|
64 |
+
|
65 |
+
return datasets.DatasetInfo(
|
66 |
+
description=_JD21_DESCRIPTION,
|
67 |
+
features=datasets.Features(features),
|
68 |
+
homepage=self.config.url,
|
69 |
+
citation=self.config.citation + "\n" + _JD21_CITATION,
|
70 |
+
)
|
71 |
+
|
72 |
+
def _split_generators(self, dl_manager):
|
73 |
+
test_file = rf'{self.config.data_dir}data\test\{self.config.name}.txt'
|
74 |
+
dev_file = rf'{self.config.data_dir}data\dev\{self.config.name}.txt'
|
75 |
+
train_file = rf'{self.config.data_dir}data\train\{self.config.name}.txt'
|
76 |
+
return [datasets.SplitGenerator(name=datasets.Split.TEST,
|
77 |
+
gen_kwargs={
|
78 |
+
"data_file": test_file,
|
79 |
+
"split": "test",
|
80 |
+
},),
|
81 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION,
|
82 |
+
gen_kwargs={
|
83 |
+
"data_file": dev_file,
|
84 |
+
"split": "dev",
|
85 |
+
},),
|
86 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
87 |
+
gen_kwargs={
|
88 |
+
"data_file": train_file,
|
89 |
+
"split": "train",
|
90 |
+
},)]
|
91 |
+
|
92 |
+
def _generate_examples(self, data_file, split):
|
93 |
+
with open(data_file, 'r', encoding='utf-8') as f:
|
94 |
+
for line in f:
|
95 |
+
lin = line.strip()
|
96 |
+
if not lin:
|
97 |
+
continue
|
98 |
+
lin_sp = lin.split('\t')
|
99 |
+
if len(lin_sp) < 5:
|
100 |
+
continue
|
101 |
+
# id, {example}
|
102 |
+
yield lin_sp[0], {'sentence':lin_sp[4],'domain':lin_sp[1], 'label':lin_sp[2], 'id':lin_sp[0], 'rank':lin_sp[3]}
|