qgyd2021 commited on
Commit
2d11779
1 Parent(s): 5938799

[update]add main

Browse files
Files changed (3) hide show
  1. README.md +7 -0
  2. e_commerce_customer_service.py +141 -0
  3. main.py +17 -0
README.md CHANGED
@@ -14,13 +14,20 @@ size_categories:
14
  是从 (lightinthebox)[https://www.lightinthebox.com/] 网站收集的电商数据. 此数据可用于电商客服机器人的研究.
15
 
16
  数据内容:
 
17
  faq.json: 包含通用问题的问答对.
 
18
  product.jsonl: 包含一些商品信息.
19
 
20
  examples 中包含收集商品信息的爬虫代码.
 
 
 
21
  requirements.txt
22
  ```text
23
  beautifulsoup4==4.12.2
24
  requests==2.31.0
25
  tqdm==4.65.0
 
26
  ```
 
 
14
  是从 (lightinthebox)[https://www.lightinthebox.com/] 网站收集的电商数据. 此数据可用于电商客服机器人的研究.
15
 
16
  数据内容:
17
+
18
  faq.json: 包含通用问题的问答对.
19
+
20
  product.jsonl: 包含一些商品信息.
21
 
22
  examples 中包含收集商品信息的爬虫代码.
23
+
24
+ python==3.8.10
25
+
26
  requirements.txt
27
  ```text
28
  beautifulsoup4==4.12.2
29
  requests==2.31.0
30
  tqdm==4.65.0
31
+ datasets==2.14.4
32
  ```
33
+
e_commerce_customer_service.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # -*- coding: utf-8 -*-
3
+ from glob import glob
4
+ import json
5
+ import os
6
+ from pathlib import Path
7
+
8
+ import datasets
9
+
10
+
11
+ _URLS = {
12
+ "faq": "data/faq.json",
13
+ "product": "data/product.jsonl",
14
+ }
15
+
16
+
17
+ _CITATION = """\
18
+ @dataset{early_media,
19
+ author = {Xing Tian},
20
+ title = {e_commerce_customer_service},
21
+ month = aug,
22
+ year = 2023,
23
+ publisher = {Xing Tian},
24
+ version = {1.0},
25
+ }
26
+ """
27
+
28
+
29
+ class TelemarketingVoiceClassification(datasets.GeneratorBasedBuilder):
30
+ VERSION = datasets.Version("1.0.0")
31
+
32
+ BUILDER_CONFIGS = [
33
+ datasets.BuilderConfig(name="faq", version=VERSION, description="faq"),
34
+ datasets.BuilderConfig(name="product", version=VERSION, description="product"),
35
+ ]
36
+
37
+ def _info(self):
38
+ if self.config.name == "faq":
39
+ features = datasets.Features(
40
+ {
41
+ "url": datasets.Value("string"),
42
+ "question": datasets.Value("string"),
43
+ "answer": datasets.Value("string"),
44
+ "label": datasets.Value("string"),
45
+ }
46
+ )
47
+ elif self.config.name == "product":
48
+ features = datasets.Features(
49
+ {
50
+ "title": datasets.Value("string"),
51
+ "brand": datasets.Value("string"),
52
+ "review": datasets.Value("string"),
53
+ "description": datasets.Value("string"),
54
+ "mpn": datasets.Value("string"),
55
+ "color": datasets.Sequence(datasets.Value("string")),
56
+ "size": datasets.Sequence(datasets.Value("string")),
57
+ "sku": datasets.Value("string"),
58
+ "ratingValue": datasets.Value("float32"),
59
+ "reviewCount": datasets.Value("int64"),
60
+ "overview": datasets.Value("string"),
61
+ "category": datasets.Value("string"),
62
+ "url": datasets.Value("string"),
63
+ }
64
+ )
65
+ else:
66
+ raise NotImplementedError
67
+
68
+ return datasets.DatasetInfo(
69
+ features=features,
70
+ supervised_keys=None,
71
+ homepage="",
72
+ license="",
73
+ citation=_CITATION,
74
+ )
75
+
76
+ def _split_generators(self, dl_manager):
77
+ """Returns SplitGenerators."""
78
+ url = _URLS[self.config.name]
79
+ dl_path = dl_manager.download_and_extract(url)
80
+ archive_path = dl_path
81
+
82
+ return [
83
+ datasets.SplitGenerator(
84
+ name=datasets.Split.TRAIN,
85
+ gen_kwargs={"archive_path": archive_path, "split": "train"},
86
+ ),
87
+ ]
88
+
89
+ def _generate_faq(self, archive_path, split):
90
+ archive_path = Path(archive_path)
91
+
92
+ with open(archive_path, "r", encoding="utf-8") as f:
93
+ faq = json.load(f)
94
+
95
+ idx = 0
96
+ for qa in faq:
97
+ yield idx, {
98
+ "url": qa["url"],
99
+ "question": qa["question"],
100
+ "answer": qa["answer"],
101
+ "label": qa["label"],
102
+ }
103
+ idx += 1
104
+
105
+ def _generate_product(self, archive_path, split):
106
+ archive_path = Path(archive_path)
107
+
108
+ idx = 0
109
+ with open(archive_path, "r", encoding="utf-8") as f:
110
+ for row in f:
111
+ row = json.loads(row)
112
+
113
+ yield idx, {
114
+ "title": row["title"],
115
+ "brand": row["brand"],
116
+ "review": row["review"],
117
+ "description": row["description"],
118
+ "mpn": row["mpn"],
119
+ "color": row["color"],
120
+ "size": row["size"],
121
+ "sku": row["sku"],
122
+ "ratingValue": float(row["ratingValue"]) if row["ratingValue"] is not None else None,
123
+ "reviewCount": int(row["reviewCount"]) if row["reviewCount"] is not None else None,
124
+ "overview": row["overview"],
125
+ "category": row["category"],
126
+ "url": row["url"],
127
+ }
128
+ idx += 1
129
+
130
+ def _generate_examples(self, archive_path, split):
131
+ """Yields examples."""
132
+ if self.config.name == "faq":
133
+ return self._generate_faq(archive_path, split)
134
+ elif self.config.name == "product":
135
+ return self._generate_product(archive_path, split)
136
+ else:
137
+ raise NotImplementedError
138
+
139
+
140
+ if __name__ == '__main__':
141
+ pass
main.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # -*- coding: utf-8 -*-
3
+ from datasets import load_dataset
4
+
5
+ dataset = load_dataset(
6
+ "e_commerce_customer_service.py",
7
+ name="faq",
8
+ # name="product",
9
+ split="train",
10
+ )
11
+
12
+ for sample in dataset:
13
+ print(sample)
14
+
15
+
16
+ if __name__ == '__main__':
17
+ pass