sarfchat 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. sarfchat-2.0.0/.github/workflows/ci.yml +37 -0
  2. sarfchat-2.0.0/.github/workflows/mirror-codeberg.yml +27 -0
  3. sarfchat-2.0.0/.github/workflows/publish.yml +32 -0
  4. sarfchat-2.0.0/.gitignore +23 -0
  5. sarfchat-2.0.0/CITATION.cff +25 -0
  6. sarfchat-2.0.0/LICENSE +176 -0
  7. sarfchat-2.0.0/NOTICE +19 -0
  8. sarfchat-2.0.0/PKG-INFO +115 -0
  9. sarfchat-2.0.0/README.md +78 -0
  10. sarfchat-2.0.0/WEIGHTS_AND_REPRODUCIBILITY.md +115 -0
  11. sarfchat-2.0.0/data-manifest.tsv +38 -0
  12. sarfchat-2.0.0/fetch-data.sh +102 -0
  13. sarfchat-2.0.0/paper/figures/fig1_subword_tax_and_isoflop_scaling.pdf +0 -0
  14. sarfchat-2.0.0/paper/figures/fig1_subword_tax_and_isoflop_scaling.png +0 -0
  15. sarfchat-2.0.0/paper/figures/fig2_v2_5b_convergence_and_systems.pdf +0 -0
  16. sarfchat-2.0.0/paper/figures/fig2_v2_5b_convergence_and_systems.png +0 -0
  17. sarfchat-2.0.0/paper/figures/fig3_localized_oov_and_tarkib_guard.pdf +0 -0
  18. sarfchat-2.0.0/paper/figures/fig3_localized_oov_and_tarkib_guard.png +0 -0
  19. sarfchat-2.0.0/paper/figures/fig4_tayf_sarfchat_neurosymbolic_rag.pdf +0 -0
  20. sarfchat-2.0.0/paper/figures/fig4_tayf_sarfchat_neurosymbolic_rag.png +0 -0
  21. sarfchat-2.0.0/paper/main.pdf +0 -0
  22. sarfchat-2.0.0/paper/main.tex +539 -0
  23. sarfchat-2.0.0/paper/references.bib +373 -0
  24. sarfchat-2.0.0/pyproject.toml +68 -0
  25. sarfchat-2.0.0/results/CAMPAIGN_COMPLETED.json +16 -0
  26. sarfchat-2.0.0/results/oov_and_guard_breakdown.svg +42 -0
  27. sarfchat-2.0.0/results/paper_fortification_metrics.json +1075 -0
  28. sarfchat-2.0.0/results/permuted_priors_control.json +4925 -0
  29. sarfchat-2.0.0/results/runs/bpe_baseline_d10.json +451 -0
  30. sarfchat-2.0.0/results/runs/bpe_baseline_d12.json +462 -0
  31. sarfchat-2.0.0/results/runs/bpe_baseline_d6.json +429 -0
  32. sarfchat-2.0.0/results/runs/bpe_baseline_d8.json +440 -0
  33. sarfchat-2.0.0/results/runs/bpe_grassmann_ve_d10.json +451 -0
  34. sarfchat-2.0.0/results/runs/bpe_grassmann_ve_d12.json +462 -0
  35. sarfchat-2.0.0/results/runs/bpe_grassmann_ve_d6.json +429 -0
  36. sarfchat-2.0.0/results/runs/bpe_grassmann_ve_d8.json +440 -0
  37. sarfchat-2.0.0/results/runs/sarfchat_full_d10.json +451 -0
  38. sarfchat-2.0.0/results/runs/sarfchat_full_d12.json +462 -0
  39. sarfchat-2.0.0/results/runs/sarfchat_full_d6.json +440 -0
  40. sarfchat-2.0.0/results/runs/sarfchat_full_d8.json +440 -0
  41. sarfchat-2.0.0/results/scaling_campaign.json +5563 -0
  42. sarfchat-2.0.0/results/scaling_isoflop_bpb.svg +70 -0
  43. sarfchat-2.0.0/results/scaling_params_and_speedrun.svg +100 -0
  44. sarfchat-2.0.0/results/v2_flagship_report.json +16176 -0
  45. sarfchat-2.0.0/results/v2_training_curve.svg +240 -0
  46. sarfchat-2.0.0/scripts/build_corpus_and_priors.py +465 -0
  47. sarfchat-2.0.0/scripts/colab_v2_driver.py +209 -0
  48. sarfchat-2.0.0/scripts/localized_oov_eval.py +311 -0
  49. sarfchat-2.0.0/scripts/make_paper_figures.py +629 -0
  50. sarfchat-2.0.0/scripts/prepare_v2_assets.py +988 -0
  51. sarfchat-2.0.0/scripts/run_campaign.py +284 -0
  52. sarfchat-2.0.0/scripts/run_local_paper_fortification.py +1061 -0
  53. sarfchat-2.0.0/scripts/run_permuted_priors_control.py +324 -0
  54. sarfchat-2.0.0/scripts/stream_corpus_v2.py +758 -0
  55. sarfchat-2.0.0/scripts/train_v2_flagship.py +978 -0
  56. sarfchat-2.0.0/src/sarfchat/__init__.py +4 -0
  57. sarfchat-2.0.0/src/sarfchat/chat_cli.py +193 -0
  58. sarfchat-2.0.0/src/sarfchat/cli_train.py +528 -0
  59. sarfchat-2.0.0/src/sarfchat/common.py +95 -0
  60. sarfchat-2.0.0/src/sarfchat/dataloader.py +513 -0
  61. sarfchat-2.0.0/src/sarfchat/loss_eval.py +523 -0
  62. sarfchat-2.0.0/src/sarfchat/model.py +1653 -0
  63. sarfchat-2.0.0/src/sarfchat/morph_codec.py +1542 -0
  64. sarfchat-2.0.0/src/sarfchat/optim.py +153 -0
  65. sarfchat-2.0.0/src/sarfchat/plots.py +296 -0
  66. sarfchat-2.0.0/src/sarfchat/priors.py +471 -0
  67. sarfchat-2.0.0/src/sarfchat/static/app.js +414 -0
  68. sarfchat-2.0.0/src/sarfchat/static/index.html +203 -0
  69. sarfchat-2.0.0/src/sarfchat/static/styles.css +443 -0
  70. sarfchat-2.0.0/src/sarfchat/web_arena.py +560 -0
  71. sarfchat-2.0.0/tests/test_model_and_guard.py +131 -0
  72. sarfchat-2.0.0/tests/test_morph_codec_lossless.py +88 -0
  73. sarfchat-2.0.0/tests/test_probability_and_bpb.py +175 -0
  74. sarfchat-2.0.0/tests/test_v2_architecture_and_chat.py +237 -0
  75. sarfchat-2.0.0/tests/test_web_arena.py +43 -0
