Spico commited on
Commit
5953ef9
1 Parent(s): 2c6adeb
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. .gitignore +187 -0
  3. .pre-commit-config.yaml +19 -0
  4. LICENSE +201 -0
  5. Makefile +26 -0
  6. README.md +136 -6
  7. conf/Pretrain_excluded.yaml +51 -0
  8. conf/Pretrain_v1.5.yaml +51 -0
  9. conf/Pretrain_v1.5_woInstruction.yaml +51 -0
  10. conf/Pretrain_woOverlapV2.yaml +51 -0
  11. conf/ac/g1_dpspd.yaml +18 -0
  12. conf/ac/g1_dpspd_fp16.yaml +18 -0
  13. conf/cadec.yaml +3 -0
  14. conf/hyperred.yaml +3 -0
  15. conf/merge_all_data.yaml +6 -0
  16. conf/merge_analysis_data.yaml +18 -0
  17. conf/merge_analysis_data_woInstruction.yaml +18 -0
  18. conf/merge_uie_data.yaml +18 -0
  19. conf/mirror-ace05en.yaml +70 -0
  20. conf/mirror-multi-task-pretrain.yaml +51 -0
  21. conf/mrc.yaml +43 -0
  22. conf/ner.yaml +45 -0
  23. conf/nlu/cola.yaml +6 -0
  24. conf/nlu/mnli.yaml +6 -0
  25. conf/nlu/mrpc.yaml +3 -0
  26. conf/nlu/plm.yaml +19 -0
  27. conf/nlu/qnli.yaml +6 -0
  28. conf/nlu/qqp.yaml +6 -0
  29. conf/nlu/rte.yaml +6 -0
  30. conf/nlu/squad_v2.yaml +4 -0
  31. conf/nlu/sst-2.yaml +6 -0
  32. conf/t-rex_pretrain.yaml +9 -0
  33. conf/uie_data/absa_14lap.yaml +3 -0
  34. conf/uie_data/absa_14res.yaml +3 -0
  35. conf/uie_data/absa_15res.yaml +3 -0
  36. conf/uie_data/absa_16res.yaml +3 -0
  37. conf/uie_data/ent_ace04.yaml +3 -0
  38. conf/uie_data/ent_ace05.yaml +3 -0
  39. conf/uie_data/ent_conll03.yaml +3 -0
  40. conf/uie_data/event_ace05.yaml +3 -0
  41. conf/uie_data/event_casie.yaml +3 -0
  42. conf/uie_data/fewshot.yaml +5 -0
  43. conf/uie_data/merged.yaml +3 -0
  44. conf/uie_data/rel_ace05.yaml +3 -0
  45. conf/uie_data/rel_conll04.yaml +3 -0
  46. conf/uie_data/rel_nyt.yaml +3 -0
  47. conf/uie_data/rel_scierc.yaml +3 -0
  48. conf/uie_data/wPretrain.yaml +19 -0
  49. eval.py +0 -0
  50. index.html +288 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ figs/mirror-frontpage.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ .DS_Store
163
+ ._.DS_Store
164
+ debug.py
165
+ outputs/
166
+ resources/NER/msra/cache/
167
+ resources/NER/msra/mrc/
168
+ resources/NER/msra/formatted/
169
+ resources/MRC/cmrc2018/cache/
170
+ resources/MRC/cmrc2018/formatted/
171
+ cache/*.cache
172
+ resources/MRC/DuReader-*/
173
+ resources/**/*.json
174
+ resources/**/*.jsonl
175
+ resources/**/*.zip
176
+ resources/**/*.tsv
177
+ resources/**/*.xml
178
+ resources/**/raw/
179
+ resources.tar.gz
180
+ debug/
181
+ debug.json
182
+ mirror_outputs/
183
+ sampled_stats.xlsx
184
+ mirror_fewshot_outputs/
185
+ conll03-100.jsonl
186
+ tmp*/
187
+ resources/
.pre-commit-config.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pycqa/isort
3
+ rev: 5.12.0
4
+ hooks:
5
+ - id: isort
6
+ name: isort (python)
7
+ args: ["--profile", "black", "--filter-files"]
8
+ - repo: https://github.com/psf/black
9
+ rev: 22.12.0
10
+ hooks:
11
+ - id: black
12
+ - repo: https://github.com/pre-commit/pre-commit-hooks
13
+ rev: v4.4.0
14
+ hooks:
15
+ - id: trailing-whitespace
16
+ - id: end-of-file-fixer
17
+ - id: check-yaml
18
+ - id: check-added-large-files
19
+ args: [--maxkb=900]
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
Makefile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ all: format clean test pre
2
+ echo 'finished'
3
+
4
+ .PHONY: format
5
+ format:
6
+ isort --profile black --filter-files .
7
+ black .
8
+
9
+ .PHONY: test
10
+ test:
11
+ coverage run --source src -m pytest -vv .
12
+ coverage report -m
13
+ flake8
14
+
15
+ .PHONY: pre
16
+ pre:
17
+ pre-commit run --all-files
18
+
19
+ .PHONY: clean
20
+ clean:
21
+ rm -rf build/
22
+ rm -rf dist/
23
+ rm -rf *.egg-info/
24
+ rm -f .coverage
25
+ rm -f coverage.xml
26
+ find . | grep -E '(__pycache__|\.pyc|\.pyo$$)' | xargs rm -rf
README.md CHANGED
@@ -1,13 +1,143 @@
1
  ---
2
  title: Mirror
3
- emoji: 👀
4
- colorFrom: green
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 4.1.2
8
- app_file: app.py
9
- pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Mirror
3
+ emoji: 🪞
4
+ colorFrom: blue
5
+ colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 4.1.2
8
+ app_file: src/app/gradio_app.py
9
+ pinned: true
10
  license: apache-2.0
11
  ---
12
 
