Update Entity tag
Browse files- inspired_unicrs.py +2 -14
inspired_unicrs.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import json
|
2 |
-
import re
|
3 |
from typing import List, Dict
|
4 |
import datasets
|
|
|
5 |
|
6 |
logger = datasets.logging.get_logger(__name__)
|
7 |
|
@@ -46,7 +46,6 @@ class Inspired(datasets.GeneratorBasedBuilder):
|
|
46 |
)
|
47 |
]
|
48 |
|
49 |
-
entity_pattern = "<entity>{}</entity>"
|
50 |
|
51 |
def __init__(self, **kwargs):
|
52 |
super().__init__(**kwargs)
|
@@ -71,17 +70,6 @@ class Inspired(datasets.GeneratorBasedBuilder):
|
|
71 |
]
|
72 |
|
73 |
|
74 |
-
def _mark_entity(self, utt: str, entities: List[str]):
|
75 |
-
# If entities like "action movie" and "action" appear at the same time, we only mark the longer one
|
76 |
-
entities = sorted(list(set(entities)), key=lambda x: len(x), reverse=True)
|
77 |
-
for i, entity in enumerate(entities):
|
78 |
-
valid = True
|
79 |
-
for prev in entities[:i]:
|
80 |
-
if entity in prev:
|
81 |
-
valid = False
|
82 |
-
if valid:
|
83 |
-
utt = re.sub(entity, self.entity_pattern.format(entity), utt)
|
84 |
-
return utt
|
85 |
|
86 |
def _generate_examples(self, filepath, entity2id):
|
87 |
"""This function returns the examples in the raw (text) form."""
|
@@ -100,7 +88,7 @@ class Inspired(datasets.GeneratorBasedBuilder):
|
|
100 |
resp = turn['text']
|
101 |
movie_turn = [entity2id[movie] for movie in turn['movie_link'] if movie in entity2id]
|
102 |
|
103 |
-
resp =
|
104 |
prefix = self.config.initiator_prefix if turn['role'] == 'SEEKER' else self.config.respondent_prefix
|
105 |
resp = prefix + resp
|
106 |
context.append(resp)
|
|
|
1 |
import json
|
|
|
2 |
from typing import List, Dict
|
3 |
import datasets
|
4 |
+
from dataset.utils import markup_entity
|
5 |
|
6 |
logger = datasets.logging.get_logger(__name__)
|
7 |
|
|
|
46 |
)
|
47 |
]
|
48 |
|
|
|
49 |
|
50 |
def __init__(self, **kwargs):
|
51 |
super().__init__(**kwargs)
|
|
|
70 |
]
|
71 |
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
def _generate_examples(self, filepath, entity2id):
|
75 |
"""This function returns the examples in the raw (text) form."""
|
|
|
88 |
resp = turn['text']
|
89 |
movie_turn = [entity2id[movie] for movie in turn['movie_link'] if movie in entity2id]
|
90 |
|
91 |
+
resp = markup_entity(resp, turn['entity_name']+turn['movie_name'])
|
92 |
prefix = self.config.initiator_prefix if turn['role'] == 'SEEKER' else self.config.respondent_prefix
|
93 |
resp = prefix + resp
|
94 |
context.append(resp)
|