Spaces:
Sleeping
Sleeping
Initial Gradio Space implementation for WimBERT Synth v0
Browse files- .gitignore +19 -0
- LICENSE +202 -0
- README.md +93 -6
- app.py +249 -0
- examples.json +7 -0
- requirements.txt +5 -0
.gitignore
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
.Python
|
| 7 |
+
*.so
|
| 8 |
+
*.egg
|
| 9 |
+
*.egg-info/
|
| 10 |
+
dist/
|
| 11 |
+
build/
|
| 12 |
+
.DS_Store
|
| 13 |
+
.vscode/
|
| 14 |
+
.idea/
|
| 15 |
+
*.log
|
| 16 |
+
.env
|
| 17 |
+
.venv
|
| 18 |
+
gradio_cached_examples/
|
| 19 |
+
flagged/
|
LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 [yyyy] [name of copyright owner]
|
| 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.
|
| 202 |
+
|
README.md
CHANGED
|
@@ -1,14 +1,101 @@
|
|
| 1 |
---
|
| 2 |
-
title: WimBERT Synth
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.49.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description:
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: WimBERT Synth v0
|
| 3 |
+
emoji: 🏛️
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.49.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: Dutch multi-label classifier for signal messages
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# WimBERT Synth v0: Dutch Multi-Label Signal Classifier
|
| 15 |
+
|
| 16 |
+
Demo of a dual-head BERT classifier trained on synthetic Dutch government signals.
|
| 17 |
+
Predicts relevant topics (**onderwerp**, 64 labels) and sentiment/experience
|
| 18 |
+
(**beleving**, 33 labels) for each input message.
|
| 19 |
+
|
| 20 |
+
## 🚀 Usage
|
| 21 |
+
|
| 22 |
+
1. Enter Dutch text (e.g., a citizen feedback message about government services)
|
| 23 |
+
2. Click **Voorspel** to classify
|
| 24 |
+
3. Adjust **Drempel** (threshold) to change prediction sensitivity
|
| 25 |
+
4. View results in three tabs:
|
| 26 |
+
- **Samenvatting**: Top-K predictions per head with color-coded probabilities
|
| 27 |
+
- **Alle labels**: Complete list of all labels sorted by probability
|
| 28 |
+
- **JSON**: Raw predictions in machine-readable format
|
| 29 |
+
|
| 30 |
+
## 🎯 Features
|
| 31 |
+
|
| 32 |
+
- **Dual-head classification**: Simultaneously predicts topic (onderwerp) and experience (beleving)
|
| 33 |
+
- **Interactive threshold**: Adjust which labels are considered "predicted"
|
| 34 |
+
- **Color-coded visualization**: Probability intensity shown via color (darker = higher probability)
|
| 35 |
+
- **Accessible**: All probabilities shown numerically, colors are enhancements
|
| 36 |
+
- **Fast**: Optimized for CPU inference (~2-5s) with optional GPU acceleration
|
| 37 |
+
|
| 38 |
+
## 🤖 Model
|
| 39 |
+
|
| 40 |
+
- **Base model**: `bert-base-multilingual-cased`
|
| 41 |
+
- **Architecture**: Dual classification heads with 64 onderwerp + 33 beleving labels
|
| 42 |
+
- **Training**: Synthetic data via Argilla + distillation pipeline
|
| 43 |
+
- **License**: Apache-2.0
|
| 44 |
+
- **Full model card**: [UWV/wimbert-synth-v0](https://huggingface.co/UWV/wimbert-synth-v0)
|
| 45 |
+
|
| 46 |
+
### Labels
|
| 47 |
+
|
| 48 |
+
**Onderwerp (64 topics)**:
|
| 49 |
+
Advies, Algemene veiligheid, Begeleiding, Bijstand, Bouwoverlast, COVID-19, Criminaliteit,
|
| 50 |
+
Documentaanvraag, Energiekosten, Evenementen, Financiële regelingen, Geluidsoverlast,
|
| 51 |
+
Gemeentelijke heffingen, Hangjongeren, Huisdierenoverlast, Hulp aan dak- en thuislozen,
|
| 52 |
+
Infrastructuur, Kwijtschelding, Migratie, Onderhoud omgeving, Parkeren, Schade en claims,
|
| 53 |
+
Verkeersmaatregelen, Verkeersveiligheid, Wijkteam, and more...
|
| 54 |
+
|
| 55 |
+
**Beleving (33 experiences)**:
|
| 56 |
+
Afspraakmogelijkheden, Algemene ervaring, Behulpzaamheid, Bereikbaarheid, Bezwaar & bewijs,
|
| 57 |
+
Communicatie, Deskundigheid, Duidelijkheid, Efficiëntie, Faciliteiten, Gebruiksgemak,
|
| 58 |
+
Informatievoorziening, Integriteit, Kwaliteit klantenservice, Snelheid van afhandeling,
|
| 59 |
+
Vriendelijkheid, Wachttijd, and more...
|
| 60 |
+
|
| 61 |
+
## 🔒 Privacy
|
| 62 |
+
|
| 63 |
+
- Input text is processed **in-memory only**
|
| 64 |
+
- No data is logged or stored beyond standard Gradio telemetry
|
| 65 |
+
- Model runs entirely within this Space (no external API calls)
|
| 66 |
+
|
| 67 |
+
## ⚙️ Hardware
|
| 68 |
+
|
| 69 |
+
- **CPU**: Works on free tier (~3-5s inference)
|
| 70 |
+
- **GPU (T4)**: Recommended for production (<1s inference)
|
| 71 |
+
|
| 72 |
+
Current Space is running on: **CPU** with FP32
|
| 73 |
+
|
| 74 |
+
## 🛠️ Local Development
|
| 75 |
+
|
| 76 |
+
```bash
|
| 77 |
+
# Clone and setup
|
| 78 |
+
git clone https://huggingface.co/spaces/UWV/wimbert-synth-v0
|
| 79 |
+
cd wimbert-synth-v0
|
| 80 |
+
python3 -m venv venv
|
| 81 |
+
source venv/bin/activate
|
| 82 |
+
pip install -r requirements.txt
|
| 83 |
+
|
| 84 |
+
# Run
|
| 85 |
+
python app.py
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## 📊 Example Use Cases
|
| 89 |
+
|
| 90 |
+
- **Citizen feedback routing**: Automatically categorize incoming messages
|
| 91 |
+
- **Sentiment analysis**: Understand citizen experience with government services
|
| 92 |
+
- **Analytics**: Aggregate trends across topics and experiences
|
| 93 |
+
- **Triage**: Prioritize urgent or negative feedback
|
| 94 |
+
|
| 95 |
+
⚠️ **Note**: This is a research/demo tool. Not intended for automated decision-making.
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
**Built with**: Gradio • Transformers • PyTorch
|
| 100 |
+
**Developed by**: UWV
|
| 101 |
+
**License**: Apache-2.0
|
app.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
WimBERT Synth v0 Gradio Space
|
| 4 |
+
Dual-head multi-label classifier for Dutch signal messages
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
import importlib.util
|
| 9 |
+
import torch
|
| 10 |
+
import gradio as gr
|
| 11 |
+
from huggingface_hub import snapshot_download
|
| 12 |
+
|
| 13 |
+
# Constants
|
| 14 |
+
MODEL_REPO = "UWV/wimbert-synth-v0"
|
| 15 |
+
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
+
DTYPE = torch.float16 if DEVICE.type == "cuda" else torch.float32
|
| 17 |
+
MAX_LENGTH = 512 # Default to 512 for better CPU performance
|
| 18 |
+
|
| 19 |
+
print(f"🔧 Loading model from {MODEL_REPO}...")
|
| 20 |
+
print(f"🖥️ Device: {DEVICE} ({DTYPE})")
|
| 21 |
+
|
| 22 |
+
# Download model files (uses HF cache)
|
| 23 |
+
model_dir = snapshot_download(MODEL_REPO, cache_dir=None)
|
| 24 |
+
|
| 25 |
+
# Dynamic import of model.py from downloaded dir
|
| 26 |
+
spec = importlib.util.spec_from_file_location("model", f"{model_dir}/model.py")
|
| 27 |
+
model_module = importlib.util.module_from_spec(spec)
|
| 28 |
+
spec.loader.exec_module(model_module)
|
| 29 |
+
DualHeadModel = model_module.DualHeadModel
|
| 30 |
+
|
| 31 |
+
# Load model + tokenizer + config
|
| 32 |
+
model, tokenizer, config = DualHeadModel.from_pretrained(model_dir, device=DEVICE)
|
| 33 |
+
|
| 34 |
+
# Cast to target dtype
|
| 35 |
+
if DTYPE == torch.float16:
|
| 36 |
+
model = model.half()
|
| 37 |
+
|
| 38 |
+
# Warm-up inference
|
| 39 |
+
with torch.no_grad():
|
| 40 |
+
dummy_input = tokenizer("Warm-up", return_tensors="pt", padding="max_length",
|
| 41 |
+
max_length=MAX_LENGTH, truncation=True)
|
| 42 |
+
_ = model.predict(
|
| 43 |
+
dummy_input["input_ids"].to(DEVICE),
|
| 44 |
+
dummy_input["attention_mask"].to(DEVICE)
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
print(f"✅ Model loaded and warmed up")
|
| 48 |
+
|
| 49 |
+
# Extract label names
|
| 50 |
+
LABELS_ONDERWERP = config["labels"]["onderwerp"]
|
| 51 |
+
LABELS_BELEVING = config["labels"]["beleving"]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def prob_to_color(prob: float, threshold: float) -> str:
|
| 55 |
+
"""Generate CSS style for probability visualization"""
|
| 56 |
+
lightness = 95 - int(prob * 65)
|
| 57 |
+
border = "2px solid #1e3a8a" if prob >= threshold else "1px solid #e5e7eb"
|
| 58 |
+
return f"background: hsl(210, 80%, {lightness}%); border: {border}; padding: 6px 12px; border-radius: 4px; margin: 2px 0;"
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def format_topk(labels: list, probs: list, threshold: float, topk: int) -> str:
|
| 62 |
+
"""Generate HTML for top-K labels"""
|
| 63 |
+
sorted_indices = sorted(range(len(probs)), key=lambda i: probs[i], reverse=True)
|
| 64 |
+
html = "<div style='display: flex; flex-direction: column; gap: 6px;'>"
|
| 65 |
+
for idx in sorted_indices[:topk]:
|
| 66 |
+
label = labels[idx]
|
| 67 |
+
prob = probs[idx]
|
| 68 |
+
style = prob_to_color(prob, threshold)
|
| 69 |
+
predicted = " ✓" if prob >= threshold else ""
|
| 70 |
+
html += f"<div style='{style}'><b>{label}</b>: {prob:.3f}{predicted}</div>"
|
| 71 |
+
html += "</div>"
|
| 72 |
+
return html
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def format_all_labels(head_name: str, labels: list, probs: list, threshold: float) -> str:
|
| 76 |
+
"""Generate scrollable table for all labels"""
|
| 77 |
+
sorted_indices = sorted(range(len(probs)), key=lambda i: probs[i], reverse=True)
|
| 78 |
+
html = f"<h3>{head_name}</h3><div style='max-height: 500px; overflow-y: auto; border: 1px solid #e5e7eb; border-radius: 4px;'>"
|
| 79 |
+
html += "<table style='width: 100%; border-collapse: collapse;'>"
|
| 80 |
+
html += "<thead style='position: sticky; top: 0; background: white; border-bottom: 2px solid #e5e7eb;'>"
|
| 81 |
+
html += "<tr><th style='text-align: left; padding: 8px;'>Label</th><th style='text-align: right; padding: 8px;'>Probability</th><th style='padding: 8px;'>Predicted</th></tr>"
|
| 82 |
+
html += "</thead><tbody>"
|
| 83 |
+
for idx in sorted_indices:
|
| 84 |
+
label = labels[idx]
|
| 85 |
+
prob = probs[idx]
|
| 86 |
+
style = prob_to_color(prob, threshold)
|
| 87 |
+
predicted = "✓" if prob >= threshold else ""
|
| 88 |
+
html += f"<tr><td style='{style}'><b>{label}</b></td><td style='text-align: right; padding: 8px;'>{prob:.4f}</td><td style='text-align: center; padding: 8px;'>{predicted}</td></tr>"
|
| 89 |
+
html += "</tbody></table></div>"
|
| 90 |
+
return html
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
@torch.inference_mode()
|
| 94 |
+
def predict(text: str, threshold: float, topk: int):
|
| 95 |
+
"""Run inference and return visualizations"""
|
| 96 |
+
if not text or not text.strip():
|
| 97 |
+
empty_msg = "<p style='color: #666; font-style: italic;'>Voer een bericht in om te classificeren...</p>"
|
| 98 |
+
return empty_msg, empty_msg, {}
|
| 99 |
+
|
| 100 |
+
# Tokenize
|
| 101 |
+
inputs = tokenizer(
|
| 102 |
+
text,
|
| 103 |
+
return_tensors="pt",
|
| 104 |
+
padding="max_length",
|
| 105 |
+
max_length=MAX_LENGTH,
|
| 106 |
+
truncation=True
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
# Move to device
|
| 110 |
+
input_ids = inputs["input_ids"].to(DEVICE)
|
| 111 |
+
attention_mask = inputs["attention_mask"].to(DEVICE)
|
| 112 |
+
|
| 113 |
+
# Predict
|
| 114 |
+
onderwerp_probs, beleving_probs = model.predict(input_ids, attention_mask)
|
| 115 |
+
|
| 116 |
+
# Convert to lists
|
| 117 |
+
onderwerp_probs = onderwerp_probs[0].cpu().numpy().tolist()
|
| 118 |
+
beleving_probs = beleving_probs[0].cpu().numpy().tolist()
|
| 119 |
+
|
| 120 |
+
# Generate summary view (top-K for each head side by side)
|
| 121 |
+
summary_html = "<div style='display: grid; grid-template-columns: 1fr 1fr; gap: 20px;'>"
|
| 122 |
+
summary_html += f"<div><h3>Onderwerp (Top-{topk})</h3>{format_topk(LABELS_ONDERWERP, onderwerp_probs, threshold, topk)}</div>"
|
| 123 |
+
summary_html += f"<div><h3>Beleving (Top-{topk})</h3>{format_topk(LABELS_BELEVING, beleving_probs, threshold, topk)}</div>"
|
| 124 |
+
summary_html += "</div>"
|
| 125 |
+
|
| 126 |
+
# Generate all labels view
|
| 127 |
+
all_labels_html = "<div style='display: grid; grid-template-columns: 1fr 1fr; gap: 20px;'>"
|
| 128 |
+
all_labels_html += f"<div>{format_all_labels('Onderwerp', LABELS_ONDERWERP, onderwerp_probs, threshold)}</div>"
|
| 129 |
+
all_labels_html += f"<div>{format_all_labels('Beleving', LABELS_BELEVING, beleving_probs, threshold)}</div>"
|
| 130 |
+
all_labels_html += "</div>"
|
| 131 |
+
|
| 132 |
+
# Generate JSON output
|
| 133 |
+
json_output = {
|
| 134 |
+
"text": text,
|
| 135 |
+
"threshold": threshold,
|
| 136 |
+
"onderwerp": {
|
| 137 |
+
"probabilities": {label: float(prob) for label, prob in zip(LABELS_ONDERWERP, onderwerp_probs)},
|
| 138 |
+
"predicted": [label for label, prob in zip(LABELS_ONDERWERP, onderwerp_probs) if prob >= threshold]
|
| 139 |
+
},
|
| 140 |
+
"beleving": {
|
| 141 |
+
"probabilities": {label: float(prob) for label, prob in zip(LABELS_BELEVING, beleving_probs)},
|
| 142 |
+
"predicted": [label for label, prob in zip(LABELS_BELEVING, beleving_probs) if prob >= threshold]
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return summary_html, all_labels_html, json_output
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def load_examples():
|
| 150 |
+
"""Load example texts"""
|
| 151 |
+
try:
|
| 152 |
+
with open("examples.json") as f:
|
| 153 |
+
return json.load(f)
|
| 154 |
+
except:
|
| 155 |
+
return []
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
# Build Gradio interface
|
| 159 |
+
with gr.Blocks(title="WimBERT Synth v0", theme=gr.themes.Soft()) as demo:
|
| 160 |
+
gr.Markdown("""
|
| 161 |
+
# 🏛️ WimBERT Synth v0: Multi-label Signaal Classifier
|
| 162 |
+
|
| 163 |
+
Classificeert Nederlandse signaalberichten op **Onderwerp** (64 categorieën) en **Beleving** (33 categorieën).
|
| 164 |
+
""")
|
| 165 |
+
|
| 166 |
+
with gr.Row():
|
| 167 |
+
with gr.Column(scale=2):
|
| 168 |
+
input_text = gr.Textbox(
|
| 169 |
+
label="Signaalbericht (Nederlands)",
|
| 170 |
+
lines=8,
|
| 171 |
+
placeholder="Bijv: Ik kan niet parkeren bij mijn huis en de website voor vergunningen werkt niet...",
|
| 172 |
+
info="Voer een bericht in en klik op 'Voorspel'"
|
| 173 |
+
)
|
| 174 |
+
with gr.Row():
|
| 175 |
+
predict_btn = gr.Button("🔮 Voorspel", variant="primary", scale=2)
|
| 176 |
+
clear_btn = gr.ClearButton([input_text], value="🗑️ Wissen", scale=1)
|
| 177 |
+
|
| 178 |
+
with gr.Column(scale=1):
|
| 179 |
+
threshold_slider = gr.Slider(
|
| 180 |
+
minimum=0,
|
| 181 |
+
maximum=1,
|
| 182 |
+
value=0.5,
|
| 183 |
+
step=0.05,
|
| 184 |
+
label="🎯 Drempel",
|
| 185 |
+
info="Labels boven deze waarde worden als 'voorspeld' gemarkeerd"
|
| 186 |
+
)
|
| 187 |
+
topk_slider = gr.Slider(
|
| 188 |
+
minimum=1,
|
| 189 |
+
maximum=15,
|
| 190 |
+
value=5,
|
| 191 |
+
step=1,
|
| 192 |
+
label="📊 Top-K",
|
| 193 |
+
info="Aantal top labels om te tonen in samenvatting"
|
| 194 |
+
)
|
| 195 |
+
gr.Markdown(f"""
|
| 196 |
+
**Hardware:** {DEVICE.type.upper()}
|
| 197 |
+
**Dtype:** {DTYPE}
|
| 198 |
+
**Max length:** {MAX_LENGTH}
|
| 199 |
+
""")
|
| 200 |
+
|
| 201 |
+
with gr.Tabs():
|
| 202 |
+
with gr.Tab("📋 Samenvatting"):
|
| 203 |
+
summary_output = gr.HTML(label="Top voorspellingen per categorie")
|
| 204 |
+
|
| 205 |
+
with gr.Tab("📊 Alle labels"):
|
| 206 |
+
all_labels_output = gr.HTML(label="Volledige classificatie")
|
| 207 |
+
|
| 208 |
+
with gr.Tab("💾 JSON"):
|
| 209 |
+
json_output = gr.JSON(label="Ruwe output")
|
| 210 |
+
|
| 211 |
+
gr.Examples(
|
| 212 |
+
examples=load_examples(),
|
| 213 |
+
inputs=input_text,
|
| 214 |
+
label="📝 Voorbeelden"
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
gr.Markdown("""
|
| 218 |
+
---
|
| 219 |
+
### ℹ️ Over dit model
|
| 220 |
+
- **Model:** `UWV/wimbert-synth-v0` (dual-head BERT)
|
| 221 |
+
- **Licentie:** Apache-2.0
|
| 222 |
+
- **Privacy:** Input wordt alleen in-memory verwerkt, niet opgeslagen
|
| 223 |
+
|
| 224 |
+
[Model Card](https://huggingface.co/UWV/wimbert-synth-v0) • Gebouwd met Gradio
|
| 225 |
+
""")
|
| 226 |
+
|
| 227 |
+
# Event handlers
|
| 228 |
+
predict_btn.click(
|
| 229 |
+
fn=predict,
|
| 230 |
+
inputs=[input_text, threshold_slider, topk_slider],
|
| 231 |
+
outputs=[summary_output, all_labels_output, json_output]
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
# Update predictions when threshold/topk changes (if there's existing output)
|
| 235 |
+
threshold_slider.change(
|
| 236 |
+
fn=predict,
|
| 237 |
+
inputs=[input_text, threshold_slider, topk_slider],
|
| 238 |
+
outputs=[summary_output, all_labels_output, json_output]
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
topk_slider.change(
|
| 242 |
+
fn=predict,
|
| 243 |
+
inputs=[input_text, threshold_slider, topk_slider],
|
| 244 |
+
outputs=[summary_output, all_labels_output, json_output]
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
if __name__ == "__main__":
|
| 249 |
+
demo.launch()
|
examples.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
["Ik heb geprobeerd te bellen maar krijg niemand aan de lijn. Kan iemand mij helpen met mijn vraag over mijn uitkering?"],
|
| 3 |
+
["De vuilcontainers zijn weer kapot en het stinkt hier verschrikkelijk. Wanneer wordt dit opgelost?"],
|
| 4 |
+
["Ik wil graag een parkeervergunning aanvragen maar de website werkt niet goed. Kan dit eenvoudiger?"],
|
| 5 |
+
["Bedankt voor de snelle en vriendelijke hulp bij mijn aanvraag! De medewerker was zeer behulpzaam."],
|
| 6 |
+
["Ik ben erg ontevreden over de lange wachttijden en onduidelijke informatie die ik kreeg."]
|
| 7 |
+
]
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0
|
| 2 |
+
transformers>=4.40
|
| 3 |
+
torch>=2.0
|
| 4 |
+
safetensors>=0.4
|
| 5 |
+
huggingface-hub>=0.20
|