Fill-Mask
Transformers
Safetensors
Urdu
avey-b
urdu
masked-language-modeling
encoder
custom_code
Eval Results (legacy)
Instructions to use SndOpenResearch/avey-b-ur with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SndOpenResearch/avey-b-ur with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="SndOpenResearch/avey-b-ur", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("SndOpenResearch/avey-b-ur", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Publish Avey-B Urdu 25M with benchmarks and model card
Browse files- .gitattributes +1 -0
- LICENSE +201 -0
- MANIFEST.json +56 -0
- README.md +153 -0
- assets/benchmark_overview.png +3 -0
- assets/training_loss.png +0 -0
- benchmark_results.json +159 -0
- config.json +26 -0
- configuration_avey.py +28 -0
- fertility_check.json +3 -0
- model.safetensors +3 -0
- modeling_avey.py +307 -0
- tokenizer.json +0 -0
- tokenizer_config.json +11 -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 |
+
assets/benchmark_overview.png filter=lfs diff=lfs merge=lfs -text
|
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 2026 Avey Inc.
|
| 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.
|
MANIFEST.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"generated_at": "2026-09-10T09:59:10.314711+00:00",
|
| 3 |
+
"lang": "urd_Arab",
|
| 4 |
+
"map_url": "https://data.hplt-project.org/three/sorted/urd_Arab.map",
|
| 5 |
+
"bins_requested": [
|
| 6 |
+
10,
|
| 7 |
+
9
|
| 8 |
+
],
|
| 9 |
+
"prob_threshold": 0.8,
|
| 10 |
+
"min_chars": 20,
|
| 11 |
+
"val_fraction": 0.005,
|
| 12 |
+
"max_docs_per_shard": 50000,
|
| 13 |
+
"max_chars_per_shard": 500000000,
|
| 14 |
+
"max_shards": null,
|
| 15 |
+
"stream_download": true,
|
| 16 |
+
"shards": [
|
| 17 |
+
{
|
| 18 |
+
"url": "https://data.hplt-project.org/three/sorted/urd_Arab/10_1.jsonl.zst",
|
| 19 |
+
"bin": 10,
|
| 20 |
+
"raw_docs": 2162,
|
| 21 |
+
"dropped_low_prob": 0,
|
| 22 |
+
"dropped_empty": 0,
|
| 23 |
+
"dropped_exact_dup": 0,
|
| 24 |
+
"pii_spans_redacted": 24,
|
| 25 |
+
"kept_train": 2151,
|
| 26 |
+
"kept_val": 11,
|
| 27 |
+
"chars_kept": 41055559
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"url": "https://data.hplt-project.org/three/sorted/urd_Arab/9_1.jsonl.zst",
|
| 31 |
+
"bin": 9,
|
| 32 |
+
"raw_docs": 29290,
|
| 33 |
+
"dropped_low_prob": 3,
|
| 34 |
+
"dropped_empty": 0,
|
| 35 |
+
"dropped_exact_dup": 1,
|
| 36 |
+
"pii_spans_redacted": 729,
|
| 37 |
+
"kept_train": 29146,
|
| 38 |
+
"kept_val": 140,
|
| 39 |
+
"chars_kept": 500109810
|
| 40 |
+
}
|
| 41 |
+
],
|
| 42 |
+
"totals": {
|
| 43 |
+
"raw_docs": 31452,
|
| 44 |
+
"kept_train": 31297,
|
| 45 |
+
"kept_val": 151,
|
| 46 |
+
"dropped_low_prob": 3,
|
| 47 |
+
"dropped_empty": 0,
|
| 48 |
+
"dropped_exact_dup": 1,
|
| 49 |
+
"pii_spans_redacted": 753,
|
| 50 |
+
"chars_kept": 541165369
|
| 51 |
+
},
|
| 52 |
+
"consolidated_counts": {
|
| 53 |
+
"train": 31297,
|
| 54 |
+
"val": 151
|
| 55 |
+
}
|
| 56 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- ur
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: fill-mask
|
| 7 |
+
tags:
|
| 8 |
+
- avey-b
|
| 9 |
+
- urdu
|
| 10 |
+
- masked-language-modeling
|
| 11 |
+
- encoder
|
| 12 |
+
- custom_code
|
| 13 |
+
datasets:
|
| 14 |
+
- HPLT/HPLT3.0
|
| 15 |
+
model-index:
|
| 16 |
+
- name: Avey-B Urdu 25M
|
| 17 |
+
results:
|
| 18 |
+
- task:
|
| 19 |
+
type: text-classification
|
| 20 |
+
name: Urdu sentiment classification
|
| 21 |
+
dataset:
|
| 22 |
+
type: mirfan899/imdb_urdu_reviews
|
| 23 |
+
name: IMDb Urdu Reviews
|
| 24 |
+
split: test
|
| 25 |
+
metrics:
|
| 26 |
+
- type: accuracy
|
| 27 |
+
value: 0.785333
|
| 28 |
+
name: Accuracy
|
| 29 |
+
- task:
|
| 30 |
+
type: token-classification
|
| 31 |
+
name: Urdu named-entity recognition
|
| 32 |
+
dataset:
|
| 33 |
+
type: unimelb-nlp/wikiann
|
| 34 |
+
name: WikiANN Urdu
|
| 35 |
+
config: ur
|
| 36 |
+
split: test
|
| 37 |
+
metrics:
|
| 38 |
+
- type: f1
|
| 39 |
+
value: 0.812677
|
| 40 |
+
name: Entity F1
|
| 41 |
+
widget:
|
| 42 |
+
- text: "پاکستان کا دارالحکومت [MASK] ہے۔"
|
| 43 |
+
- text: "اردو ایک خوبصورت [MASK] ہے۔"
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
# Avey-B Urdu 25M
|
| 47 |
+
|
| 48 |
+
**A compact, fast Urdu encoder trained from scratch for masked-language modeling.**
|
| 49 |
+
|
| 50 |
+
🚀 **24.87M parameters** · ⚡ **408K tokens/s on RTX 4060** · 🧠 **32K Urdu WordPiece vocabulary**
|
| 51 |
+
|
| 52 |
+

|
| 53 |
+
|
| 54 |
+
## ✨ Highlights
|
| 55 |
+
|
| 56 |
+
- **78.53% ± 0.51 sentiment accuracy**, essentially level with 278M-parameter XLM-R base in this setup.
|
| 57 |
+
- **81.27 WikiANN Urdu entity F1** with only 24.87M parameters.
|
| 58 |
+
- **1.71 ms** encoder latency at batch 1 / length 128 and **148 MiB** peak VRAM at batch 16 / length 512.
|
| 59 |
+
- **14.29 held-out MLM perplexity**, **50.46% top-1**, and **70.39% top-5** masked-token accuracy.
|
| 60 |
+
- Compact Urdu tokenization: **4.19 characters/token** on held-out data.
|
| 61 |
+
|
| 62 |
+
## 🧪 Quick start
|
| 63 |
+
|
| 64 |
+
This model contains a custom Avey architecture, so `trust_remote_code=True` is required.
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
import torch
|
| 68 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
| 69 |
+
|
| 70 |
+
repo_id = "mahwizzzz/avey-b-ur"
|
| 71 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
|
| 72 |
+
model = AutoModelForMaskedLM.from_pretrained(repo_id, trust_remote_code=True).eval()
|
| 73 |
+
|
| 74 |
+
text = "پاکستان کا دارالحکومت [MASK] ہے۔"
|
| 75 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 76 |
+
with torch.inference_mode():
|
| 77 |
+
logits = model(**inputs).logits
|
| 78 |
+
|
| 79 |
+
mask_index = (inputs.input_ids[0] == tokenizer.mask_token_id).nonzero()[0, 0]
|
| 80 |
+
top_ids = logits[0, mask_index].topk(5).indices
|
| 81 |
+
print(tokenizer.convert_ids_to_tokens(top_ids.tolist()))
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
Extract contextual token representations with `AutoModel`:
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
from transformers import AutoModel, AutoTokenizer
|
| 88 |
+
|
| 89 |
+
tokenizer = AutoTokenizer.from_pretrained("mahwizzzz/avey-b-ur", trust_remote_code=True)
|
| 90 |
+
encoder = AutoModel.from_pretrained("mahwizzzz/avey-b-ur", trust_remote_code=True)
|
| 91 |
+
hidden = encoder(**tokenizer("یہ ایک اردو جملہ ہے۔", return_tensors="pt")).last_hidden_state
|
| 92 |
+
print(hidden.shape) # [batch, tokens, 384]
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## 📊 Evaluation
|
| 96 |
+
|
| 97 |
+
| Model | Parameters | Sentiment accuracy | WikiANN Urdu NER F1 |
|
| 98 |
+
|---|---:|---:|---:|
|
| 99 |
+
| **Avey-B Urdu** | **24.87M** | **78.53% ± 0.51** | **81.27** |
|
| 100 |
+
| UrNova | 94.72M | 81.83% ± 0.42 | 87.79 |
|
| 101 |
+
| HPLT Urdu BERT | 124.36M | 83.93% ± 1.27 | 90.92 |
|
| 102 |
+
| XLM-R base | 278.04M | 78.80% ± 0.52 | 84.89 |
|
| 103 |
+
|
| 104 |
+
Sentiment uses 4K train / 1K validation / 1K test examples for two epochs; the test result is mean ± sample standard deviation over three seeds after validation learning-rate selection. The source is a machine-translated Urdu IMDb dataset. NER uses 4K training examples and the full 1K validation / 1K test Urdu WikiANN splits for three epochs; it reports validation-selected entity F1 for one seed. See [`benchmark_results.json`](benchmark_results.json) for machine-readable results.
|
| 105 |
+
|
| 106 |
+
### RTX 4060 BF16 inference
|
| 107 |
+
|
| 108 |
+
| Model | B1/L128 latency | B16/L512 throughput | B16/L512 peak VRAM |
|
| 109 |
+
|---|---:|---:|---:|
|
| 110 |
+
| **Avey-B Urdu** | **1.71 ms** | **408,329 tok/s** | **148 MiB** |
|
| 111 |
+
| UrNova | 4.98 ms | 84,695 tok/s | 345 MiB |
|
| 112 |
+
| HPLT Urdu BERT | 4.95 ms | 40,400 tok/s | 1,821 MiB |
|
| 113 |
+
| XLM-R base | 2.18 ms | 136,274 tok/s | 678 MiB |
|
| 114 |
+
|
| 115 |
+
Eager encoder inference with synthetic full-length token tensors, 10 warmup and 30 measured iterations. Hardware and software choices can materially change these numbers.
|
| 116 |
+
|
| 117 |
+
## 🏋️ Training
|
| 118 |
+
|
| 119 |
+

|
| 120 |
+
|
| 121 |
+
| Item | Value |
|
| 122 |
+
|---|---|
|
| 123 |
+
| Corpus | HPLT 3.0 Urdu (`urd_Arab`), quality bins 10 and 9 |
|
| 124 |
+
| Clean data | 31,297 train docs, 151 validation docs, 541,165,369 characters |
|
| 125 |
+
| Sequence length | 512 |
|
| 126 |
+
| Token batch | 16,384 tokens/step |
|
| 127 |
+
| Training | 20,000 steps, BF16, fused AdamW |
|
| 128 |
+
| Peak learning rate | 7e-4 |
|
| 129 |
+
| Hardware/runtime | NVIDIA RTX 4060 8GB, approximately 20 minutes |
|
| 130 |
+
| Final train loss | 2.52 |
|
| 131 |
+
|
| 132 |
+
The architecture has 12 alternating static/dynamic Avey layers, 384-dimensional embeddings, 128-token chunks, and `k=3` retrieval/compression context. The checkpoint was trained at sequence length 512; longer contexts were not evaluated here.
|
| 133 |
+
|
| 134 |
+
## ⚠️ Intended use and limitations
|
| 135 |
+
|
| 136 |
+
Use this checkpoint for Urdu classification, token classification, representation extraction, or continued pretraining. It is an **encoder**, not a chat model or free-text generator. Benchmark coverage is limited to masked-token prediction, machine-translated movie-review sentiment, and Wikipedia-derived NER; evaluate on native, domain-specific Urdu before production use.
|
| 137 |
+
|
| 138 |
+
HPLT packages its dataset under CC0 but does not own the underlying web text. The Apache-2.0 model license does not grant rights to third-party source documents that may be reproduced by the model.
|
| 139 |
+
|
| 140 |
+
## 📄 Architecture and citation
|
| 141 |
+
|
| 142 |
+
Based on [Avey-B](https://arxiv.org/abs/2602.15814), an attention-free bidirectional encoder architecture.
|
| 143 |
+
|
| 144 |
+
```bibtex
|
| 145 |
+
@inproceedings{2026aveyb,
|
| 146 |
+
title={Avey-B},
|
| 147 |
+
author={Acharya, Devang and Hammoud, Mohammad},
|
| 148 |
+
booktitle={The Fourteenth International Conference on Learning Representations},
|
| 149 |
+
year={2026}
|
| 150 |
+
}
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
Training provenance is available in [`MANIFEST.json`](MANIFEST.json). Model code is included for reproducible loading.
|
assets/benchmark_overview.png
ADDED
|
Git LFS Details
|
assets/training_loss.png
ADDED
|
benchmark_results.json
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"protocol": {
|
| 3 |
+
"sentiment": "4k train / 1k validation / 1k test, 2 epochs, 3 seeds",
|
| 4 |
+
"ner": "Urdu WikiANN, 4k train / 1k validation / 1k test, 3 epochs, seed 0",
|
| 5 |
+
"efficiency": "RTX 4060, eager BF16 encoder inference, 10 warmup + 30 measured iterations"
|
| 6 |
+
},
|
| 7 |
+
"models": {
|
| 8 |
+
"Avey-B Urdu": {
|
| 9 |
+
"model_id": "avey-b-urdu-25m/checkpoint_19999",
|
| 10 |
+
"sentiment_accuracy_mean": 0.7853333333333333,
|
| 11 |
+
"sentiment_accuracy_std": 0.005131601439446889,
|
| 12 |
+
"sentiment_seed_scores": [
|
| 13 |
+
0.781,
|
| 14 |
+
0.784,
|
| 15 |
+
0.791
|
| 16 |
+
],
|
| 17 |
+
"sentiment_best_lr": 0.0005,
|
| 18 |
+
"wikiann_ner_f1": 0.8126773888363292,
|
| 19 |
+
"wikiann_best_lr": 0.0005,
|
| 20 |
+
"parameters": 24865804,
|
| 21 |
+
"checkpoint_mb": 94.86239624023438,
|
| 22 |
+
"latency_ms_b1_l128": 1.7135274251302084,
|
| 23 |
+
"tokens_per_second_b16_l512": 408328.5424109701,
|
| 24 |
+
"peak_vram_mb_b16_l512": 148.267578125
|
| 25 |
+
},
|
| 26 |
+
"UrNova": {
|
| 27 |
+
"model_id": "ProximaAI/urnova-95m",
|
| 28 |
+
"sentiment_accuracy_mean": 0.8183333333333332,
|
| 29 |
+
"sentiment_accuracy_std": 0.0041633319989322695,
|
| 30 |
+
"sentiment_seed_scores": [
|
| 31 |
+
0.817,
|
| 32 |
+
0.815,
|
| 33 |
+
0.823
|
| 34 |
+
],
|
| 35 |
+
"sentiment_best_lr": 0.0001,
|
| 36 |
+
"wikiann_ner_f1": 0.877932024892293,
|
| 37 |
+
"wikiann_best_lr": 0.0001,
|
| 38 |
+
"parameters": 94723200,
|
| 39 |
+
"checkpoint_mb": 363.1072540283203,
|
| 40 |
+
"latency_ms_b1_l128": 4.984183247884115,
|
| 41 |
+
"tokens_per_second_b16_l512": 84695.40102035012,
|
| 42 |
+
"peak_vram_mb_b16_l512": 344.56005859375
|
| 43 |
+
},
|
| 44 |
+
"HPLT Urdu BERT": {
|
| 45 |
+
"model_id": "HPLT/hplt_bert_base_ur",
|
| 46 |
+
"sentiment_accuracy_mean": 0.8393333333333333,
|
| 47 |
+
"sentiment_accuracy_std": 0.012662279942148398,
|
| 48 |
+
"sentiment_seed_scores": [
|
| 49 |
+
0.853,
|
| 50 |
+
0.828,
|
| 51 |
+
0.837
|
| 52 |
+
],
|
| 53 |
+
"sentiment_best_lr": 0.0001,
|
| 54 |
+
"wikiann_ner_f1": 0.9091792132102962,
|
| 55 |
+
"wikiann_best_lr": 0.0001,
|
| 56 |
+
"parameters": 124361472,
|
| 57 |
+
"checkpoint_mb": 596.7949447631836,
|
| 58 |
+
"latency_ms_b1_l128": 4.946500142415364,
|
| 59 |
+
"tokens_per_second_b16_l512": 40399.82395789245,
|
| 60 |
+
"peak_vram_mb_b16_l512": 1821.2353515625
|
| 61 |
+
},
|
| 62 |
+
"XLM-R base": {
|
| 63 |
+
"model_id": "FacebookAI/xlm-roberta-base",
|
| 64 |
+
"sentiment_accuracy_mean": 0.788,
|
| 65 |
+
"sentiment_accuracy_std": 0.005196152422706636,
|
| 66 |
+
"sentiment_seed_scores": [
|
| 67 |
+
0.791,
|
| 68 |
+
0.782,
|
| 69 |
+
0.791
|
| 70 |
+
],
|
| 71 |
+
"sentiment_best_lr": 2e-05,
|
| 72 |
+
"wikiann_ner_f1": 0.8488652824722356,
|
| 73 |
+
"wikiann_best_lr": 2e-05,
|
| 74 |
+
"parameters": 278043648,
|
| 75 |
+
"checkpoint_mb": 1063.8882179260254,
|
| 76 |
+
"latency_ms_b1_l128": 2.1774335225423176,
|
| 77 |
+
"tokens_per_second_b16_l512": 136274.27949161586,
|
| 78 |
+
"peak_vram_mb_b16_l512": 677.99609375
|
| 79 |
+
}
|
| 80 |
+
},
|
| 81 |
+
"efficiency_protocol": {
|
| 82 |
+
"device": "NVIDIA GeForce RTX 4060",
|
| 83 |
+
"dtype": "bfloat16",
|
| 84 |
+
"mode": "eager inference",
|
| 85 |
+
"warmup": 10,
|
| 86 |
+
"iterations": 30
|
| 87 |
+
},
|
| 88 |
+
"held_out_mlm": {
|
| 89 |
+
"protocol": {
|
| 90 |
+
"validation_data": "data/processed/val",
|
| 91 |
+
"batch_size": 2,
|
| 92 |
+
"sequence_length": 512,
|
| 93 |
+
"batches": 100,
|
| 94 |
+
"mask_fraction": 0.15,
|
| 95 |
+
"seed": 2026,
|
| 96 |
+
"dtype": "bfloat16"
|
| 97 |
+
},
|
| 98 |
+
"checkpoints": {
|
| 99 |
+
"random_init": {
|
| 100 |
+
"masked_tokens": 15378,
|
| 101 |
+
"loss": 10.379354222169049,
|
| 102 |
+
"perplexity": 32188.168372746946,
|
| 103 |
+
"top1_accuracy": 6.502796202367018e-05,
|
| 104 |
+
"top5_accuracy": 0.00026011184809468074,
|
| 105 |
+
"parameters": 24865804
|
| 106 |
+
},
|
| 107 |
+
"checkpoint_999": {
|
| 108 |
+
"masked_tokens": 15378,
|
| 109 |
+
"loss": 6.6500120069940625,
|
| 110 |
+
"perplexity": 772.7936044076636,
|
| 111 |
+
"top1_accuracy": 0.1179607231109377,
|
| 112 |
+
"top5_accuracy": 0.21335674339966185,
|
| 113 |
+
"parameters": 24865804
|
| 114 |
+
},
|
| 115 |
+
"checkpoint_9999": {
|
| 116 |
+
"masked_tokens": 15378,
|
| 117 |
+
"loss": 3.1010802833695053,
|
| 118 |
+
"perplexity": 22.221944316353014,
|
| 119 |
+
"top1_accuracy": 0.4473923787228508,
|
| 120 |
+
"top5_accuracy": 0.6474183899076603,
|
| 121 |
+
"parameters": 24865804
|
| 122 |
+
},
|
| 123 |
+
"checkpoint_19999": {
|
| 124 |
+
"masked_tokens": 15378,
|
| 125 |
+
"loss": 2.6596765298653615,
|
| 126 |
+
"perplexity": 14.291665423968677,
|
| 127 |
+
"top1_accuracy": 0.5046169853036806,
|
| 128 |
+
"top5_accuracy": 0.703862660944206,
|
| 129 |
+
"parameters": 24865804
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
},
|
| 133 |
+
"tokenizer_efficiency": {
|
| 134 |
+
"documents": 151,
|
| 135 |
+
"characters": 2739705,
|
| 136 |
+
"models": {
|
| 137 |
+
"avey-b-urdu-25m/checkpoint_19999": {
|
| 138 |
+
"tokens": 654351,
|
| 139 |
+
"tokens_per_character": 0.23883994809660164,
|
| 140 |
+
"characters_per_token": 4.186904276145372
|
| 141 |
+
},
|
| 142 |
+
"ProximaAI/urnova-95m": {
|
| 143 |
+
"tokens": 667376,
|
| 144 |
+
"tokens_per_character": 0.24359410958479105,
|
| 145 |
+
"characters_per_token": 4.105189578288701
|
| 146 |
+
},
|
| 147 |
+
"HPLT/hplt_bert_base_ur": {
|
| 148 |
+
"tokens": 693627,
|
| 149 |
+
"tokens_per_character": 0.2531757981242506,
|
| 150 |
+
"characters_per_token": 3.9498246175538148
|
| 151 |
+
},
|
| 152 |
+
"FacebookAI/xlm-roberta-base": {
|
| 153 |
+
"tokens": 763456,
|
| 154 |
+
"tokens_per_character": 0.2786635787429669,
|
| 155 |
+
"characters_per_token": 3.5885565114427025
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"AveyForMaskedLM"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_avey.AveyConfig",
|
| 7 |
+
"AutoModel": "modeling_avey.AveyModel",
|
| 8 |
+
"AutoModelForMaskedLM": "modeling_avey.AveyForMaskedLM",
|
| 9 |
+
"AutoModelForSequenceClassification": "modeling_avey.AveyForSequenceClassification",
|
| 10 |
+
"AutoModelForTokenClassification": "modeling_avey.AveyForTokenClassification"
|
| 11 |
+
},
|
| 12 |
+
"chunk_size": 128,
|
| 13 |
+
"context_proportion": 0.5,
|
| 14 |
+
"d_embed": 384,
|
| 15 |
+
"dtype": "float32",
|
| 16 |
+
"eps": 1e-12,
|
| 17 |
+
"expansion_factor": 4,
|
| 18 |
+
"hidden_size": 384,
|
| 19 |
+
"k": 3,
|
| 20 |
+
"max_position_embeddings": 4294967296,
|
| 21 |
+
"model_type": "avey-b",
|
| 22 |
+
"n_layers": 12,
|
| 23 |
+
"training_sequence_length": 512,
|
| 24 |
+
"transformers_version": "5.16.1",
|
| 25 |
+
"vocab_size": 32000
|
| 26 |
+
}
|
configuration_avey.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class AveyConfig(PretrainedConfig):
|
| 5 |
+
model_type = "avey-b"
|
| 6 |
+
|
| 7 |
+
def __init__(
|
| 8 |
+
self,
|
| 9 |
+
vocab_size: int = 50304,
|
| 10 |
+
context_len: int = 512,
|
| 11 |
+
d_embed: int = 768,
|
| 12 |
+
n_layers: int = 26,
|
| 13 |
+
chunk_size: int = 128,
|
| 14 |
+
k: int = 3,
|
| 15 |
+
eps=1e-12,
|
| 16 |
+
**kwargs,
|
| 17 |
+
):
|
| 18 |
+
self.vocab_size = vocab_size
|
| 19 |
+
self.d_embed = d_embed
|
| 20 |
+
self.n_layers = n_layers
|
| 21 |
+
self.chunk_size = chunk_size
|
| 22 |
+
self.k = k
|
| 23 |
+
self.eps = eps
|
| 24 |
+
|
| 25 |
+
# for compatibility with the eval lib
|
| 26 |
+
self.max_position_embeddings = context_len
|
| 27 |
+
self.hidden_size = d_embed
|
| 28 |
+
super().__init__(**kwargs)
|
fertility_check.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"avey-b-urdu-tokenizer": 0.23883994809660164
|
| 3 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2b420e51caaf7a43267a7ca17a5532327dd96382b0d9294b8d03edeec0b26bb
|
| 3 |
+
size 99470432
|
modeling_avey.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn.functional as F
|
| 3 |
+
from torch import nn
|
| 4 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 5 |
+
from transformers import PreTrainedModel
|
| 6 |
+
from transformers.modeling_outputs import (
|
| 7 |
+
BaseModelOutput,
|
| 8 |
+
MaskedLMOutput,
|
| 9 |
+
SequenceClassifierOutput,
|
| 10 |
+
TokenClassifierOutput,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
from .configuration_avey import AveyConfig
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class StaticLayer(nn.Module):
|
| 17 |
+
def __init__(self, config: AveyConfig):
|
| 18 |
+
super().__init__()
|
| 19 |
+
self.norm = nn.RMSNorm(config.d_embed, eps=config.eps)
|
| 20 |
+
self.enricher = nn.Linear(config.d_embed, config.d_embed * 4)
|
| 21 |
+
|
| 22 |
+
proj_size = config.chunk_size
|
| 23 |
+
self.spatial_proj = nn.Parameter(torch.empty(proj_size, proj_size))
|
| 24 |
+
nn.init.xavier_normal_(self.spatial_proj)
|
| 25 |
+
|
| 26 |
+
self.fuser = nn.Linear(int(config.d_embed * 3), config.d_embed)
|
| 27 |
+
self.alpha = nn.Parameter(torch.tensor(1.0))
|
| 28 |
+
|
| 29 |
+
def forward(self, x, attention_mask=None):
|
| 30 |
+
_, T, _ = x.shape
|
| 31 |
+
res = x
|
| 32 |
+
x = self.norm(x)
|
| 33 |
+
x = self.enricher(x)
|
| 34 |
+
x = F.gelu(x)
|
| 35 |
+
if attention_mask is not None:
|
| 36 |
+
x = x * attention_mask
|
| 37 |
+
x, bypass = x.chunk(2, dim=-1)
|
| 38 |
+
|
| 39 |
+
x, gate = x.chunk(2, dim=-1)
|
| 40 |
+
x = self.spatial_proj[:T, :T] @ x
|
| 41 |
+
x = gate * x
|
| 42 |
+
|
| 43 |
+
x = torch.cat([x, bypass], dim=-1)
|
| 44 |
+
x = self.fuser(x)
|
| 45 |
+
x = x + (self.alpha * res)
|
| 46 |
+
return x if attention_mask is None else x * attention_mask
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class DynamicLayer(nn.Module):
|
| 50 |
+
def __init__(self, config: AveyConfig):
|
| 51 |
+
super().__init__()
|
| 52 |
+
self.norm = nn.RMSNorm(config.d_embed, eps=config.eps)
|
| 53 |
+
self.enricher = nn.Linear(config.d_embed, config.d_embed * 4)
|
| 54 |
+
self.fuser = nn.Linear(config.d_embed * 3, config.d_embed)
|
| 55 |
+
self.alpha = nn.Parameter(torch.tensor(1.0))
|
| 56 |
+
|
| 57 |
+
def forward(self, x, attention_mask=None):
|
| 58 |
+
_, T, _ = x.shape
|
| 59 |
+
res = x
|
| 60 |
+
x = self.norm(x)
|
| 61 |
+
x = self.enricher(x)
|
| 62 |
+
x = F.gelu(x)
|
| 63 |
+
if attention_mask is not None:
|
| 64 |
+
x = x * attention_mask
|
| 65 |
+
x, bypass = x.chunk(2, dim=-1)
|
| 66 |
+
|
| 67 |
+
x, gate = x.chunk(2, dim=-1)
|
| 68 |
+
x_norm = F.normalize(x, p=2, dim=-1)
|
| 69 |
+
sim_scores = x_norm @ x_norm.mT
|
| 70 |
+
x = F.normalize(sim_scores, p=1, dim=-1) @ x
|
| 71 |
+
x = gate * x
|
| 72 |
+
|
| 73 |
+
x = torch.cat([x, bypass], dim=-1)
|
| 74 |
+
x = self.fuser(x)
|
| 75 |
+
x = x + (self.alpha * res)
|
| 76 |
+
return x if attention_mask is None else x * attention_mask
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class Ranker(nn.Module):
|
| 80 |
+
def __init__(self, config):
|
| 81 |
+
super().__init__()
|
| 82 |
+
self.chunk_size = config.chunk_size
|
| 83 |
+
self.k = config.k + 1
|
| 84 |
+
self.extended_len = self.k * config.chunk_size
|
| 85 |
+
self.eps = config.eps
|
| 86 |
+
self.down_proj = nn.Parameter(torch.empty(self.chunk_size, self.extended_len))
|
| 87 |
+
nn.init.xavier_normal_(self.down_proj)
|
| 88 |
+
|
| 89 |
+
def preprocess(self, x):
|
| 90 |
+
B, T, E = x.shape
|
| 91 |
+
cs, L = self.chunk_size, self.extended_len
|
| 92 |
+
|
| 93 |
+
padded = False
|
| 94 |
+
orig_T = T
|
| 95 |
+
if T % cs != 0:
|
| 96 |
+
pad_len = cs - (T % cs)
|
| 97 |
+
pad = torch.zeros(B, pad_len, E, device=x.device, dtype=x.dtype)
|
| 98 |
+
x = torch.cat([x, pad], dim=1)
|
| 99 |
+
T += pad_len
|
| 100 |
+
padded = True
|
| 101 |
+
|
| 102 |
+
N = T // cs
|
| 103 |
+
x_chunks = x.view(B, N, cs, E)
|
| 104 |
+
|
| 105 |
+
extended = []
|
| 106 |
+
for i in range(0, N):
|
| 107 |
+
cur = x_chunks[:, i]
|
| 108 |
+
others = x_chunks[:, :i]
|
| 109 |
+
cat = self._extend(others, cur) # (B, ≤k⋅cs+cs, E)
|
| 110 |
+
|
| 111 |
+
# pad or truncate to length L
|
| 112 |
+
cur_len = cat.size(1)
|
| 113 |
+
if cur_len < L:
|
| 114 |
+
pad2 = torch.zeros(B, L - cur_len, E, device=x.device, dtype=x.dtype)
|
| 115 |
+
cat = torch.cat([pad2, cat], dim=1)
|
| 116 |
+
else:
|
| 117 |
+
cat = cat[:, -L:]
|
| 118 |
+
|
| 119 |
+
extended.append(cat)
|
| 120 |
+
|
| 121 |
+
ext = torch.stack(extended, dim=1) # (B, N, L, E)
|
| 122 |
+
ext = (self.down_proj @ ext) + x_chunks
|
| 123 |
+
h = ext.view(B * N, cs, E)
|
| 124 |
+
|
| 125 |
+
state = {"B": B, "N": N, "orig_T": orig_T, "padded": padded}
|
| 126 |
+
return h, state
|
| 127 |
+
|
| 128 |
+
def contract(self, h, st):
|
| 129 |
+
B, cs = st["B"], self.chunk_size
|
| 130 |
+
N = st["N"]
|
| 131 |
+
padded = st["padded"]
|
| 132 |
+
orig_T = st["orig_T"]
|
| 133 |
+
|
| 134 |
+
E = h.size(-1)
|
| 135 |
+
final_chunks = h.view(B, N, cs, E)
|
| 136 |
+
|
| 137 |
+
out = final_chunks.reshape(B, N * cs, E)
|
| 138 |
+
|
| 139 |
+
if padded:
|
| 140 |
+
out = out[:, :orig_T, :]
|
| 141 |
+
|
| 142 |
+
return out
|
| 143 |
+
|
| 144 |
+
def _extend(self, other_chunks, cur_chunk):
|
| 145 |
+
B, cs, E = cur_chunk.shape
|
| 146 |
+
if other_chunks is None or other_chunks.size(1) == 0:
|
| 147 |
+
return cur_chunk
|
| 148 |
+
|
| 149 |
+
i = other_chunks.size(1)
|
| 150 |
+
num_sel = min(i, self.k - 1)
|
| 151 |
+
if num_sel <= 0:
|
| 152 |
+
return cur_chunk
|
| 153 |
+
|
| 154 |
+
# l2 normalize
|
| 155 |
+
cn = other_chunks / (other_chunks.norm(dim=-1, keepdim=True) + self.eps)
|
| 156 |
+
cm = cur_chunk / (cur_chunk.norm(dim=-1, keepdim=True) + self.eps)
|
| 157 |
+
|
| 158 |
+
# cosine sim
|
| 159 |
+
cm_e = cm.unsqueeze(1) # (B, 1, cs, E)
|
| 160 |
+
ct = cn.transpose(-1, -2) # (B, i, E, cs)
|
| 161 |
+
sims = torch.matmul(cm_e, ct) # (B, i, cs, cs)
|
| 162 |
+
mx, _ = sims.max(dim=-1) # (B, i, cs)
|
| 163 |
+
scores = mx.sum(dim=-1) # (B, i)
|
| 164 |
+
|
| 165 |
+
# topk
|
| 166 |
+
topk_vals, topk_idx = scores.topk(num_sel, dim=1)
|
| 167 |
+
|
| 168 |
+
# normalize weights
|
| 169 |
+
v_min = topk_vals.min(dim=-1, keepdim=True)[0] # (B, 1)
|
| 170 |
+
w = topk_vals / (v_min + self.eps) # (B, num_sel)
|
| 171 |
+
w = w.unsqueeze(-1).unsqueeze(-1) # (B, num_sel, 1, 1)
|
| 172 |
+
|
| 173 |
+
# gather
|
| 174 |
+
idx_e = topk_idx.unsqueeze(-1).unsqueeze(-1).expand(-1, -1, cs, E)
|
| 175 |
+
sel = other_chunks.gather(1, idx_e) # (B, num_sel, cs, E)
|
| 176 |
+
|
| 177 |
+
# weight & flatten
|
| 178 |
+
wt = (sel * w).reshape(B, num_sel * cs, E)
|
| 179 |
+
|
| 180 |
+
return torch.cat([wt, cur_chunk], dim=1) # (B, ≤k⋅cs+cs, E)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class AveyPreTrainedModel(PreTrainedModel):
|
| 184 |
+
config_class = AveyConfig
|
| 185 |
+
|
| 186 |
+
def _init_weights(self, module):
|
| 187 |
+
if isinstance(module, nn.Linear):
|
| 188 |
+
nn.init.xavier_normal_(module.weight)
|
| 189 |
+
if module.bias is not None:
|
| 190 |
+
module.bias.data.zero_()
|
| 191 |
+
elif isinstance(module, nn.Embedding):
|
| 192 |
+
nn.init.xavier_normal_(module.weight)
|
| 193 |
+
if module.padding_idx is not None:
|
| 194 |
+
module.weight.data[module.padding_idx].zero_()
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
class AveyModel(AveyPreTrainedModel):
|
| 198 |
+
def __init__(self, config):
|
| 199 |
+
super().__init__(config)
|
| 200 |
+
self.chunk_size = config.chunk_size
|
| 201 |
+
self.embed = nn.Embedding(config.vocab_size, config.d_embed)
|
| 202 |
+
self.layers = nn.ModuleList(
|
| 203 |
+
[
|
| 204 |
+
DynamicLayer(config) if (i + 1) % 2 == 0 else StaticLayer(config)
|
| 205 |
+
for i in range(config.n_layers)
|
| 206 |
+
]
|
| 207 |
+
)
|
| 208 |
+
self.ranker = Ranker(config)
|
| 209 |
+
self.post_init()
|
| 210 |
+
|
| 211 |
+
def _get_hidden(self, input_ids, attention_mask=None):
|
| 212 |
+
x = self.embed(input_ids)
|
| 213 |
+
layer_mask = None
|
| 214 |
+
if attention_mask is not None:
|
| 215 |
+
attention_mask = attention_mask.to(device=x.device, dtype=x.dtype)
|
| 216 |
+
x = x * attention_mask.unsqueeze(-1)
|
| 217 |
+
|
| 218 |
+
pad_len = (-attention_mask.size(1)) % self.chunk_size
|
| 219 |
+
if pad_len:
|
| 220 |
+
attention_mask = F.pad(attention_mask, (0, pad_len))
|
| 221 |
+
layer_mask = attention_mask.reshape(-1, self.chunk_size, 1)
|
| 222 |
+
|
| 223 |
+
x, state = self.ranker.preprocess(x)
|
| 224 |
+
for layer in self.layers:
|
| 225 |
+
x = layer(x, attention_mask=layer_mask)
|
| 226 |
+
x = self.ranker.contract(x, state)
|
| 227 |
+
return x
|
| 228 |
+
|
| 229 |
+
def forward(self, input_ids, attention_mask=None, **kwargs):
|
| 230 |
+
x = self._get_hidden(input_ids, attention_mask=attention_mask)
|
| 231 |
+
return BaseModelOutput(last_hidden_state=x)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class AveyForMaskedLM(AveyModel):
|
| 235 |
+
def __init__(self, config):
|
| 236 |
+
super().__init__(config)
|
| 237 |
+
self.post_init()
|
| 238 |
+
|
| 239 |
+
def forward(self, input_ids, attention_mask=None, labels=None, **kwargs):
|
| 240 |
+
x = self._get_hidden(input_ids, attention_mask=attention_mask)
|
| 241 |
+
logits = F.linear(x, self.embed.weight)
|
| 242 |
+
|
| 243 |
+
loss = None
|
| 244 |
+
if labels is not None:
|
| 245 |
+
loss = F.cross_entropy(
|
| 246 |
+
logits.view(-1, logits.size(-1)), labels.view(-1), ignore_index=-100
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
return MaskedLMOutput(logits=logits, loss=loss)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class AveyForSequenceClassification(AveyModel):
|
| 253 |
+
def __init__(self, config):
|
| 254 |
+
super().__init__(config)
|
| 255 |
+
self.num_labels = config.num_labels
|
| 256 |
+
self.dense = nn.Sequential(
|
| 257 |
+
nn.Linear(self.config.d_embed, self.config.d_embed * 2),
|
| 258 |
+
nn.GELU(),
|
| 259 |
+
nn.Linear(self.config.d_embed * 2, self.config.d_embed * 2),
|
| 260 |
+
nn.GELU(),
|
| 261 |
+
nn.Linear(self.config.d_embed * 2, self.config.d_embed),
|
| 262 |
+
)
|
| 263 |
+
self.classifier = nn.Linear(config.d_embed, config.num_labels)
|
| 264 |
+
self.post_init()
|
| 265 |
+
|
| 266 |
+
def forward(self, input_ids, attention_mask=None, labels=None, **kwargs):
|
| 267 |
+
x = self._get_hidden(input_ids, attention_mask=attention_mask)
|
| 268 |
+
if attention_mask is None:
|
| 269 |
+
x = x.mean(dim=1)
|
| 270 |
+
else:
|
| 271 |
+
mask = attention_mask.to(dtype=x.dtype).unsqueeze(-1)
|
| 272 |
+
x = (x * mask).sum(dim=1) / mask.sum(dim=1).clamp_min(1.0)
|
| 273 |
+
x = self.dense(x)
|
| 274 |
+
logits = self.classifier(x)
|
| 275 |
+
|
| 276 |
+
loss = None
|
| 277 |
+
if labels is not None:
|
| 278 |
+
if self.num_labels == 1:
|
| 279 |
+
loss = MSELoss()(logits.squeeze(), labels.squeeze())
|
| 280 |
+
elif labels.dtype in (torch.long, torch.int):
|
| 281 |
+
loss = CrossEntropyLoss()(
|
| 282 |
+
logits.view(-1, self.num_labels), labels.view(-1)
|
| 283 |
+
)
|
| 284 |
+
else:
|
| 285 |
+
loss = BCEWithLogitsLoss()(logits, labels)
|
| 286 |
+
|
| 287 |
+
return SequenceClassifierOutput(logits=logits, loss=loss)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class AveyForTokenClassification(AveyModel):
|
| 291 |
+
def __init__(self, config):
|
| 292 |
+
super().__init__(config)
|
| 293 |
+
self.num_labels = config.num_labels
|
| 294 |
+
self.dense = nn.Sequential(nn.Linear(config.d_embed, config.d_embed), nn.Tanh())
|
| 295 |
+
self.classifier = nn.Linear(config.d_embed, config.num_labels)
|
| 296 |
+
self.post_init()
|
| 297 |
+
|
| 298 |
+
def forward(self, input_ids, attention_mask=None, labels=None, **kwargs):
|
| 299 |
+
x = self._get_hidden(input_ids, attention_mask=attention_mask)
|
| 300 |
+
x = self.dense(x)
|
| 301 |
+
logits = self.classifier(x)
|
| 302 |
+
|
| 303 |
+
loss = None
|
| 304 |
+
if labels is not None:
|
| 305 |
+
loss = CrossEntropyLoss()(logits.view(-1, self.num_labels), labels.view(-1))
|
| 306 |
+
|
| 307 |
+
return TokenClassifierOutput(logits=logits, loss=loss)
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"mask_token": "[MASK]",
|
| 5 |
+
"model_max_length": 512,
|
| 6 |
+
"pad_token": "[PAD]",
|
| 7 |
+
"sep_token": "[SEP]",
|
| 8 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 9 |
+
"unk_token": "[UNK]",
|
| 10 |
+
"clean_up_tokenization_spaces": false
|
| 11 |
+
}
|