fix assignment before ref bug, add examples in index
Browse files- index.html +63 -13
- src/task.py +3 -3
index.html
CHANGED
@@ -116,31 +116,42 @@
|
|
116 |
<p>
|
117 |
🪞Mirror can help you deal with a wide range of Natural Language Understanding and Information Extraction tasks.
|
118 |
</p>
|
|
|
119 |
<p>
|
120 |
-
🌟Star me on <a href="https://github.com/Spico197/Mirror" target="_blank">GitHub</a>!
|
121 |
</p>
|
|
|
122 |
</header>
|
123 |
|
124 |
<main>
|
125 |
<div id="app">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
<div>
|
127 |
<label for="instruction"><strong>Instruction</strong></label>
|
128 |
<input id="instruction" type="text" v-model="instruction" placeholder="Mirror mirror tell me ..." size="200">
|
129 |
</div>
|
130 |
<div>
|
131 |
<label for="schema"><strong>Schema Labels</strong></label>
|
132 |
-
<p>
|
133 |
-
<p>For entities, relations or classification, input <code>{"ent|rel|cls": ["cls1", "type2"]}</code> .</p>
|
134 |
-
<p>For events and hyper relations, input <code>{"type": ["role1", "role2"]}</code> .</p>
|
135 |
<input id="schema" type="text" v-model="schema" size="200">
|
136 |
-
<!-- <div>
|
137 |
-
<button @click.prevent="addCls">Class</button>
|
138 |
-
<button @click.prevent="addEnt">Entity</button>
|
139 |
-
<button @click.prevent="addDisconEnt">Discontinuous Entity</button>
|
140 |
-
<button @click.prevent="addRel">Relation</button>
|
141 |
-
<button @click.prevent="addEvent">Event Type</button>
|
142 |
-
<button @click.prevent="addHyperRel">Hyper Relation</button>
|
143 |
-
</div> -->
|
144 |
</div>
|
145 |
<div>
|
146 |
<label for="text"><strong>Text</strong></label>
|
@@ -198,6 +209,7 @@
|
|
198 |
const instruction = ref("")
|
199 |
const text = ref("")
|
200 |
const background = ref("")
|
|
|
201 |
const schema = ref("{}")
|
202 |
const results = ref({})
|
203 |
const timerHandler = ref(0)
|
@@ -217,6 +229,8 @@
|
|
217 |
|
218 |
function reset() {
|
219 |
schema.value = "{}"
|
|
|
|
|
220 |
clearOutput()
|
221 |
}
|
222 |
|
@@ -269,6 +283,41 @@
|
|
269 |
.finally(() => endTimer())
|
270 |
}
|
271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
return {
|
273 |
instruction,
|
274 |
text,
|
@@ -281,6 +330,7 @@
|
|
281 |
searchSecondsString,
|
282 |
timerHandler,
|
283 |
isNotEmptyObj,
|
|
|
284 |
}
|
285 |
}
|
286 |
}
|
@@ -288,4 +338,4 @@
|
|
288 |
</script>
|
289 |
</body>
|
290 |
|
291 |
-
</html>
|
|
|
116 |
<p>
|
117 |
🪞Mirror can help you deal with a wide range of Natural Language Understanding and Information Extraction tasks.
|
118 |
</p>
|
119 |
+
<p>🔍 Mechanism behind this demo: <a href="https://arxiv.org/abs/2311.05419" target="_blank">Mirror paper</a>.</p>
|
120 |
<p>
|
121 |
+
🌟 Star me on <a href="https://github.com/Spico197/Mirror" target="_blank">GitHub</a>!
|
122 |
</p>
|
123 |
+
<p>📢 This demo only supports English tasks. For Chinese Information Extraction tasks, please refer to this model: <a href="https://huggingface.co/Spico/mirror-chinese-mrcqa-alpha" target="_blank">Spico/mirror-chinese-mrcqa-alpha</a>.</p>
|
124 |
</header>
|
125 |
|
126 |
<main>
|
127 |
<div id="app">
|
128 |
+
<div>
|
129 |
+
<label for="example-select"><strong>Examples</strong></label>
|
130 |
+
<select id="example-select" v-model="selectedExample">
|
131 |
+
<optgroup label="Named Entity Recognition">
|
132 |
+
<option>Person & Nationality</option>
|
133 |
+
</optgroup>
|
134 |
+
<optgroup label="Relation Extraction">
|
135 |
+
<option>Break up</option>
|
136 |
+
</optgroup>
|
137 |
+
<optgroup label="Classification">
|
138 |
+
<option>The most handsome man</option>
|
139 |
+
<option>I'm more handsome!</option>
|
140 |
+
</optgroup>
|
141 |
+
<optgroup label="Machine Reading Comprehension">
|
142 |
+
<option>The former CEO of Apple</option>
|
143 |
+
<option>The new CEO of Apple</option>
|
144 |
+
</optgroup>
|
145 |
+
</select>
|
146 |
+
</div>
|
147 |
<div>
|
148 |
<label for="instruction"><strong>Instruction</strong></label>
|
149 |
<input id="instruction" type="text" v-model="instruction" placeholder="Mirror mirror tell me ..." size="200">
|
150 |
</div>
|
151 |
<div>
|
152 |
<label for="schema"><strong>Schema Labels</strong></label>
|
153 |
+
<p>For entities, relations or classification, input <code>{"ent|rel|cls": ["type1", "type2"]}</code> .</p>
|
|
|
|
|
154 |
<input id="schema" type="text" v-model="schema" size="200">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
</div>
|
156 |
<div>
|
157 |
<label for="text"><strong>Text</strong></label>
|
|
|
209 |
const instruction = ref("")
|
210 |
const text = ref("")
|
211 |
const background = ref("")
|
212 |
+
const selectedExample = ref("")
|
213 |
const schema = ref("{}")
|
214 |
const results = ref({})
|
215 |
const timerHandler = ref(0)
|
|
|
229 |
|
230 |
function reset() {
|
231 |
schema.value = "{}"
|
232 |
+
instruction.value = ""
|
233 |
+
text.value = ""
|
234 |
clearOutput()
|
235 |
}
|
236 |
|
|
|
283 |
.finally(() => endTimer())
|
284 |
}
|
285 |
|
286 |
+
watch(
|
287 |
+
() => selectedExample.value,
|
288 |
+
(newValue, oldValue) => {
|
289 |
+
if (newValue !== oldValue) {
|
290 |
+
reset()
|
291 |
+
console.log(newValue)
|
292 |
+
if (newValue === "Person & Nationality") {
|
293 |
+
instruction.value = "Please identify any entities in the provided text and classify them based on their types."
|
294 |
+
text.value = "Isaac Newton was an English mathematician."
|
295 |
+
schema.value = '{"ent": ["person", "nationality"]}'
|
296 |
+
} else if (newValue === "Break up") {
|
297 |
+
instruction.value = "Please extract the entity relationship triplet."
|
298 |
+
text.value = "The drama surrounding the high-profile divorce between Hollywood actors Johnny Depp and Amber Heard appears to be over as the couple reportedly reached an amicable settlement."
|
299 |
+
schema.value = '{"rel": ["break up"]}'
|
300 |
+
} else if (newValue === "The most handsome man") {
|
301 |
+
instruction.value = "Mirror Mirror tell me, who's the most handsome man in the world?"
|
302 |
+
text.value = ""
|
303 |
+
schema.value = '{"cls": ["Tong Zhu", "Leonardo Dicaprio"]}'
|
304 |
+
} else if (newValue === "I'm more handsome!") {
|
305 |
+
instruction.value = "Mirror Mirror tell me, who's the most handsome man in the world?"
|
306 |
+
text.value = "Tong Zhu won the Most Handsome Man Award every year for ten consecutive years."
|
307 |
+
schema.value = '{"cls": ["Tong Zhu", "Leonardo Dicaprio"]}'
|
308 |
+
} else if (newValue === "The former CEO of Apple") {
|
309 |
+
instruction.value = "Who's the former CEO of Apple?"
|
310 |
+
text.value = "After Jobs resigned as CEO and became chairman of the board, Cook was named the new chief executive officer of Apple Inc. on August 24, 2011."
|
311 |
+
schema.value = '{}'
|
312 |
+
} else if (newValue === "The new CEO of Apple") {
|
313 |
+
instruction.value = "Who's the new CEO of Apple?"
|
314 |
+
text.value = "After Jobs resigned as CEO and became chairman of the board, Cook was named the new chief executive officer of Apple Inc. on August 24, 2011."
|
315 |
+
schema.value = '{}'
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
)
|
320 |
+
|
321 |
return {
|
322 |
instruction,
|
323 |
text,
|
|
|
330 |
searchSecondsString,
|
331 |
timerHandler,
|
332 |
isNotEmptyObj,
|
333 |
+
selectedExample,
|
334 |
}
|
335 |
}
|
336 |
}
|
|
|
338 |
</script>
|
339 |
</body>
|
340 |
|
341 |
+
</html>
|
src/task.py
CHANGED
@@ -357,9 +357,9 @@ class SchemaGuidedInstructBertTask(MrcTaggingTask):
|
|
357 |
string = tokenizer.decode(token_ids[span[0] : span[1] + 1])
|
358 |
return (string, self.reset_position(token_ids, span))
|
359 |
|
360 |
-
def reset_position(self,
|
361 |
-
if isinstance(
|
362 |
-
input_ids =
|
363 |
if len(span) < 1:
|
364 |
return span
|
365 |
|
|
|
357 |
string = tokenizer.decode(token_ids[span[0] : span[1] + 1])
|
358 |
return (string, self.reset_position(token_ids, span))
|
359 |
|
360 |
+
def reset_position(self, input_ids: list[int], span: list[int]) -> list[int]:
|
361 |
+
if isinstance(input_ids, torch.Tensor):
|
362 |
+
input_ids = input_ids.cpu().tolist()
|
363 |
if len(span) < 1:
|
364 |
return span
|
365 |
|