Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
sentiment-classification
Languages:
Chinese
Size:
100K - 1M
Tags:
stock
License:
wangsong
commited on
Commit
•
d588e01
1
Parent(s):
0521b79
Upload stock11.py
Browse files- stock11.py +104 -0
stock11.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from datasets import Value, ClassLabel,Sequence
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
|
6 |
+
_STOCK11_CITATION = """\
|
7 |
+
|
8 |
+
"""
|
9 |
+
|
10 |
+
_STOCK11_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 STOCK11Config(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(STOCK11Config, 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 STOCK11(datasets.GeneratorBasedBuilder):
|
42 |
+
domain_list = ['airline', 'car', 'communication', 'energy', 'finance', 'manufacture', 'medical', 'Real estate', 'tech', 'traffic', 'wine']
|
43 |
+
|
44 |
+
BUILDER_CONFIGS = [
|
45 |
+
STOCK11Config(name=domain_name,
|
46 |
+
description= f'comments of {domain_name}.',
|
47 |
+
text_features={'sentence':'sentence', 'domain':'domain'},
|
48 |
+
label_classes=['POS','NEG', 'NEU'],
|
49 |
+
label_column='label',
|
50 |
+
citation="",
|
51 |
+
data_dir= "",
|
52 |
+
data_url = r"https://huggingface.co/datasets/kuroneko3578/stock11/blob/main/data.7z",
|
53 |
+
url='https://github.com/ws719547997/LNB-DA')
|
54 |
+
for domain_name in domain_list
|
55 |
+
]
|
56 |
+
|
57 |
+
def _info(self):
|
58 |
+
features = {'id':Value(dtype='int32', id=None),
|
59 |
+
'domain':Value(dtype='string', id=None),
|
60 |
+
'label':ClassLabel(num_classes=3, names=['POS','NEG', 'NEU'], names_file=None, id=None),
|
61 |
+
'rank':Value(dtype='int32', id=None),
|
62 |
+
'sentence':Value(dtype='string', id=None)}
|
63 |
+
|
64 |
+
return datasets.DatasetInfo(
|
65 |
+
description=_STOCK11_DESCRIPTION,
|
66 |
+
features=datasets.Features(features),
|
67 |
+
homepage=self.config.url,
|
68 |
+
citation=self.config.citation + "\n" + _STOCK11_CITATION,
|
69 |
+
)
|
70 |
+
|
71 |
+
def _split_generators(self, dl_manager):
|
72 |
+
downloaded_file = dl_manager.download_and_extract(self.config.data_url)
|
73 |
+
print(downloaded_file)
|
74 |
+
|
75 |
+
test_file = rf'{downloaded_file}\data\test\{self.config.name}.txt'
|
76 |
+
dev_file = rf'{downloaded_file}\data\dev\{self.config.name}.txt'
|
77 |
+
train_file = rf'{downloaded_file}\data\train\{self.config.name}.txt'
|
78 |
+
return [datasets.SplitGenerator(name=datasets.Split.TEST,
|
79 |
+
gen_kwargs={
|
80 |
+
"data_file": test_file,
|
81 |
+
"split": "test",
|
82 |
+
},),
|
83 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION,
|
84 |
+
gen_kwargs={
|
85 |
+
"data_file": dev_file,
|
86 |
+
"split": "dev",
|
87 |
+
},),
|
88 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
89 |
+
gen_kwargs={
|
90 |
+
"data_file": train_file,
|
91 |
+
"split": "train",
|
92 |
+
},)]
|
93 |
+
|
94 |
+
def _generate_examples(self, data_file, split):
|
95 |
+
with open(data_file, 'r', encoding='utf-8') as f:
|
96 |
+
for line in f:
|
97 |
+
lin = line.strip()
|
98 |
+
if not lin:
|
99 |
+
continue
|
100 |
+
lin_sp = lin.split('\t')
|
101 |
+
if len(lin_sp) < 5:
|
102 |
+
continue
|
103 |
+
# id, {example}
|
104 |
+
yield lin_sp[0], {'sentence':lin_sp[4],'domain':lin_sp[1], 'label':lin_sp[2], 'id':lin_sp[0], 'rank':lin_sp[3]}
|