Kevin99z commited on
Commit
7db2883
1 Parent(s): 8b16d9b

initial commit

Browse files
.gitattributes CHANGED
@@ -53,3 +53,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ dbpedia_subkg.json filter=lfs diff=lfs merge=lfs -text
57
+ entity2id.json filter=lfs diff=lfs merge=lfs -text
58
+ item_ids.json filter=lfs diff=lfs merge=lfs -text
59
+ relation2id.json filter=lfs diff=lfs merge=lfs -text
60
+ relation_set.json filter=lfs diff=lfs merge=lfs -text
61
+ test_data_dbpedia.jsonl filter=lfs diff=lfs merge=lfs -text
62
+ train_data_dbpedia.jsonl filter=lfs diff=lfs merge=lfs -text
63
+ valid_data_dbpedia.jsonl filter=lfs diff=lfs merge=lfs -text
dbpedia_subkg.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d08a20e445068a9220bac84a26725800cdd2e4cba47b9ef917947fa7de9b4581
3
+ size 540171
entity2id.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa6a8779bf6ef947b1c6046da3535946f60b27d1d7bba83c8d65e197b176acbd
3
+ size 1060452
inspired_unicrs.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import re
3
+ from typing import List, Dict
4
+ import html
5
+
6
+ import datasets
7
+ import pyarrow as pa
8
+
9
+ logger = datasets.logging.get_logger(__name__)
10
+
11
+
12
+ _URL = "./"
13
+ _URLS = {
14
+ "train": _URL + "train_data_dbpedia.jsonl",
15
+ "valid": _URL + "valid_data_dbpedia.jsonl",
16
+ "test": _URL + "test_data_dbpedia.jsonl",
17
+ "entity2id": _URL + "entity2id.json"
18
+ }
19
+
20
+
21
+ class InspiredConfig(datasets.BuilderConfig):
22
+ def __init__(self, **kwargs):
23
+ """BuilderConfig for Inspired (used in UniCRS).
24
+
25
+ Args:
26
+ features: *list[string]*, list of the features that will appear in the
27
+ feature dict. Should not include "label".
28
+ **kwargs: keyword arguments forwarded to super.
29
+ """
30
+ super().__init__(version=datasets.Version("0.0.1"), **kwargs)
31
+ self.features = {
32
+ "context": datasets.Sequence(datasets.Value("string")),
33
+ "resp": datasets.Value("string"),
34
+ "rec": datasets.Sequence(datasets.Value("int32")),
35
+ "entity": datasets.Sequence(datasets.Value("int32")),
36
+ }
37
+
38
+ class Inspired(datasets.GeneratorBasedBuilder):
39
+ DEFAULT_CONFIG_NAME = "multiturn"
40
+ BUILDER_CONFIGS = [
41
+ datasets.BuilderConfig(
42
+ name="multiturn",
43
+ description="The processed Inspired dataset in UniCRS. Each conversation yields multiple samples",
44
+ ),
45
+
46
+ datasets.BuilderConfig(
47
+ name="multiturn_masked",
48
+ description="The processed Inspired dataset in UniCRS used for generation task. Each conversation yields multiple samples",
49
+ )
50
+ ]
51
+
52
+ movie_pattern = re.compile(r'@\d+')
53
+
54
+ def __init__(self, **kwargs):
55
+ super().__init__(**kwargs)
56
+
57
+ def _info(self):
58
+ return datasets.DatasetInfo(
59
+ description=self.config.description,
60
+ features=datasets.Features({
61
+ "context": datasets.Sequence(datasets.Value("string")),
62
+ "resp": datasets.Value("string"),
63
+ "rec": datasets.Sequence(datasets.Value("int32")),
64
+ "entity": datasets.Sequence(datasets.Value("int32")),
65
+ }),
66
+ )
67
+
68
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
69
+ urls_to_download = _URLS
70
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
71
+ entity2id_file = downloaded_files["entity2id"]
72
+ return [
73
+ datasets.SplitGenerator(name=datasets.Split.TRAIN,
74
+ gen_kwargs={"filepath": downloaded_files["train"], "entity2id": entity2id_file}),
75
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION,
76
+ gen_kwargs={"filepath": downloaded_files["valid"], "entity2id": entity2id_file}),
77
+ datasets.SplitGenerator(name=datasets.Split.TEST,
78
+ gen_kwargs={"filepath": downloaded_files["test"], "entity2id": entity2id_file}),
79
+ ]
80
+
81
+ def _process_utt(self, utt, movieid2name, replace_movieId, remove_movie=False):
82
+ def convert(match):
83
+ movieid = match.group(0)[1:]
84
+ if movieid in movieid2name:
85
+ if remove_movie:
86
+ return '<movie>'
87
+ movie_name = movieid2name[movieid]
88
+ movie_name = ' '.join(movie_name.split())
89
+ return movie_name
90
+ else:
91
+ return match.group(0)
92
+
93
+ if replace_movieId:
94
+ utt = re.sub(self.movie_pattern, convert, utt)
95
+ utt = ' '.join(utt.split())
96
+ utt = html.unescape(utt)
97
+
98
+ return utt
99
+
100
+
101
+ def _generate_examples(self, filepath, entity2id):
102
+ """This function returns the examples in the raw (text) form."""
103
+ logger.info("generating examples from = %s", filepath)
104
+
105
+ with open(entity2id, 'r', encoding='utf-8') as f:
106
+ entity2id = json.load(f)
107
+ if "multiturn" in self.config.name:
108
+ mask_flag = "mask" in self.config.name
109
+ Idx = 0
110
+ with open(filepath, encoding="utf-8") as f:
111
+ for line in f:
112
+ dialog = json.loads(line)
113
+
114
+ context, resp = [], ''
115
+ entity_list = []
116
+
117
+ for turn in dialog:
118
+ resp = turn['text']
119
+ entity_link = [entity2id[entity] for entity in turn['entity_link'] if entity in entity2id]
120
+ movie_link = [entity2id[movie] for movie in turn['movie_link'] if movie in entity2id]
121
+
122
+
123
+ if mask_flag and turn['role'] == 'SEEKER':
124
+ context.append(resp)
125
+ entity_list.extend(entity_link + movie_link)
126
+ else:
127
+ if mask_flag:
128
+ mask_resp = resp
129
+ for movie_name in turn['movie_name']:
130
+ start_ind = mask_resp.lower().find(movie_name.lower())
131
+ if start_ind != -1:
132
+ mask_resp = f'{mask_resp[:start_ind]}<movie>{mask_resp[start_ind + len(movie_name):]}'
133
+
134
+ if len(context) == 0:
135
+ context.append('')
136
+
137
+ yield Idx, {
138
+ 'context': context,
139
+ 'resp': mask_resp if mask_flag else resp,
140
+ 'rec': movie_link if mask_flag else list(set(movie_link + entity_link)),
141
+ 'entity': list(set(entity_list))
142
+ }
143
+ Idx += 1
144
+
145
+ context.append(resp)
146
+ entity_list.extend(entity_link + movie_link)
147
+
item_ids.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:753c5ed5e79fda3ea0699d02744e1e752dbfc38cf3d3695c45ee34c8950e5254
3
+ size 9361
relation2id.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a36fdf987d0597e8346c6d9a0e6333b6d3aea67cfe03bebce0114a0deaabda1
3
+ size 578
test_data_dbpedia.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1ab79e33858224983de938f6401a18fab7bd99bb4580512fbe804459539f593
3
+ size 476786
train_data_dbpedia.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f185878d61f4cf95036711612befbec2e587b42fcb7bf855fba3af08016e7743
3
+ size 3965124
valid_data_dbpedia.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cde8cf7f55d4f2a71f1c7c8e4b921ca9caaee615999fd3728c7bea214b01839
3
+ size 484801