@@ -0,0 +1,37 @@
1
+ name: CI (sarfchat)
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ env:
10
+ TARKIB_OPENITI_ONLY: "1"
11
+ CUDA_VISIBLE_DEVICES: ""
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v5
22
+
23
+ - name: Set up Python 3.12
24
+ run: uv python install 3.12
25
+
26
+ - name: Install CPU PyTorch and package dependencies
27
+ run: |
28
+ uv venv --python 3.12 .ci-venv
29
+ uv pip install --python .ci-venv/bin/python --index-url https://download.pytorch.org/whl/cpu torch
30
+ uv pip install --python .ci-venv/bin/python --no-deps -e .
31
+ uv pip install --python .ci-venv/bin/python numpy scipy scikit-learn tokenizers safetensors huggingface-hub pyarrow pytest
32
+
33
+ - name: Run offline CPU unit test suite
34
+ run: .ci-venv/bin/pytest -q
35
+
36
+ - name: Build wheel and sdist
37
+ run: uv build
@@ -0,0 +1,27 @@
1
+ name: Sovereign Mirror to Codeberg (sarfchat)
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ tags: ["v*"]
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ mirror:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout full git history
14
+ uses: actions/checkout@v4
15
+ with:
16
+ fetch-depth: 0
17
+
18
+ - name: Push mirror to Codeberg (maqayis/sarfchat)
19
+ env:
20
+ CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
21
+ run: |
22
+ if [ -z "$CODEBERG_TOKEN" ]; then
23
+ echo "CODEBERG_TOKEN secret is not set; skipping mirror push."
24
+ exit 0
25
+ fi
26
+ git remote add codeberg "https://maqayis:${CODEBERG_TOKEN}@codeberg.org/maqayis/sarfchat.git" || true
27
+ git push --mirror codeberg
@@ -0,0 +1,32 @@
1
+ name: Publish to PyPI (sarfchat)
2
+
3
+ on:
4
+ release:
5
+ types: ["published"]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+
12
+ env:
13
+ TARKIB_OPENITI_ONLY: "1"
14
+
15
+ jobs:
16
+ publish:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - name: Checkout repository
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Install uv
23
+ uses: astral-sh/setup-uv@v5
24
+
25
+ - name: Set up Python 3.12
26
+ run: uv python install 3.12
27
+
28
+ - name: Build wheel and sdist
29
+ run: uv build
30
+
31
+ - name: Publish package distributions to PyPI via OIDC Trusted Publisher
32
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,23 @@
1
+ # Byte-compiled / caches
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .mypy_cache/
8
+
9
+ # Virtual environments & build staging (`dist/` release wheels/sdists are tracked)
10
+ .venv/
11
+ venv/
12
+ build/
13
+ *.egg-info/
14
+
15
+ # Hydrated checkpoints & corpus artifacts (fetched via ./fetch-data.sh & verified by data-manifest.tsv)
16
+ checkpoints/
17
+ data/
18
+ !data-manifest.tsv
19
+
20
+ # Local environment files
21
+ .env
22
+ .env.*
23
+ !.env.example
@@ -0,0 +1,25 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use SarfChat-v2 in your research or software, please cite it using the metadata below."
3
+ title: "SarfChat-v2: Certified Byte-Lossless Root×Pattern Tokenization, Grassmannian Value Routing, and Iso-FLOP Bits-Per-Byte Scaling Laws for Arabic Foundation Models"
4
+ version: "2.0.0"
5
+ date-released: "2026-11-07"
6
+ license: "Apache-2.0"
7
+ url: "https://maqayis.org"
8
+ repository-code: "https://github.com/maqayis/sarfchat"
9
+ authors:
10
+ - family-names: "Abdo"
11
+ given-names: "Salah"
12
+ email: "Salah.Abdo.Tech@gmail.com"
13
+ abstract: >-
14
+ Algebraic Semitic Root×Pattern Transformer (d16, 261.75M total / 221.79M active matmul parameters)
15
+ trained from scratch on 5.10B tokens (33.63 GB UTF-8) to val_bpb = 0.7353 (0.6976 on unseen OOV-root
16
+ passages; 1.8861 localized OOV-word bpb), paired with certified 100%-byte-lossless Sarf-BPE,
17
+ Grassmannian multi-asl fiber value routing, a 19-run Iso-FLOP scaling and causal permutation harness,
18
+ and a 23.8-microsecond GPU Tarkib morpho-phonotactic shield achieving 100.0% legality (40/40 and 200/200).
19
+ keywords:
20
+ - "Arabic foundation models"
21
+ - "root-pattern morphology"
22
+ - "Grassmannian manifold"
23
+ - "bits-per-byte scaling laws"
24
+ - "Maqayis"
25
+ - "sarfchat"
sarfchat-2.0.0/LICENSE ADDED
@@ -0,0 +1,176 @@
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
sarfchat-2.0.0/NOTICE ADDED
@@ -0,0 +1,19 @@
1
+ SarfChat-v2 (صرف-شات) v2.0.0 — Maqāyīs (مَقاييس) Open-Source Ecosystem
2
+ Copyright 2026 Salah Abdo and successor entity
3
+
4
+ Software, Model Architecture, Codec, & Evaluation Harness (`src/`, `scripts/`, `tests/`):
5
+ Licensed under the Apache License, Version 2.0 (Apache-2.0).
6
+ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Research Paper, Figures, & Empirical Scaling-Law / Fortification Ledgers (`paper/`, `results/`):
9
+ Licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
10
+ https://creativecommons.org/licenses/by/4.0/
11
+
12
+ Clean-Room Provenance & Architectural Acknowledgements:
13
+ - Morphological, phonotactic, and Grassmannian multi-aṣl priors (`sarfchat_priors_v1.npz` &
14
+ `sarfchat_priors_v2.npz`) are compiled cleanly via `tarkib>=2.0.0` (`TARKIB_OPENITI_ONLY=1`)
15
+ strictly from pre-modern public-domain classical Arabic lexicons (170–1205 AH via OpenITI).
16
+ - Baseline ResFormer / `MuonAdamW` trunk conventions draw architectural inspiration from
17
+ Andrej Karpathy's public `nanochat` reference (MIT License), extended with certified
18
+ byte-lossless `Ṣarf-BPE`, `GrassmannFiberValueRouter`, `TarkibSubwordInjector`, single-pass
19
+ `_FusedChunkedSoftcapLinearCE`, and the `<24 μs` GPU `Tarkīb` morpho-phonotactic shield.
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.5
2
+ Name: sarfchat
3
+ Version: 2.0.0
4
+ Summary: SarfChat-v2 (صرف-شات): Algebraic Semitic Root×Pattern Transformer, Certified Byte-Lossless Sarf-BPE, & Iso-FLOP Scaling-Law Harness (Maqayis)
5
+ Project-URL: Homepage, https://maqayis.org
6
+ Project-URL: Repository, https://github.com/maqayis/sarfchat
7
+ Project-URL: Mirror, https://codeberg.org/maqayis/sarfchat
8
+ Author-email: Salah Abdo <Salah.Abdo.Tech@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: arabic,grassmannian,maqayis,morphology,sarfchat,scaling-laws,transformer
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Natural Language :: Arabic
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: huggingface-hub>=0.26.0
24
+ Requires-Dist: numpy>=1.26.0
25
+ Requires-Dist: pyarrow>=15.0.0
26
+ Requires-Dist: safetensors>=0.4.5
27
+ Requires-Dist: scikit-learn>=1.4.0
28
+ Requires-Dist: scipy>=1.12.0
29
+ Requires-Dist: tarkib>=2.0.0
30
+ Requires-Dist: tokenizers>=0.20.0
31
+ Requires-Dist: torch>=2.4.0
32
+ Provides-Extra: data
33
+ Requires-Dist: datasets>=3.0.0; extra == 'data'
34
+ Provides-Extra: rag
35
+ Requires-Dist: tayf>=1.0.0; extra == 'rag'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # SarfChat-v2 (`صرف-شات`) v2.0.0 — المحوِّل الصرفي–الغراسماني التأسيسي وقوانين التوسّع التوليدي
39
+
40
+ <div align="center">
41
+
42
+ **Algebraic Semitic Root×Pattern Foundation Transformer (`d16`, `261.75M` Params, `5.10B` Tokens), Certified `100%`-Byte-Lossless `Ṣarf-BPE`, `Grassmann-VE` Routing, & `23.8 μs` GPU `Tarkīb` Shield**
43
+ Part of the **Maqāyīs (`مَقاييس`)** Open-Source Ecosystem · [maqayis.org](https://maqayis.org) · [github.com/maqayis/sarfchat](https://github.com/maqayis/sarfchat) · [codeberg.org/maqayis/sarfchat](https://codeberg.org/maqayis/sarfchat)
44
+
45
+ [![License: Apache-2.0](https://img.shields.io/badge/Code-Apache--2.0-blue.svg)](LICENSE)
46
+ [![Paper & Results: CC BY 4.0](https://img.shields.io/badge/Paper_%26_Results-CC_BY_4.0-246B45.svg)](NOTICE)
47
+ [![Python 3.11+](https://img.shields.io/badge/Python-3.11%2B-3776AB.svg)](pyproject.toml)
48
+
49
+ </div>
50
+
51
+ ---
52
+
53
+ ## نظرة عامّة | Overview
54
+
55
+ **`SarfChat-v2` (`صرف-شات v2.0.0`)** هو المحوِّل التوليدي التأسيسي ومختبر قوانين التوسّع متساوية الحوسبة (`Iso-FLOP Scaling Laws`) في منظومة **مَقاييس (`Maqāyīs`)** من تأليف وتطوير **صلاح عبده (`Salah Abdo`)**. بدلاً من الاكتفاء بترقيع النماذج الأجنبية من الخارج أو استنزاف ميزانية المعلمات في جداول التقطيع الإحصائي الصمّاء (`Byte-BPE`)، يدمج `SarfChat-v2` جبر الجذر والوزن الريماني وألياف غراسمان المتعدّدة الأصول (`Gr(k_R, 256)`) والسمات النطقية لسيبويه في صميم طبقات المحوِّل ذاته.
56
+
57
+ **`SarfChat-v2` (`v2.0.0`)** replaces monolithic subword memorization tables with **asymmetric morphological-Grassmannian inductive biases**:
58
+ 1. **Certified `100.0%`-Byte-Lossless `Ṣarf-BPE` & `FactoredSarfDAGHead` (`Exp S1`):** Folds `65.67%` of running Arabic words (`36,186 / 55,103`) and `100.0%` (`534 / 534`) of unseen OOV-root words into a single algebraic frame `(p, C1, C2, C3, w, e)`, eliminating OOV radical fracture (`2.41 -> 1.00` steps/word) and saving `1.22×` quadratic attention FLOPs while guaranteeing `100.000%` UTF-8 byte round-trip identity.
59
+ 2. **Dynamic `Grassmann-VE` Routing (`GrassmannFiberValueRouter`, `Exp S2–S3`):** Projects hidden states onto Ibn Fāris's orthonormal multi-*aṣl* sense bundles `Gr(k_R, 256)` across `L/2` alternating layers, compressing deep value tables by **`-93.6%`** (`75.50M -> 4.83M` at `d12`; `134.22M -> 9.54M` at `d16`).
60
+ 3. **19-Run Iso-FLOP Scaling & Causal Permutation Campaign (`Exp S2–S3`):** Breaks the multi-epoch flat-BPE memorization wall (`1.0962 -> 0.9716 bpb`, **`-0.1246 bpb`** at `d12`) and causally separates low-rank value regularization on seen words (`token_perm` / `root_perm` / `true_tarkib` within `±0.003 bpb` overall) from authentic sub-root zero-shot generalization on unseen OOV-root target words (**`2.6677 bpb`** vs `2.7009` `token_perm`, `2.7007` `root_perm`, and `2.8620` flat BPE; paired `t = -5.94, p = 2.83×10⁻⁹` across `97` roots).
61
+ 4. **Asymmetric Flagship `SarfChat-v2` (`d16`, `261.75M` Params, `5.10B` Tokens, `Exp S4–S5`):** Pairs `TarkibSubwordInjector` (`23,253 / 32,768` root-grounded subwords = `70.96%`, `29.49%` interface share vs `64.52%` flat equivalent) with single-pass `_FusedChunkedSoftcapLinearCE` (`8.59 GB -> 0.54 GB` logit VRAM, **`-93.7%`**, `105.0k tok/s`, **`58.3% MFU`**) and paragraph-level OOV surgical isolation (`1.4% -> 57.7%` long-book retention = **`41.2×`**, `0.0%` root leakage).
62
+ 5. **`23.8 μs` GPU `Tarkīb` Morpho-Phonotactic Shield & `Tayf` Neuro-Symbolic Prism (`Exp S6–S7`):** Lifts morpho-phonotactic & ontological legality to **`100.0%`** (`40/40` core suite: `97.5% -> 100.0%`; `200/200` extended suite: `98.0% / 96.5% -> 100.0%`) in `23.82 μs` per step, and lowers grounded answer entropy from `1.238 -> 0.673 bpb` (`95.0%` homonym trap survival) when paired with Zero-LLM [`maqayis/tayf`](https://github.com/maqayis/tayf).
63
+
64
+ ---
65
+
66
+ ## النتائج المرجعية | Headline `SarfChat-v2` Metrics
67
+
68
+ | Metric / Stage | Specification / Split | Value |
69
+ | :--- | :--- | :--- |
70
+ | **Architecture (`sarfchat_v2`)** | `d16` (`L=16, d=1024, n_q=16, n_kv=8, T=2048, V=32,768`) | **`261,751,467`** total / **`221,788,952`** active matmul |
71
+ | **Interface Parameter Tax** | `SarfChat-v2` (`77.20M`) vs Flat Equivalent (`335.54M`) | **`29.49%`** vs `64.52%` (`-258.3M` params saved) |
72
+ | **Pretraining Scale (Stages 1 + 2)** | `WSD Plateau` (`4.40B`) + `WSD Cooldown` (`0.70B`) | **`5,095,292,928` tokens** (**`33.63 GB`** UTF-8, `8.83e18` FLOPs) |
73
+ | **Overall Validation `val_bpb`** | Held-out multi-register `val_v2` (`0.8157` plateau -> cooldown) | **`0.7353 bpb`** (`0.73529`, `-0.0804` cooldown drop) |
74
+ | **Register Breakdown (`val_bpb`)** | `msa_edu` / `msa_wiki_books` / `classical_turath` | **`0.7139`** / **`0.7321`** / **`0.7598 bpb`** |
75
+ | **Zero-Shot Unseen OOV-Root `bpb`** | `511` OOV-root docs (`100` strictly held-out roots, `0%` leakage) | **`0.6976 bpb`** (`0.69757` doc) · **`1.8861 bpb`** (`643` OOV words) |
76
+ | **Stage 3 Arabic Chat SFT** | `46,858` train / `600` val multi-turn dialogues (`342` steps) | `sft_val_loss`: `4.0122 ->` **`2.4743`** (`PPL = 11.87`) |
77
+ | **GPU `Tarkīb` Guard (`23.82 μs`)** | `40`-pair core suite (`base`) · `200`-pair fortification (`base` / `sft`) | `97.5% ->` **`100.0%`** (`40/40`) · `98.0% / 96.5% ->` **`100.0%`** (`200/200`) |
78
+ | **Neuro-Symbolic `Tayf + SarfChat-v2`** | `20`-query adversarial homonym-trap grounded QA (`Exp S7-B`) | `1.238 ->` **`0.673 bpb`** (`-45.7%`) · **`95.0%`** (`19/20`) trap survival |
79
+
80
+ > **Book `v2.0` Sync Note:** *The Geometry of the Arabic Tongue* (`Book v2.0`, [`maqayis/tarkib`](https://github.com/maqayis/tarkib)) Ch. 21 reports the foundational `SarfChat-v1` `d12` Iso-FLOP campaign and early `d16` specification, while Part X (Ch. 22–23) and this repository (`v2.0.0`) present the completed `5.10B`-token 3-stage `d16` WSD cooldown + Chat SFT campaign (`val_bpb = 0.7353`), `19`-run causal permutation matrix, and `200`-pair GPU guard audit.
81
+
82
+ ---
83
+
84
+ ## التثبيت والتشغيل السريع | Installation & Quickstart
85
+
86
+ ```bash
87
+ pip install sarfchat
88
+ ```
89
+
90
+ ### 1. Offline CPU Unit Tests (`<200 MB` RAM, Zero Downloads Required)
91
+ ```bash
92
+ pytest -q
93
+ ```
94
+
95
+ ### 2. Hydrate Checkpoints & Tokenizers (SHA-256 Verified via `data-manifest.tsv`)
96
+ ```bash
97
+ ./fetch-data.sh data # corpus splits, bpe16k/bpe32k tokenizers, and Tarkīb priors (~499 MB)
98
+ ./fetch-data.sh runs # all 8 safetensors checkpoints incl. sarfchat_v2_d16_base & _sft (~2.96 GB)
99
+ ```
100
+
101
+ ### 3. Launch Interactive RTL Web Arena or Terminal Chat
102
+ ```bash
103
+ sarfchat-arena --host 127.0.0.1 --port 8787
104
+ sarfchat-chat --checkpoint checkpoints/sarfchat_v2_d16_sft
105
+ ```
106
+
107
+ See [`WEIGHTS_AND_REPRODUCIBILITY.md`](WEIGHTS_AND_REPRODUCIBILITY.md) for complete `SHA-256` checkpoint manifests, model cards, and exact reproduction commands, and [`paper/main.pdf`](paper/main.pdf) (`paper/main.tex`) for the full Arabic monograph study.
108
+
109
+ ---
110
+
111
+ ## الترخيص وحقوق الملكية | License & Attribution
112
+
113
+ - **Software & Source Code (`src/`, `scripts/`, `tests/`):** [Apache License 2.0](LICENSE)
114
+ - **Research Paper, Figures, & Empirical Result Ledgers (`paper/`, `results/`):** [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
115
+ - **Author:** Salah Abdo (`صلاح عبده`) `<Salah.Abdo.Tech@gmail.com>` · `Copyright 2026 Salah Abdo and successor entity` · [`NOTICE`](NOTICE) · [`CITATION.cff`](CITATION.cff)
@@ -0,0 +1,78 @@
1
+ # SarfChat-v2 (`صرف-شات`) v2.0.0 — المحوِّل الصرفي–الغراسماني التأسيسي وقوانين التوسّع التوليدي
2
+
3
+ <div align="center">
4
+
5
+ **Algebraic Semitic Root×Pattern Foundation Transformer (`d16`, `261.75M` Params, `5.10B` Tokens), Certified `100%`-Byte-Lossless `Ṣarf-BPE`, `Grassmann-VE` Routing, & `23.8 μs` GPU `Tarkīb` Shield**
6
+ Part of the **Maqāyīs (`مَقاييس`)** Open-Source Ecosystem · [maqayis.org](https://maqayis.org) · [github.com/maqayis/sarfchat](https://github.com/maqayis/sarfchat) · [codeberg.org/maqayis/sarfchat](https://codeberg.org/maqayis/sarfchat)
7
+
8
+ [![License: Apache-2.0](https://img.shields.io/badge/Code-Apache--2.0-blue.svg)](LICENSE)
9
+ [![Paper & Results: CC BY 4.0](https://img.shields.io/badge/Paper_%26_Results-CC_BY_4.0-246B45.svg)](NOTICE)
10
+ [![Python 3.11+](https://img.shields.io/badge/Python-3.11%2B-3776AB.svg)](pyproject.toml)
11
+
12
+ </div>
13
+
14
+ ---
15
+
16
+ ## نظرة عامّة | Overview
17
+
18
+ **`SarfChat-v2` (`صرف-شات v2.0.0`)** هو المحوِّل التوليدي التأسيسي ومختبر قوانين التوسّع متساوية الحوسبة (`Iso-FLOP Scaling Laws`) في منظومة **مَقاييس (`Maqāyīs`)** من تأليف وتطوير **صلاح عبده (`Salah Abdo`)**. بدلاً من الاكتفاء بترقيع النماذج الأجنبية من الخارج أو استنزاف ميزانية المعلمات في جداول التقطيع الإحصائي الصمّاء (`Byte-BPE`)، يدمج `SarfChat-v2` جبر الجذر والوزن الريماني وألياف غراسمان المتعدّدة الأصول (`Gr(k_R, 256)`) والسمات النطقية لسيبويه في صميم طبقات المحوِّل ذاته.
19
+
20
+ **`SarfChat-v2` (`v2.0.0`)** replaces monolithic subword memorization tables with **asymmetric morphological-Grassmannian inductive biases**:
21
+ 1. **Certified `100.0%`-Byte-Lossless `Ṣarf-BPE` & `FactoredSarfDAGHead` (`Exp S1`):** Folds `65.67%` of running Arabic words (`36,186 / 55,103`) and `100.0%` (`534 / 534`) of unseen OOV-root words into a single algebraic frame `(p, C1, C2, C3, w, e)`, eliminating OOV radical fracture (`2.41 -> 1.00` steps/word) and saving `1.22×` quadratic attention FLOPs while guaranteeing `100.000%` UTF-8 byte round-trip identity.
22
+ 2. **Dynamic `Grassmann-VE` Routing (`GrassmannFiberValueRouter`, `Exp S2–S3`):** Projects hidden states onto Ibn Fāris's orthonormal multi-*aṣl* sense bundles `Gr(k_R, 256)` across `L/2` alternating layers, compressing deep value tables by **`-93.6%`** (`75.50M -> 4.83M` at `d12`; `134.22M -> 9.54M` at `d16`).
23
+ 3. **19-Run Iso-FLOP Scaling & Causal Permutation Campaign (`Exp S2–S3`):** Breaks the multi-epoch flat-BPE memorization wall (`1.0962 -> 0.9716 bpb`, **`-0.1246 bpb`** at `d12`) and causally separates low-rank value regularization on seen words (`token_perm` / `root_perm` / `true_tarkib` within `±0.003 bpb` overall) from authentic sub-root zero-shot generalization on unseen OOV-root target words (**`2.6677 bpb`** vs `2.7009` `token_perm`, `2.7007` `root_perm`, and `2.8620` flat BPE; paired `t = -5.94, p = 2.83×10⁻⁹` across `97` roots).
24
+ 4. **Asymmetric Flagship `SarfChat-v2` (`d16`, `261.75M` Params, `5.10B` Tokens, `Exp S4–S5`):** Pairs `TarkibSubwordInjector` (`23,253 / 32,768` root-grounded subwords = `70.96%`, `29.49%` interface share vs `64.52%` flat equivalent) with single-pass `_FusedChunkedSoftcapLinearCE` (`8.59 GB -> 0.54 GB` logit VRAM, **`-93.7%`**, `105.0k tok/s`, **`58.3% MFU`**) and paragraph-level OOV surgical isolation (`1.4% -> 57.7%` long-book retention = **`41.2×`**, `0.0%` root leakage).
25
+ 5. **`23.8 μs` GPU `Tarkīb` Morpho-Phonotactic Shield & `Tayf` Neuro-Symbolic Prism (`Exp S6–S7`):** Lifts morpho-phonotactic & ontological legality to **`100.0%`** (`40/40` core suite: `97.5% -> 100.0%`; `200/200` extended suite: `98.0% / 96.5% -> 100.0%`) in `23.82 μs` per step, and lowers grounded answer entropy from `1.238 -> 0.673 bpb` (`95.0%` homonym trap survival) when paired with Zero-LLM [`maqayis/tayf`](https://github.com/maqayis/tayf).
26
+
27
+ ---
28
+
29
+ ## النتائج المرجعية | Headline `SarfChat-v2` Metrics
30
+
31
+ | Metric / Stage | Specification / Split | Value |
32
+ | :--- | :--- | :--- |
33
+ | **Architecture (`sarfchat_v2`)** | `d16` (`L=16, d=1024, n_q=16, n_kv=8, T=2048, V=32,768`) | **`261,751,467`** total / **`221,788,952`** active matmul |
34
+ | **Interface Parameter Tax** | `SarfChat-v2` (`77.20M`) vs Flat Equivalent (`335.54M`) | **`29.49%`** vs `64.52%` (`-258.3M` params saved) |
35
+ | **Pretraining Scale (Stages 1 + 2)** | `WSD Plateau` (`4.40B`) + `WSD Cooldown` (`0.70B`) | **`5,095,292,928` tokens** (**`33.63 GB`** UTF-8, `8.83e18` FLOPs) |
36
+ | **Overall Validation `val_bpb`** | Held-out multi-register `val_v2` (`0.8157` plateau -> cooldown) | **`0.7353 bpb`** (`0.73529`, `-0.0804` cooldown drop) |
37
+ | **Register Breakdown (`val_bpb`)** | `msa_edu` / `msa_wiki_books` / `classical_turath` | **`0.7139`** / **`0.7321`** / **`0.7598 bpb`** |
38
+ | **Zero-Shot Unseen OOV-Root `bpb`** | `511` OOV-root docs (`100` strictly held-out roots, `0%` leakage) | **`0.6976 bpb`** (`0.69757` doc) · **`1.8861 bpb`** (`643` OOV words) |
39
+ | **Stage 3 Arabic Chat SFT** | `46,858` train / `600` val multi-turn dialogues (`342` steps) | `sft_val_loss`: `4.0122 ->` **`2.4743`** (`PPL = 11.87`) |
40
+ | **GPU `Tarkīb` Guard (`23.82 μs`)** | `40`-pair core suite (`base`) · `200`-pair fortification (`base` / `sft`) | `97.5% ->` **`100.0%`** (`40/40`) · `98.0% / 96.5% ->` **`100.0%`** (`200/200`) |
41
+ | **Neuro-Symbolic `Tayf + SarfChat-v2`** | `20`-query adversarial homonym-trap grounded QA (`Exp S7-B`) | `1.238 ->` **`0.673 bpb`** (`-45.7%`) · **`95.0%`** (`19/20`) trap survival |
42
+
43
+ > **Book `v2.0` Sync Note:** *The Geometry of the Arabic Tongue* (`Book v2.0`, [`maqayis/tarkib`](https://github.com/maqayis/tarkib)) Ch. 21 reports the foundational `SarfChat-v1` `d12` Iso-FLOP campaign and early `d16` specification, while Part X (Ch. 22–23) and this repository (`v2.0.0`) present the completed `5.10B`-token 3-stage `d16` WSD cooldown + Chat SFT campaign (`val_bpb = 0.7353`), `19`-run causal permutation matrix, and `200`-pair GPU guard audit.
44
+
45
+ ---
46
+
47
+ ## التثبيت والتشغيل السريع | Installation & Quickstart
48
+
49
+ ```bash
50
+ pip install sarfchat
51
+ ```
52
+
53
+ ### 1. Offline CPU Unit Tests (`<200 MB` RAM, Zero Downloads Required)
54
+ ```bash
55
+ pytest -q
56
+ ```
57
+
58
+ ### 2. Hydrate Checkpoints & Tokenizers (SHA-256 Verified via `data-manifest.tsv`)
59
+ ```bash
60
+ ./fetch-data.sh data # corpus splits, bpe16k/bpe32k tokenizers, and Tarkīb priors (~499 MB)
61
+ ./fetch-data.sh runs # all 8 safetensors checkpoints incl. sarfchat_v2_d16_base & _sft (~2.96 GB)
62
+ ```
63
+
64
+ ### 3. Launch Interactive RTL Web Arena or Terminal Chat
65
+ ```bash
66
+ sarfchat-arena --host 127.0.0.1 --port 8787
67
+ sarfchat-chat --checkpoint checkpoints/sarfchat_v2_d16_sft
68
+ ```
69
+
70
+ See [`WEIGHTS_AND_REPRODUCIBILITY.md`](WEIGHTS_AND_REPRODUCIBILITY.md) for complete `SHA-256` checkpoint manifests, model cards, and exact reproduction commands, and [`paper/main.pdf`](paper/main.pdf) (`paper/main.tex`) for the full Arabic monograph study.
71
+
72
+ ---
73
+
74
+ ## الترخيص وحقوق الملكية | License & Attribution
75
+
76
+ - **Software & Source Code (`src/`, `scripts/`, `tests/`):** [Apache License 2.0](LICENSE)
77
+ - **Research Paper, Figures, & Empirical Result Ledgers (`paper/`, `results/`):** [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
78
+ - **Author:** Salah Abdo (`صلاح عبده`) `<Salah.Abdo.Tech@gmail.com>` · `Copyright 2026 Salah Abdo and successor entity` · [`NOTICE`](NOTICE) · [`CITATION.cff`](CITATION.cff)