13
+ <div align="center">
14
+ <h1>🪞 Mirror: A Universal Framework for Various Information Extraction Tasks</h1>
15
+ <img src="figs/mirror-frontpage.png" width="300" alt="Magic mirror"><br>
16
+ <i>Image generated by DALLE 3</i><br>
17
+ <!-- <img src="figs/mirror-framework.png" alt="Mirror Framework"> -->
18
+ <a href="https://arxiv.org/abs/2311.05419" target="_blank">[Paper]</a> | <a href="https://huggingface.co/spaces/Spico/Mirror" target="_blank">[Demo]</a><br>
19
+ 📃 Our paper has been accepted to EMNLP23 main conference, <a href="http://arxiv.org/abs/2311.05419" target="_blank">check it out</a>!<br>
20
+ </div>
21
+
22
+ <hr>
23
+
24
+ 😎: This is the official implementation of [🪞Mirror](https://arxiv.org/abs/2311.05419) which supports *almost* all the Information Extraction tasks.
25
+
26
+ The name, Mirror, comes from the classical story *Snow White and the Seven Dwarfs*, where a magic mirror knows everything in the world.
27
+ We aim to build such a powerful tool for the IE community.
28
+
29
+ ## 🔥 Supported Tasks
30
+
31
+ 1. Named Entity Recognition
32
+ 2. Entity Relationship Extraction (Triplet Extraction)
33
+ 3. Event Extraction
34
+ 4. Aspect-based Sentiment Analysis
35
+ 5. Multi-span Extraction (e.g. Discontinuous NER)
36
+ 6. N-ary Extraction (e.g. Hyper Relation Extraction)
37
+ 7. Extractive Machine Reading Comprehension (MRC) and Question Answering
38
+ 8. Classification & Multi-choice MRC
39
+
40
+ ![System Comparison](figs/sys-comparison.png)
41
+
42
+ ## 🌴 Dependencies
43
+
44
+ Python>=3.10
45
+
46
+ ```bash
47
+ pip install -r requirements.txt
48
+ ```
49
+
50
+ ## 🚀 QuickStart
51
+
52
+ ### Pretrained Model Weights & Datasets
53
+
54
+ Download the pretrained model weights & datasets from [[OSF]](https://osf.io/kwsm4/?view_only=5b66734d88cf456b93f17b6bac8a44fb) .
55
+
56
+ No worries, it's an anonymous link just for double blind peer reviewing.
57
+
58
+ ### Pretraining
59
+
60
+ 1. Download and unzip the pretraining corpus into `resources/Mirror/v1.4_sampled_v3/merged/all_excluded`
61
+ 2. Start to run
62
+
63
+ ```bash
64
+ CUDA_VISIBLE_DEVICES=0 rex train -m src.task -dc conf/Pretrain_excluded.yaml
65
+ ```
66
+
67
+ ### Fine-tuning
68
+
69
+ ⚠️ Due to data license constraints, some datasets are unavailable to provide directly (e.g. ACE04, ACE05).
70
+
71
+ 1. Download and unzip the pretraining corpus into `resources/Mirror/v1.4_sampled_v3/merged/all_excluded`
72
+ 2. Download and unzip the fine-tuning datasets into `resources/Mirror/uie/`
73
+ 3. Start to fine-tuning
74
+
75
+ ```bash
76
+ # UIE tasks
77
+ CUDA_VISIBLE_DEVICES=0 bash scripts/single_task_wPTAllExcluded_wInstruction/run1.sh
78
+ CUDA_VISIBLE_DEVICES=1 bash scripts/single_task_wPTAllExcluded_wInstruction/run2.sh
79
+ CUDA_VISIBLE_DEVICES=2 bash scripts/single_task_wPTAllExcluded_wInstruction/run3.sh
80
+ CUDA_VISIBLE_DEVICES=3 bash scripts/single_task_wPTAllExcluded_wInstruction/run4.sh
81
+ # Multi-span and N-ary extraction
82
+ CUDA_VISIBLE_DEVICES=4 bash scripts/single_task_wPTAllExcluded_wInstruction/run_new_tasks.sh
83
+ # GLUE datasets
84
+ CUDA_VISIBLE_DEVICES=5 bash scripts/single_task_wPTAllExcluded_wInstruction/glue.sh
85
+ ```
86
+
87
+ ### Analysis Experiments
88
+
89
+ - Few-shot experiments : `scripts/run_fewshot.sh`. Collecting results: `python mirror_fewshot_outputs/get_avg_results.py`
90
+ - Mirror w/ PT w/o Inst. : `scripts/single_task_wPTAllExcluded_woInstruction`
91
+ - Mirror w/o PT w/ Inst. : `scripts/single_task_wo_pretrain`
92
+ - Mirror w/o PT w/o Inst. : `scripts/single_task_wo_pretrain_wo_instruction`
93
+
94
+ ### Evaluation
95
+
96
+ 1. Change `task_dir` and `data_pairs` you want to evaluate. The default setting is to get results of Mirror<sub>direct</sub> on all downstream tasks.
97
+ 2. `CUDA_VISIBLE_DEVICES=0 python -m src.eval`
98
+
99
+ ### Demo
100
+
101
+ 1. Download and unzip the pretrained task dump into `mirror_outputs/Mirror_Pretrain_AllExcluded_2`
102
+ 2. Try our demo:
103
+
104
+ ```bash
105
+ CUDA_VISIBLE_DEVICES=0 python -m src.app.api_backend
106
+ ```
107
+
108
+ ![Demo](figs/mirror-demo.gif)
109
+
110
+ ## 📋 Citation
111
+
112
+ ```bibtex
113
+ @misc{zhu_mirror_2023,
114
+ shorttitle = {Mirror},
115
+ title = {Mirror: A Universal Framework for Various Information Extraction Tasks},
116
+ author = {Zhu, Tong and Ren, Junfei and Yu, Zijian and Wu, Mengsong and Zhang, Guoliang and Qu, Xiaoye and Chen, Wenliang and Wang, Zhefeng and Huai, Baoxing and Zhang, Min},
117
+ url = {http://arxiv.org/abs/2311.05419},
118
+ doi = {10.48550/arXiv.2311.05419},
119
+ urldate = {2023-11-10},
120
+ publisher = {arXiv},
121
+ month = nov,
122
+ year = {2023},
123
+ note = {arXiv:2311.05419 [cs]},
124
+ keywords = {Computer Science - Artificial Intelligence, Computer Science - Computation and Language},
125
+ }
126
+ ```
127
+
128
+ ## 🛣️ Roadmap
129
+
130
+ - [ ] Convert current model into Huggingface version, supporting loading from `transformers` like other newly released LLMs.
131
+ - [ ] Remove `Background` area, merge `TL`, `TP` into a single `T` token
132
+ - [ ] Add more task data: keyword extraction, coreference resolution, FrameNet, WikiNER, T-Rex relation extraction dataset, etc.
133
+ - [ ] Pre-train on all the data (including benchmarks) to build a nice out-of-the-box toolkit for universal IE.
134
+
135
+ ## 💌 Yours sincerely
136
+
137
+ This project is licensed under Apache-2.0.
138
+ We hope you enjoy it ~
139
+
140
+ <hr>
141
+ <div align="center">
142
+ <p>Mirror Team w/ 💖</p>
143
+ </div>
conf/Pretrain_excluded.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: SchemaGuidedInstructBertTask
3
+ task_name: Mirror_Pretrain_AllExcluded_2
4
+ comment: '~~content as label, (start, end + 1) span'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ label_span: tag # tag `[LM]` or content `person`
10
+ mode: span # w2 (1,2,3) or span (1,3)
11
+ stream_mode: false
12
+
13
+ # filepaths
14
+ plm_dir: microsoft/deberta-v3-large
15
+ data_dir: resources/Mirror/v1.4_sampled_v3/merged/all_excluded
16
+ output_dir: mirror_outputs
17
+ task_dir: ${output_dir}/${task_name}
18
+ train_filepath: ${data_dir}/train.jsonl
19
+ dev_filepath: ${data_dir}/dev.jsonl
20
+ test_filepath: ${data_dir}/test.jsonl
21
+ dump_cache_dir: ${task_dir}/cache
22
+ regenerate_cache: false
23
+
24
+ # training
25
+ random_seed: 1227
26
+ base_model_path: null
27
+ eval_on_data: [train]
28
+ select_best_on_data: train
29
+ select_best_by_key: loss
30
+ final_eval_on_test: false
31
+ save_every_ckpt: true
32
+ save_best_ckpt: true
33
+
34
+ warmup_proportion: 0.1
35
+ num_epochs: 3
36
+ epoch_patience: -1
37
+ num_steps: -1
38
+ step_patience: -1
39
+ step_eval_interval: 10000
40
+ train_batch_size: 8
41
+ eval_batch_size: 8
42
+ grad_accum_steps: 1
43
+ learning_rate: !!float 2e-5
44
+ other_learning_rate: !!float 1e-4
45
+ max_grad_norm: 1.0
46
+ weight_decay: 0.1
47
+
48
+ # model
49
+ dropout: 0.3
50
+ use_rope: true
51
+ biaffine_size: 512
conf/Pretrain_v1.5.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: SchemaGuidedInstructBertTask
3
+ task_name: Mirror_Pretrain_DataV1.5_2
4
+ comment: '~~content as label, (start, end + 1) span'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ label_span: tag # tag `[LM]` or content `person`
10
+ mode: span # w2 (1,2,3) or span (1,3)
11
+ stream_mode: false
12
+
13
+ # filepaths
14
+ plm_dir: microsoft/deberta-v3-large
15
+ data_dir: resources/Mirror/v1.5/merged/t-rex-200k
16
+ output_dir: mirror_outputs
17
+ task_dir: ${output_dir}/${task_name}
18
+ train_filepath: ${data_dir}/train.jsonl
19
+ dev_filepath: ${data_dir}/dev.jsonl
20
+ test_filepath: ${data_dir}/test.jsonl
21
+ dump_cache_dir: ${task_dir}/cache
22
+ regenerate_cache: false
23
+
24
+ # training
25
+ random_seed: 1227
26
+ base_model_path: null
27
+ eval_on_data: [train]
28
+ select_best_on_data: train
29
+ select_best_by_key: loss
30
+ final_eval_on_test: false
31
+ save_every_ckpt: true
32
+ save_best_ckpt: true
33
+
34
+ warmup_proportion: 0.1
35
+ num_epochs: 3
36
+ epoch_patience: -1
37
+ num_steps: -1
38
+ step_patience: -1
39
+ step_eval_interval: 10000
40
+ train_batch_size: 8
41
+ eval_batch_size: 8
42
+ grad_accum_steps: 1
43
+ learning_rate: !!float 2e-5
44
+ other_learning_rate: !!float 1e-4
45
+ max_grad_norm: 1.0
46
+ weight_decay: 0.1
47
+
48
+ # model
49
+ dropout: 0.3
50
+ use_rope: true
51
+ biaffine_size: 512
conf/Pretrain_v1.5_woInstruction.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: SchemaGuidedInstructBertTask
3
+ task_name: Mirror_Pretrain_DataV1.5_woInstruction
4
+ comment: '~~content as label, (start, end + 1) span'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ label_span: tag # tag `[LM]` or content `person`
10
+ mode: span # w2 (1,2,3) or span (1,3)
11
+ stream_mode: false
12
+
13
+ # filepaths
14
+ plm_dir: microsoft/deberta-v3-large
15
+ data_dir: resources/Mirror/v1.5/merged/t-rex-200k-woInstruction/remove_instruction
16
+ output_dir: mirror_outputs
17
+ task_dir: ${output_dir}/${task_name}
18
+ train_filepath: ${data_dir}/train.jsonl
19
+ dev_filepath: ${data_dir}/dev.jsonl
20
+ test_filepath: ${data_dir}/test.jsonl
21
+ dump_cache_dir: ${task_dir}/cache
22
+ regenerate_cache: false
23
+
24
+ # training
25
+ random_seed: 1227
26
+ base_model_path: null
27
+ eval_on_data: [train]
28
+ select_best_on_data: train
29
+ select_best_by_key: loss
30
+ final_eval_on_test: false
31
+ save_every_ckpt: true
32
+ save_best_ckpt: true
33
+
34
+ warmup_proportion: 0.1
35
+ num_epochs: 3
36
+ epoch_patience: -1
37
+ num_steps: -1
38
+ step_patience: -1
39
+ step_eval_interval: 10000
40
+ train_batch_size: 8
41
+ eval_batch_size: 8
42
+ grad_accum_steps: 1
43
+ learning_rate: !!float 2e-5
44
+ other_learning_rate: !!float 1e-4
45
+ max_grad_norm: 1.0
46
+ weight_decay: 0.1
47
+
48
+ # model
49
+ dropout: 0.3
50
+ use_rope: true
51
+ biaffine_size: 512
conf/Pretrain_woOverlapV2.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: SchemaGuidedInstructBertTask
3
+ task_name: Mirror_Pretrain_woOverlapV2
4
+ comment: '~~content as label, (start, end + 1) span'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ label_span: tag # tag `[LM]` or content `person`
10
+ mode: span # w2 (1,2,3) or span (1,3)
11
+ stream_mode: false
12
+
13
+ # filepaths
14
+ plm_dir: microsoft/deberta-v3-large
15
+ data_dir: resources/Mirror/v1.4_sampled_v3/merged/all
16
+ output_dir: mirror_outputs
17
+ task_dir: ${output_dir}/${task_name}
18
+ train_filepath: ${data_dir}/train_wo_overlap_v2.jsonl
19
+ dev_filepath: ${data_dir}/dev.jsonl
20
+ test_filepath: ${data_dir}/test.jsonl
21
+ dump_cache_dir: ${task_dir}/cache
22
+ regenerate_cache: false
23
+
24
+ # training
25
+ random_seed: 1227
26
+ base_model_path: null
27
+ eval_on_data: [train]
28
+ select_best_on_data: train
29
+ select_best_by_key: loss
30
+ final_eval_on_test: false
31
+ save_every_ckpt: true
32
+ save_best_ckpt: true
33
+
34
+ warmup_proportion: 0.1
35
+ num_epochs: 3
36
+ epoch_patience: -1
37
+ num_steps: -1
38
+ step_patience: -1
39
+ step_eval_interval: 10000
40
+ train_batch_size: 8
41
+ eval_batch_size: 8
42
+ grad_accum_steps: 1
43
+ learning_rate: !!float 2e-5
44
+ other_learning_rate: !!float 1e-4
45
+ max_grad_norm: 1.0
46
+ weight_decay: 0.1
47
+
48
+ # model
49
+ dropout: 0.3
50
+ use_rope: true
51
+ biaffine_size: 512
conf/ac/g1_dpspd.yaml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ compute_environment: LOCAL_MACHINE
2
+ deepspeed_config:
3
+ gradient_accumulation_steps: 1
4
+ zero3_init_flag: false
5
+ zero_stage: 1
6
+ distributed_type: DEEPSPEED
7
+ downcast_bf16: 'no'
8
+ machine_rank: 0
9
+ main_training_function: main
10
+ mixed_precision: 'no'
11
+ num_machines: 1
12
+ num_processes: 1
13
+ rdzv_backend: static
14
+ same_network: true
15
+ tpu_env: []
16
+ tpu_use_cluster: false
17
+ tpu_use_sudo: false
18
+ use_cpu: false
conf/ac/g1_dpspd_fp16.yaml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ compute_environment: LOCAL_MACHINE
2
+ deepspeed_config:
3
+ gradient_accumulation_steps: 4
4
+ zero3_init_flag: false
5
+ zero_stage: 1
6
+ distributed_type: DEEPSPEED
7
+ downcast_bf16: 'no'
8
+ machine_rank: 0
9
+ main_training_function: main
10
+ mixed_precision: fp16
11
+ num_machines: 1
12
+ num_processes: 1
13
+ rdzv_backend: static
14
+ same_network: true
15
+ tpu_env: []
16
+ tpu_use_cluster: false
17
+ tpu_use_sudo: false
18
+ use_cpu: false
conf/cadec.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_DiscontinuousNER_CADEC
2
+ data_dir: resources/Mirror/new_abilities_v2/cadec/new
3
+ best_metric_field: discontinuous_ent.micro.f1
conf/hyperred.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_HyperRel_HyperRED
2
+ data_dir: resources/Mirror/new_abilities_v2/HyperRED/new
3
+ best_metric_field: hyper_rel.micro.f1
conf/merge_all_data.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: InstructBert_MergedAllData
2
+ data_dir: resources/Mirror/v1.3/merged_pretrained_data
3
+ train_filepath: ${data_dir}/train.jsonl
4
+ dev_filepath: resources/Mirror/v1.3/uie_data/dev.jsonl
5
+ test_filepath: resources/Mirror/v1.3/uie_data/test.jsonl
6
+ num_epochs: 1
conf/merge_analysis_data.yaml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ task_name: Mirror_MultiTask_Analysis
2
+ plm_dir: microsoft/deberta-v3-large
3
+
4
+ data_dir: resources/Mirror/uie/merged_analysis
5
+ train_filepath: ${data_dir}/train.jsonl
6
+ dev_filepath: ${data_dir}/dev.jsonl
7
+ test_filepath: ${data_dir}/test.jsonl
8
+ num_epochs: 20
9
+ epoch_patience: 3
10
+ regenerate_cache: true
11
+
12
+ eval_on_data: [dev]
13
+ select_best_on_data: dev
14
+ select_best_by_key: metric
15
+ best_metric_field: general_spans.micro.f1
16
+ final_eval_on_test: true
17
+
18
+ base_model_path: null
conf/merge_analysis_data_woInstruction.yaml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ task_name: Mirror_MultiTask_Analysis_woInstruction
2
+ plm_dir: microsoft/deberta-v3-large
3
+
4
+ data_dir: resources/Mirror/uie/merged_analysis/remove_instruction
5
+ train_filepath: ${data_dir}/train.jsonl
6
+ dev_filepath: ${data_dir}/dev.jsonl
7
+ test_filepath: ${data_dir}/test.jsonl
8
+ num_epochs: 20
9
+ epoch_patience: 3
10
+ regenerate_cache: true
11
+
12
+ eval_on_data: [dev]
13
+ select_best_on_data: dev
14
+ select_best_by_key: metric
15
+ best_metric_field: general_spans.micro.f1
16
+ final_eval_on_test: true
17
+
18
+ base_model_path: null
conf/merge_uie_data.yaml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ task_name: Mirror_woPT_NewMergedUIEData_woOverlap
2
+ plm_dir: microsoft/deberta-v3-large
3
+
4
+ data_dir: resources/Mirror/uie/merged
5
+ train_filepath: ${data_dir}/train_wo_overlap.jsonl
6
+ dev_filepath: ${data_dir}/dev.jsonl
7
+ test_filepath: ${data_dir}/test.jsonl
8
+ num_epochs: 20
9
+ epoch_patience: 3
10
+ regenerate_cache: true
11
+
12
+ eval_on_data: [dev]
13
+ select_best_on_data: dev
14
+ select_best_by_key: metric
15
+ best_metric_field: general_spans.micro.f1
16
+ final_eval_on_test: true
17
+
18
+ base_model_path: null
conf/mirror-ace05en.yaml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: SchemaGuidedInstructBertTask
3
+ task_name: InstructBert_TagSpan_DebertaV3Base_ACE05ENPlus
4
+ comment: '~~content as label, (start, end + 1) span'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ label_span: tag # tag `[LM]` or content `person`
10
+ mode: span # w2 (1,2,3) or span (1,3)
11
+
12
+ # filepaths
13
+ plm_dir: microsoft/deberta-v3-base
14
+ # plm_dir: bert-base-cased
15
+ # data_dir: resources/Mirror/Tasks/EE/ACE05-EN
16
+ # data_dir: resources/Mirror/Tasks/RE/merged-20230502-2340-v1
17
+ # data_dir: resources/Mirror/Tasks/RE/merged-20230502-2358-v2-woADE
18
+ # data_dir: resources/Mirror/Tasks/EE/ACE05-EN-labelmap
19
+ data_dir: resources/Mirror/v1.3/event/en/ACE05-EN-plus/fixed_instructed
20
+ output_dir: outputs
21
+ task_dir: ${output_dir}/${task_name}
22
+ # train_filepath: ${data_dir}/ACE2005_plus_train.jsonl
23
+ # dev_filepath: ${data_dir}/ACE2005_plus_dev.jsonl
24
+ # test_filepath: ${data_dir}/ACE2005_plus_test.jsonl
25
+ # train_filepath: ${data_dir}/ACE2005_oneie_NER_train.jsonl
26
+ # dev_filepath: ${data_dir}/ACE2005_oneie_NER_dev.jsonl
27
+ # test_filepath: ${data_dir}/ACE2005_oneie_NER_test.jsonl
28
+ # train_filepath: ${data_dir}/ACE2005_oneie_RE_train.jsonl
29
+ # dev_filepath: ${data_dir}/ACE2005_oneie_RE_dev.jsonl
30
+ # test_filepath: ${data_dir}/ACE2005_oneie_RE_test.jsonl
31
+ # train_filepath: ${data_dir}/ACE2005_oneie_EE_train.jsonl
32
+ # dev_filepath: ${data_dir}/ACE2005_oneie_EE_dev.jsonl
33
+ # test_filepath: ${data_dir}/ACE2005_oneie_EE_test.jsonl
34
+ # train_filepath: ${data_dir}/ACE2005_oneie_train.jsonl
35
+ # dev_filepath: ${data_dir}/ACE2005_oneie_dev.jsonl
36
+ # test_filepath: ${data_dir}/ACE2005_oneie_test.jsonl
37
+ # train_filepath: ${data_dir}/train.jsonl
38
+ # dev_filepath: ${data_dir}/dev.jsonl
39
+ # test_filepath: ${data_dir}/test.jsonl
40
+ train_filepath: ${data_dir}/train.jsonl
41
+ dev_filepath: ${data_dir}/dev.jsonl
42
+ test_filepath: ${data_dir}/test.jsonl
43
+
44
+ dump_cache_dir: ${task_dir}/cache
45
+ regenerate_cache: false
46
+
47
+ # training
48
+ random_seed: 1227
49
+ eval_on_data: [dev, test]
50
+ select_best_on_data: dev
51
+ select_best_by_key: metric
52
+ best_metric_field: general_spans.micro.f1
53
+ final_eval_on_test: true
54
+ save_every_ckpt: false
55
+ save_best_ckpt: true
56
+
57
+ warmup_proportion: 0.1
58
+ num_epochs: 50
59
+ epoch_patience: 5
60
+ train_batch_size: 32
61
+ eval_batch_size: 32
62
+ learning_rate: !!float 3e-5
63
+ other_learning_rate: !!float 3e-5
64
+ max_grad_norm: 1.0
65
+ weight_decay: 0.1
66
+
67
+ # model
68
+ dropout: 0.3
69
+ use_rope: true
70
+ biaffine_size: 512
conf/mirror-multi-task-pretrain.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: SchemaGuidedInstructBertTask
3
+ task_name: MirrorLarge_SamplingPretrain_woLowResource_woOverlap
4
+ comment: '~~content as label, (start, end + 1) span'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ label_span: tag # tag `[LM]` or content `person`
10
+ mode: span # w2 (1,2,3) or span (1,3)
11
+ stream_mode: false
12
+
13
+ # filepaths
14
+ plm_dir: microsoft/deberta-v3-large
15
+ data_dir: resources/Mirror/v1.4_sampled_v3/merged/woLowResource
16
+ output_dir: mirror_outputs
17
+ task_dir: ${output_dir}/${task_name}
18
+ train_filepath: ${data_dir}/train_wo_overlap.jsonl
19
+ dev_filepath: ${data_dir}/dev.jsonl
20
+ test_filepath: ${data_dir}/test.jsonl
21
+ dump_cache_dir: ${task_dir}/cache
22
+ regenerate_cache: false
23
+
24
+ # training
25
+ random_seed: 1227
26
+ base_model_path: null
27
+ eval_on_data: [train]
28
+ select_best_on_data: train
29
+ select_best_by_key: loss
30
+ final_eval_on_test: false
31
+ save_every_ckpt: true
32
+ save_best_ckpt: true
33
+
34
+ warmup_proportion: 0.1
35
+ num_epochs: 1
36
+ epoch_patience: -1
37
+ num_steps: -1
38
+ step_patience: -1
39
+ step_eval_interval: 3000
40
+ train_batch_size: 8
41
+ eval_batch_size: 8
42
+ grad_accum_steps: 1
43
+ learning_rate: !!float 2e-5
44
+ other_learning_rate: !!float 1e-4
45
+ max_grad_norm: 1.0
46
+ weight_decay: 0.1
47
+
48
+ # model
49
+ dropout: 0.3
50
+ use_rope: true
51
+ biaffine_size: 512
conf/mrc.yaml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: MrcQaTask
3
+ task_name: Mirror_RobertaBaseWwm_Cons_MsraMrc
4
+ comment: 'GlobalPointer with RoPE'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 512
8
+ debug_mode: false
9
+ mode: cons
10
+
11
+ # filepaths
12
+ plm_dir: hfl/chinese-roberta-wwm-ext
13
+ data_dir: resources/NER/msra/mrc
14
+ output_dir: outputs
15
+ task_dir: ${output_dir}/${task_name}
16
+ train_filepath: ${data_dir}/train.jsonl
17
+ dev_filepath: ${data_dir}/test.jsonl
18
+ test_filepath: ${data_dir}/test.jsonl
19
+ dump_cache_dir: ${task_dir}/cache
20
+ regenerate_cache: true
21
+
22
+ # training
23
+ random_seed: 1227
24
+ eval_on_data: [dev]
25
+ select_best_on_data: dev
26
+ select_best_by_key: metric
27
+ best_metric_field: micro.f1
28
+ final_eval_on_test: true
29
+
30
+ warmup_proportion: 0.1
31
+ step_eval_interval: 20000
32
+ step_patience: -1
33
+ num_epochs: 5
34
+ epoch_patience: 5
35
+ train_batch_size: 32
36
+ eval_batch_size: 64
37
+ learning_rate: !!float 5e-5
38
+ other_learning_rate: !!float 1e-4
39
+ max_grad_norm: 1.0
40
+
41
+ # model
42
+ dropout: 0.3
43
+ biaffine_size: 512
conf/ner.yaml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task
2
+ task_type: MrcTaggingTask
3
+ task_name: debug-Mirror_W2_MSRAv2_NER_FreezeBertEmbAnd0-3_bs64
4
+ comment: 'bert mrc w/ w2ner for NER'
5
+
6
+ # data preprocessing
7
+ max_seq_len: 300
8
+ negative_sample_prob: 1.0
9
+ debug_mode: false
10
+ mode: w2
11
+
12
+ # filepaths
13
+ base_model_path: outputs/RobertaBase_data20230314v2/ckpt/MrcGlobalPointerModel.best.pth
14
+ plm_dir: hfl/chinese-roberta-wwm-ext
15
+ data_dir: resources/NER/MSRA_v2/formatted
16
+ output_dir: outputs
17
+ task_dir: ${output_dir}/${task_name}
18
+ train_filepath: ${data_dir}/train.char.bmes.jsonl
19
+ dev_filepath: ${data_dir}/dev.char.bmes.jsonl
20
+ test_filepath: ${data_dir}/test.char.bmes.jsonl
21
+ ent_type2query_filepath: ${data_dir}/query.json
22
+ dump_cache_dir: ${task_dir}/cache
23
+ regenerate_cache: true
24
+
25
+ # training
26
+ random_seed: 1227
27
+ eval_on_data: [dev, test]
28
+ select_best_on_data: dev
29
+ select_best_by_key: metric
30
+ best_metric_field: micro.f1
31
+ final_eval_on_test: true
32
+
33
+ warmup_proportion: 0.1
34
+ num_epochs: 5
35
+ epoch_patience: 5
36
+ train_batch_size: 64
37
+ eval_batch_size: 128
38
+ learning_rate: !!float 5e-5
39
+ other_learning_rate: !!float 1e-4
40
+ max_grad_norm: 1.0
41
+ weight_decay: 0.1
42
+
43
+ # model
44
+ dropout: 0.3
45
+ biaffine_size: 512
conf/nlu/cola.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_CoLA
2
+ data_dir: resources/Mirror/v1.3/cls/en/CoLA/formated
3
+ train_filepath: ${data_dir}/train.jsonl
4
+ dev_filepath: ${data_dir}/dev.jsonl
5
+ test_filepath: ${data_dir}/dev.jsonl
6
+ best_metric_field: cls.mcc
conf/nlu/mnli.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_MNLI
2
+ data_dir: resources/Mirror/v1.3/cls/en/MNLI/formated
3
+ train_filepath: ${data_dir}/MNLI_train.jsonl
4
+ dev_filepath: ${data_dir}/MNLI_dev.jsonl
5
+ test_filepath: ${data_dir}/MNLI_dev.jsonl
6
+ best_metric_field: cls.acc
conf/nlu/mrpc.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_MRPC
2
+ data_dir: resources/Mirror/v1.3/cls/en/MRPC/formated
3
+ best_metric_field: cls.acc
conf/nlu/plm.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ plm_dir: microsoft/deberta-v3-large
2
+ base_model_path: mirror_outputs/Mirror_Pretrain_AllExcluded_2/ckpt/SchemaGuidedInstructBertModel.best.pth
3
+
4
+ stream_mode: false
5
+ train_filepath: ${data_dir}/train.jsonl
6
+ dev_filepath: ${data_dir}/dev.jsonl
7
+ test_filepath: ${data_dir}/test.jsonl
8
+
9
+ num_epochs: 5
10
+ epoch_patience: -1
11
+ num_steps: -1
12
+ step_patience: -1
13
+ step_eval_interval: -1
14
+
15
+ eval_on_data: [dev]
16
+ select_best_on_data: dev
17
+ select_best_by_key: metric
18
+ best_metric_field: general_spans.micro.f1
19
+ final_eval_on_test: true
conf/nlu/qnli.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_QNLI
2
+ data_dir: resources/Mirror/v1.3/cls/en/QNLI/processed
3
+ train_filepath: ${data_dir}/QNLI_train.jsonl
4
+ dev_filepath: ${data_dir}/QNLI_dev.jsonl
5
+ test_filepath: ${data_dir}/QNLI_dev.jsonl
6
+ best_metric_field: cls.acc
conf/nlu/qqp.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_QQP
2
+ data_dir: resources/Mirror/v1.3/cls/en/QQP/new
3
+ train_filepath: ${data_dir}/train.jsonl
4
+ dev_filepath: ${data_dir}/dev.jsonl
5
+ test_filepath: ${data_dir}/dev.jsonl
6
+ best_metric_field: cls.acc
conf/nlu/rte.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_RTE
2
+ data_dir: resources/Mirror/v1.3/cls/en/RTE/formated
3
+ train_filepath: ${data_dir}/RTE_train.jsonl
4
+ dev_filepath: ${data_dir}/RTE_dev.jsonl
5
+ test_filepath: ${data_dir}/RTE_dev.jsonl
6
+ best_metric_field: cls.acc
conf/nlu/squad_v2.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_MRC_SQuADv2
2
+ data_dir: resources/Mirror/v1.3/span/en/squad_v2
3
+ test_filepath: ${data_dir}/dev.jsonl
4
+ best_metric_field: span.f1.f1
conf/nlu/sst-2.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ task_name: Mirror_SingleTask_Cls_SST2
2
+ data_dir: resources/Mirror/v1.3/cls/en/SST-2/instructed
3
+ train_filepath: ${data_dir}/SST-2_train.jsonl
4
+ dev_filepath: ${data_dir}/SST-2_dev.jsonl
5
+ test_filepath: ${data_dir}/SST-2_dev.jsonl
6
+ best_metric_field: cls.acc
conf/t-rex_pretrain.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ task_name: InstructBert_TagSpan_DebertaV3Base_TRExPretrain
2
+ data_dir: resources/Mirror/v1.3/rel/en/T-REx/instructed
3
+ train_filepath: ${data_dir}/t-rex.udi.fix.jsonl
4
+
5
+ num_epochs: 3
6
+ eval_on_data: [train]
7
+ select_best_on_data: train
8
+ select_best_by_key: loss
9
+ final_eval_on_test: false
conf/uie_data/absa_14lap.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_ABSA_14lap
2
+ data_dir: resources/Mirror/uie/absa/14lap
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/absa_14res.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_ABSA_14res
2
+ data_dir: resources/Mirror/uie/absa/14res
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/absa_15res.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_ABSA_15res
2
+ data_dir: resources/Mirror/uie/absa/15res
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/absa_16res.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_ABSA_16res
2
+ data_dir: resources/Mirror/uie/absa/16res
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/ent_ace04.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Ent_ACE04
2
+ data_dir: resources/Mirror/uie/ent/ace04
3
+ best_metric_field: ent.micro.f1
conf/uie_data/ent_ace05.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Ent_ACE05
2
+ data_dir: resources/Mirror/uie/ent/ace05
3
+ best_metric_field: ent.micro.f1
conf/uie_data/ent_conll03.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Ent_CoNLL03
2
+ data_dir: resources/Mirror/uie/ent/conll03
3
+ best_metric_field: ent.micro.f1
conf/uie_data/event_ace05.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Event_ACE05
2
+ data_dir: resources/Mirror/uie/event/ace05-evt
3
+ best_metric_field: event.arg_cls.f1
conf/uie_data/event_casie.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Event_CASIE
2
+ data_dir: resources/Mirror/uie/event/casie
3
+ best_metric_field: event.arg_cls.f1
conf/uie_data/fewshot.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ num_epochs: 200
2
+ epoch_patience: 10
3
+ output_dir: mirror_fewshot_outputs
4
+ base_model_path: mirror_outputs/Mirror_Pretrain_AllExcluded_2/ckpt/SchemaGuidedInstructBertModel.best.pth
5
+ save_every_ckpt: false
conf/uie_data/merged.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_MultiTask_UIE
2
+ data_dir: resources/Mirror/uie/merged
3
+ best_metric_field: general_spans.micro.f1
conf/uie_data/rel_ace05.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Rel_ACE05
2
+ data_dir: resources/Mirror/uie/rel/ace05-rel
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/rel_conll04.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Rel_CoNLL04
2
+ data_dir: resources/Mirror/uie/rel/conll04
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/rel_nyt.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Rel_NYT
2
+ data_dir: resources/Mirror/uie/rel/nyt
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/rel_scierc.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ task_name: Mirror_SingleTask_Rel_SciERC
2
+ data_dir: resources/Mirror/uie/rel/scierc
3
+ best_metric_field: rel.rel.micro.f1
conf/uie_data/wPretrain.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ plm_dir: microsoft/deberta-v3-large
2
+ base_model_path: mirror_outputs/Mirror_Pretrain_AllExcluded_2/ckpt/SchemaGuidedInstructBertModel.best.pth
3
+
4
+ stream_mode: false
5
+ train_filepath: ${data_dir}/train.jsonl
6
+ dev_filepath: ${data_dir}/dev.jsonl
7
+ test_filepath: ${data_dir}/test.jsonl
8
+
9
+ num_epochs: 20
10
+ epoch_patience: 3
11
+ num_steps: -1
12
+ step_patience: -1
13
+ step_eval_interval: -1
14
+
15
+ eval_on_data: [dev]
16
+ select_best_on_data: dev
17
+ select_best_by_key: metric
18
+ best_metric_field: general_spans.micro.f1
19
+ final_eval_on_test: true
eval.py ADDED
File without changes
index.html ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <title>🪞Mirror</title>
9
+ <link rel="stylesheet" href="https://unpkg.com/boltcss/bolt.min.css">
10
+ <script type="importmap">
11
+ {
12
+ "imports": {
13
+ "vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js"
14
+ }
15
+ }
16
+ </script>
17
+ <style>
18
+ body {
19
+ max-width: 800px;
20
+ margin: 40px auto;
21
+ padding: 0 20px;
22
+ }
23
+
24
+ .form-group {
25
+ display: flex;
26
+ flex-direction: row;
27
+ justify-content: flex-start;
28
+ align-items: center;
29
+ }
30
+
31
+ label {
32
+ margin-right: 1rem;
33
+ }
34
+
35
+ button {
36
+ margin: 0.2rem 0.2rem;
37
+ }
38
+
39
+ button:hover {
40
+ background-color: #dbdbdb;
41
+ }
42
+
43
+ footer {
44
+ text-align: center;
45
+ margin-top: 2rem;
46
+ }
47
+
48
+ input {
49
+ width: 100%;
50
+ }
51
+
52
+ .button-group {
53
+ margin-top: 1rem;
54
+ margin-bottom: 1rem;
55
+ }
56
+
57
+ .submit-button {
58
+ background-color: #ffc83d;
59
+ color: #d67d00;
60
+ font-weight: bold;
61
+ }
62
+
63
+ .lc-button {
64
+ background-color: #c4e5be;
65
+ }
66
+
67
+ .lm-button {
68
+ background-color: #dae7fb;
69
+ }
70
+
71
+ .lr-button {
72
+ background-color: #fff3ce;
73
+ }
74
+
75
+ .submit-button:hover {
76
+ background-color: #ffc83dc0;
77
+ }
78
+
79
+ .download-button {
80
+ background-color: #98ca56;
81
+ color: white;
82
+ font-weight: bold;
83
+ }
84
+
85
+ .download-button:hover {
86
+ background-color: #98ca56d1;
87
+ }
88
+
89
+ .output-title {
90
+ margin-top: 2rem;
91
+ margin-bottom: 0;
92
+ display: block;
93
+ background-color: #98ca56;
94
+ color: white;
95
+ font-weight: bold;
96
+ font-size: large;
97
+ padding: 6px 15px;
98
+ border-top-left-radius: 6px;
99
+ border-top-right-radius: 6px;
100
+ }
101
+
102
+ .output-box {
103
+ margin-top: 0;
104
+ padding: 6px 15px;
105
+ background-color: white;
106
+ border: 2px solid #98ca56;
107
+ border-bottom-left-radius: 6px;
108
+ border-bottom-right-radius: 6px;
109
+ }
110
+ </style>
111
+ </head>
112
+
113
+ <body>
114
+ <header>
115
+ <h1>🪞Mirror</h1>
116
+ <p>
117
+ 🪞Mirror can help you deal with a wide range of Natural Language Understanding and Information Extraction tasks.
118
+ </p>
119
+ </header>
120
+
121
+ <main>
122
+ <div id="app">
123
+ <div>
124
+ <label for="instruction"><strong>Instruction</strong></label>
125
+ <input id="instruction" type="text" v-model="instruction" placeholder="Mirror mirror tell me ..." size="200">
126
+ </div>
127
+ <div>
128
+ <label for="schema"><strong>Schema Labels</strong></label>
129
+ <p>Split with <code>#</code> for multiple inputs</p>
130
+ <p>For entities, relations or classification, input <code>{"ent|rel|cls": ["cls1", "type2"]}</code> .</p>
131
+ <p>For events and hyper relations, input <code>{"type": ["role1", "role2"]}</code> .</p>
132
+ <input id="schema" type="text" v-model="schema" size="200">
133
+ <!-- <div>
134
+ <button @click.prevent="addCls">Class</button>
135
+ <button @click.prevent="addEnt">Entity</button>
136
+ <button @click.prevent="addDisconEnt">Discontinuous Entity</button>
137
+ <button @click.prevent="addRel">Relation</button>
138
+ <button @click.prevent="addEvent">Event Type</button>
139
+ <button @click.prevent="addHyperRel">Hyper Relation</button>
140
+ </div> -->
141
+ </div>
142
+ <div>
143
+ <label for="text"><strong>Text</strong></label>
144
+ <input id="text" type="text" v-model="text" size="200">
145
+ </div>
146
+ <!-- <div>
147
+ <label for="background"><strong>Background</strong></label>
148
+ <input id="background" type="text" v-model="background" size="200">
149
+ </div> -->
150
+
151
+ <div class="button-group">
152
+ <button @click.prevent="reset">Reset</button>
153
+ <button @click.prevent="clearOutput">Clear Output</button>
154
+ <button class="submit-button" @click.prevent="getResults">Ask Mirror</button>
155
+ </div>
156
+
157
+ <div v-if="timerHandler">
158
+ <p>⏱️ {{ searchSecondsString }}</p>
159
+ </div>
160
+
161
+ <div>
162
+ <div v-if="isNotEmptyObj(results)">
163
+ <label for="output"><strong>Output</strong></label>
164
+ <table>
165
+ <thead>
166
+ <th>Item</th>
167
+ <th>Predicted</th>
168
+ </thead>
169
+ <tbody>
170
+ <tr v-for="(value, key, index) in results" :key="index">
171
+ <template v-if="value.length">
172
+ <td>{{ key }}</td>
173
+ <td>{{ value }}</td>
174
+ </template>
175
+ </tr>
176
+ </tbody>
177
+ </table>
178
+ </div>
179
+ </div>
180
+
181
+ </div>
182
+ </main>
183
+
184
+ <footer>
185
+ <hr>
186
+ Made by Mirror Team w/ 💖
187
+ </footer>
188
+
189
+ <script type="module">
190
+ import { createApp, ref, computed, toRaw, watch } from 'vue'
191
+
192
+ createApp(
193
+ {
194
+ setup() {
195
+ const instruction = ref("")
196
+ const text = ref("")
197
+ const background = ref("")
198
+ const schema = ref("{}")
199
+ const results = ref({})
200
+ const timerHandler = ref(0)
201
+ const searchSeconds = ref(0.0)
202
+ const searchSecondsString = computed(() => {
203
+ return `${searchSeconds.value.toFixed(1)}s`
204
+ })
205
+
206
+ function isNotEmptyObj(obj) {
207
+ return Object.keys(obj).length > 0
208
+ }
209
+
210
+ function clearOutput() {
211
+ timerHandler.value = 0
212
+ results.value = {}
213
+ }
214
+
215
+ function reset() {
216
+ schema.value = "{}"
217
+ clearOutput()
218
+ }
219
+
220
+ function startTimer() {
221
+ searchSeconds.value = 0.0
222
+ timerHandler.value = setInterval(() => {
223
+ searchSeconds.value += 0.1
224
+ }, 100)
225
+ }
226
+
227
+ function endTimer() {
228
+ if (timerHandler.value > 0) {
229
+ clearInterval(timerHandler.value)
230
+ }
231
+ }
232
+
233
+ function getResults() {
234
+ clearOutput()
235
+ startTimer()
236
+ const data = {
237
+ "id": Date.now().toString(),
238
+ "instruction": instruction.value,
239
+ "schema": JSON.parse(schema.value),
240
+ "text": text.value,
241
+ "background": background.value,
242
+ "ans": {},
243
+ }
244
+ const postData = JSON.stringify({
245
+ "data": [data],
246
+ })
247
+ fetch(
248
+ "/process",
249
+ {
250
+ method: "POST",
251
+ headers: {
252
+ 'Content-Type': 'application/json',
253
+ },
254
+ body: postData,
255
+ }
256
+ )
257
+ .then((response) => response.json())
258
+ .then((json) => {
259
+ if (json["ok"] === false) {
260
+ alert(json["msg"])
261
+ } else {
262
+ results.value = json["results"][0]["results"]
263
+ }
264
+ })
265
+ .catch((err) => { alert(err) })
266
+ .finally(() => endTimer())
267
+ }
268
+
269
+ return {
270
+ instruction,
271
+ text,
272
+ background,
273
+ schema,
274
+ results,
275
+ reset,
276
+ clearOutput,
277
+ getResults,
278
+ searchSecondsString,
279
+ timerHandler,
280
+ isNotEmptyObj,
281
+ }
282
+ }
283
+ }
284
+ ).mount("#app")
285
+ </script>
286
+ </body>
287
+
288
+ </html>