Question Answering
sentence-transformers
Safetensors
GGUF
English
retrieval
cross-encoder
verification
citations
edge
cpu
offline
Eval Results (legacy)
Instructions to use RysoAI/tinyqa-1-moss with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use RysoAI/tinyqa-1-moss with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("RysoAI/tinyqa-1-moss") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use RysoAI/tinyqa-1-moss with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf RysoAI/tinyqa-1-moss:Q8_0 # Run inference directly in the terminal: llama cli -hf RysoAI/tinyqa-1-moss:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf RysoAI/tinyqa-1-moss:Q8_0 # Run inference directly in the terminal: llama cli -hf RysoAI/tinyqa-1-moss:Q8_0
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf RysoAI/tinyqa-1-moss:Q8_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf RysoAI/tinyqa-1-moss:Q8_0
Use Docker
docker model run hf.co/RysoAI/tinyqa-1-moss:Q8_0
- Llama new
- LM Studio
- Jan
- Ollama
How to use RysoAI/tinyqa-1-moss with Ollama:
ollama run hf.co/RysoAI/tinyqa-1-moss:Q8_0
- Unsloth Desktop
- Docker Model Runner
How to use RysoAI/tinyqa-1-moss with Docker Model Runner:
docker model run hf.co/RysoAI/tinyqa-1-moss:Q8_0
- Lemonade
How to use RysoAI/tinyqa-1-moss with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull RysoAI/tinyqa-1-moss:Q8_0
Run and chat with the model
lemonade run user.tinyqa-1-moss-Q8_0
List all available models
lemonade list
- Atomic Chat
Commit ·
b257ec0
0
Parent(s):
RysoAI TinyQA-1 Moss
Browse files- .gitattributes +41 -0
- LICENSE +202 -0
- NOTICE.md +19 -0
- README.md +195 -0
- SHA256SUMS +29 -0
- code/tinyqa/__init__.py +0 -0
- code/tinyqa/cli.py +35 -0
- code/tinyqa/extract.py +98 -0
- code/tinyqa/pipeline.py +691 -0
- code/tinyqa/server.py +49 -0
- code/tinyqa/sieve.py +57 -0
- gguf/tinyqa-1-moss-glue-Q8_0.gguf +3 -0
- gguf/tinyqa-1-moss-planner-Q8_0.gguf +3 -0
- gguf/tinyqa-1-moss-verbaliser-Q8_0.gguf +3 -0
- models/ranker/config.json +37 -0
- models/ranker/model.safetensors +3 -0
- models/ranker/tokenizer.json +0 -0
- models/ranker/tokenizer_config.json +18 -0
- models/verifier/config.json +32 -0
- models/verifier/model.safetensors +3 -0
- models/verifier/special_tokens_map.json +37 -0
- models/verifier/tokenizer.json +0 -0
- models/verifier/tokenizer_config.json +58 -0
- models/verifier/vocab.txt +0 -0
- moss.sh +51 -0
- requirements.txt +7 -0
- results/freshqa_600_serper_summary.json +56 -0
- results/popqa_1000_serper_summary.json +116 -0
- results/repro.json +70 -0
- results/simpleqa_1000_ddgs_summary.json +91 -0
- results/simpleqa_1000_serper_summary.json +91 -0
.gitattributes
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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 |
+
gguf/gse-planner-120m-v2-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
gguf/gse-sft-120m-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
gguf/gse-verbaliser-120m-short-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
gguf/tinyqa-1-moss-glue-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
gguf/tinyqa-1-moss-planner-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
gguf/tinyqa-1-moss-verbaliser-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache License
|
| 3 |
+
Version 2.0, January 2004
|
| 4 |
+
http://www.apache.org/licenses/
|
| 5 |
+
|
| 6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
+
|
| 8 |
+
1. Definitions.
|
| 9 |
+
|
| 10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
+
|
| 13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
+
the copyright owner that is granting the License.
|
| 15 |
+
|
| 16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
+
other entities that control, are controlled by, or are under common
|
| 18 |
+
control with that entity. For the purposes of this definition,
|
| 19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
+
direction or management of such entity, whether by contract or
|
| 21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
+
|
| 24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
+
exercising permissions granted by this License.
|
| 26 |
+
|
| 27 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
+
including but not limited to software source code, documentation
|
| 29 |
+
source, and configuration files.
|
| 30 |
+
|
| 31 |
+
"Object" form shall mean any form resulting from mechanical
|
| 32 |
+
transformation or translation of a Source form, including but
|
| 33 |
+
not limited to compiled object code, generated documentation,
|
| 34 |
+
and conversions to other media types.
|
| 35 |
+
|
| 36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
+
Object form, made available under the License, as indicated by a
|
| 38 |
+
copyright notice that is included in or attached to the work
|
| 39 |
+
(an example is provided in the Appendix below).
|
| 40 |
+
|
| 41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
+
form, that is based on (or derived from) the Work and for which the
|
| 43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
+
of this License, Derivative Works shall not include works that remain
|
| 46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
+
the Work and Derivative Works thereof.
|
| 48 |
+
|
| 49 |
+
"Contribution" shall mean any work of authorship, including
|
| 50 |
+
the original version of the Work and any modifications or additions
|
| 51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
+
means any form of electronic, verbal, or written communication sent
|
| 56 |
+
to the Licensor or its representatives, including but not limited to
|
| 57 |
+
communication on electronic mailing lists, source code control systems,
|
| 58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
+
excluding communication that is conspicuously marked or otherwise
|
| 61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
+
|
| 63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
+
subsequently incorporated within the Work.
|
| 66 |
+
|
| 67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
+
Work and such Derivative Works in Source or Object form.
|
| 73 |
+
|
| 74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
+
(except as stated in this section) patent license to make, have made,
|
| 78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
+
where such license applies only to those patent claims licensable
|
| 80 |
+
by such Contributor that are necessarily infringed by their
|
| 81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
+
institute patent litigation against any entity (including a
|
| 84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
+
or contributory patent infringement, then any patent licenses
|
| 87 |
+
granted to You under this License for that Work shall terminate
|
| 88 |
+
as of the date such litigation is filed.
|
| 89 |
+
|
| 90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
+
modifications, and in Source or Object form, provided that You
|
| 93 |
+
meet the following conditions:
|
| 94 |
+
|
| 95 |
+
(a) You must give any other recipients of the Work or
|
| 96 |
+
Derivative Works a copy of this License; and
|
| 97 |
+
|
| 98 |
+
(b) You must cause any modified files to carry prominent notices
|
| 99 |
+
stating that You changed the files; and
|
| 100 |
+
|
| 101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
+
that You distribute, all copyright, patent, trademark, and
|
| 103 |
+
attribution notices from the Source form of the Work,
|
| 104 |
+
excluding those notices that do not pertain to any part of
|
| 105 |
+
the Derivative Works; and
|
| 106 |
+
|
| 107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
+
distribution, then any Derivative Works that You distribute must
|
| 109 |
+
include a readable copy of the attribution notices contained
|
| 110 |
+
within such NOTICE file, excluding those notices that do not
|
| 111 |
+
pertain to any part of the Derivative Works, in at least one
|
| 112 |
+
of the following places: within a NOTICE text file distributed
|
| 113 |
+
as part of the Derivative Works; within the Source form or
|
| 114 |
+
documentation, if provided along with the Derivative Works; or,
|
| 115 |
+
within a display generated by the Derivative Works, if and
|
| 116 |
+
wherever such third-party notices normally appear. The contents
|
| 117 |
+
of the NOTICE file are for informational purposes only and
|
| 118 |
+
do not modify the License. You may add Your own attribution
|
| 119 |
+
notices within Derivative Works that You distribute, alongside
|
| 120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
+
that such additional attribution notices cannot be construed
|
| 122 |
+
as modifying the License.
|
| 123 |
+
|
| 124 |
+
You may add Your own copyright statement to Your modifications and
|
| 125 |
+
may provide additional or different license terms and conditions
|
| 126 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
+
the conditions stated in this License.
|
| 130 |
+
|
| 131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
+
this License, without any additional terms or conditions.
|
| 135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
+
the terms of any separate license agreement you may have executed
|
| 137 |
+
with Licensor regarding such Contributions.
|
| 138 |
+
|
| 139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
+
except as required for reasonable and customary use in describing the
|
| 142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
+
|
| 144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
+
implied, including, without limitation, any warranties or conditions
|
| 149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
+
appropriateness of using or redistributing the Work and assume any
|
| 152 |
+
risks associated with Your exercise of permissions under this License.
|
| 153 |
+
|
| 154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
+
unless required by applicable law (such as deliberate and grossly
|
| 157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
+
liable to You for damages, including any direct, indirect, special,
|
| 159 |
+
incidental, or consequential damages of any character arising as a
|
| 160 |
+
result of this License or out of the use or inability to use the
|
| 161 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
+
other commercial damages or losses), even if such Contributor
|
| 164 |
+
has been advised of the possibility of such damages.
|
| 165 |
+
|
| 166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
+
or other liability obligations and/or rights consistent with this
|
| 170 |
+
License. However, in accepting such obligations, You may act only
|
| 171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
+
defend, and hold each Contributor harmless for any liability
|
| 174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
+
of your accepting any such warranty or additional liability.
|
| 176 |
+
|
| 177 |
+
END OF TERMS AND CONDITIONS
|
| 178 |
+
|
| 179 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 180 |
+
|
| 181 |
+
To apply the Apache License to your work, attach the following
|
| 182 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 183 |
+
replaced with your own identifying information. (Don't include
|
| 184 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 185 |
+
comment syntax for the file format. We also recommend that a
|
| 186 |
+
file or class name and description of purpose be included on the
|
| 187 |
+
same "printed page" as the copyright notice for easier
|
| 188 |
+
identification within third-party archives.
|
| 189 |
+
|
| 190 |
+
Copyright [yyyy] [name of copyright owner]
|
| 191 |
+
|
| 192 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 193 |
+
you may not use this file except in compliance with the License.
|
| 194 |
+
You may obtain a copy of the License at
|
| 195 |
+
|
| 196 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 197 |
+
|
| 198 |
+
Unless required by applicable law or agreed to in writing, software
|
| 199 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 200 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 201 |
+
See the License for the specific language governing permissions and
|
| 202 |
+
limitations under the License.
|
NOTICE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Notices
|
| 2 |
+
|
| 3 |
+
RysoAI TinyQA-1 Moss code and the weights in `models/` and `gguf/` are released under the Apache License 2.0 (see `LICENSE`).
|
| 4 |
+
|
| 5 |
+
## Components
|
| 6 |
+
|
| 7 |
+
| component | file | license |
|
| 8 |
+
|---|---|---|
|
| 9 |
+
| Ranker, 22M | `models/ranker` | Apache-2.0; fine-tuned from `cross-encoder/ms-marco-MiniLM-L6-v2` (Apache-2.0) |
|
| 10 |
+
| Verifier, 33M | `models/verifier` | Apache-2.0; fine-tuned from `cross-encoder/ms-marco-MiniLM-L12-v2` (Apache-2.0) |
|
| 11 |
+
| Verbaliser, glue decoder, planner, 113M each | `gguf/` | Apache-2.0 |
|
| 12 |
+
| Reader, 33M | not included; downloaded at run time | `deepset/minilm-uncased-squad2`, CC-BY-4.0 |
|
| 13 |
+
|
| 14 |
+
## Attributions
|
| 15 |
+
|
| 16 |
+
- Reader: deepset, *minilm-uncased-squad2*, https://huggingface.co/deepset/minilm-uncased-squad2, CC-BY-4.0.
|
| 17 |
+
- Cross-encoder bases: *ms-marco-MiniLM-L6-v2* and *ms-marco-MiniLM-L12-v2*, https://huggingface.co/cross-encoder, Apache-2.0.
|
| 18 |
+
- Tokenizer of the 113M models: derived from the SmolLM2 vocabulary (Hugging Face, Apache-2.0).
|
| 19 |
+
- Pretraining text of the 113M models: FineWeb-Edu (Hugging Face), ODC-By 1.0.
|
README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
library_name: sentence-transformers
|
| 6 |
+
pipeline_tag: question-answering
|
| 7 |
+
tags:
|
| 8 |
+
- question-answering
|
| 9 |
+
- retrieval
|
| 10 |
+
- cross-encoder
|
| 11 |
+
- verification
|
| 12 |
+
- citations
|
| 13 |
+
- edge
|
| 14 |
+
- cpu
|
| 15 |
+
- offline
|
| 16 |
+
base_model:
|
| 17 |
+
- cross-encoder/ms-marco-MiniLM-L6-v2
|
| 18 |
+
- cross-encoder/ms-marco-MiniLM-L12-v2
|
| 19 |
+
model-index:
|
| 20 |
+
- name: RysoAI TinyQA-1 Moss
|
| 21 |
+
results:
|
| 22 |
+
- task: {type: question-answering, name: Open-book question answering}
|
| 23 |
+
dataset: {type: google/simpleqa-verified, name: SimpleQA Verified, split: eval}
|
| 24 |
+
metrics:
|
| 25 |
+
- {type: f1, value: 77.1, name: F-score (open-book, DuckDuckGo)}
|
| 26 |
+
- {type: accuracy, value: 71.3, name: Correct (open-book, DuckDuckGo)}
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
# RysoAI TinyQA-1 Moss
|
| 30 |
+
|
| 31 |
+
**A tiny but powerful 89M-parameter question-answering model.**
|
| 32 |
+
|
| 33 |
+
Moss is a retrieval question-answering system built to be as small as possible while still answering at a high standard.
|
| 34 |
+
It reads search results or a local collection of documents, selects the text that states the answer, checks and verifies
|
| 35 |
+
it, and returns the exact quote, the short answer and its source in a readable format. Every answer carries its
|
| 36 |
+
verification result, so an unverified answer is always clearly marked.
|
| 37 |
+
|
| 38 |
+
## 1. General information
|
| 39 |
+
|
| 40 |
+
Moss can be used anywhere a question needs a sourced answer. It was initially designed for two settings:
|
| 41 |
+
|
| 42 |
+
- **Minimal hardware.** Small enough for single-board computers and other constrained devices, with very little
|
| 43 |
+
inference cost. It can run fully offline against a local corpus, or over an intranet, where a large language model
|
| 44 |
+
is not practical.
|
| 45 |
+
- **Retrieval at scale.** At about a quarter of a second of compute per question on a laptop CPU, Moss can gather and
|
| 46 |
+
verify large volumes of facts cheaply. We use it to collect millions of data points of evidence for our larger
|
| 47 |
+
forecasting models, which we benchmark publicly on ForecastBench ([ryso.ai](https://ryso.ai)).
|
| 48 |
+
|
| 49 |
+
It also works well alongside larger models: Moss gathers and verifies information with almost no inference, and the
|
| 50 |
+
sourced results can be passed to a large language model to reason over.
|
| 51 |
+
|
| 52 |
+
| | |
|
| 53 |
+
|---|---|
|
| 54 |
+
| Model provider | RysoAI |
|
| 55 |
+
| Release date | November 2026 |
|
| 56 |
+
| Languages | English |
|
| 57 |
+
| License | Apache 2.0 |
|
| 58 |
+
|
| 59 |
+
## 2. Getting started
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
./moss.sh setup # Python 3.11 environment with pinned dependencies
|
| 63 |
+
./moss.sh start # loads the models in the background
|
| 64 |
+
./moss.sh ask "Who designed the Missouri Centennial half dollar?"
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
The Missouri Centennial half dollar was designed by Robert Aitken, who is best known for designing the Panama Pacific Exposition fifty dollar gold commemoratives.
|
| 69 |
+
“The coin was designed by Robert Aitken, who is best known for designing the Panama Pacific Exposition fifty dollar gold commemoratives.” (stated by 3 sources)
|
| 70 |
+
https://www.your-rare-coin-collecting-guide.com/missouri-centennial.html
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
**Local documents.** Index any folder of `.txt` or `.md` files, or a `.jsonl` file of `{"title", "text"}` records, and
|
| 74 |
+
ask questions with no network connection:
|
| 75 |
+
|
| 76 |
+
```bash
|
| 77 |
+
./moss.sh index ~/Documents/field-manuals
|
| 78 |
+
./moss.sh start
|
| 79 |
+
./moss.sh ask --local "How long should water be boiled to make it safe?"
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
**Search.** Web search uses DuckDuckGo by default and needs no key. Add `SERPER_API_KEY=...` to a `.env` file beside
|
| 83 |
+
`moss.sh` to use Google results and verifier-gated retries.
|
| 84 |
+
|
| 85 |
+
**Answer line.** Install [llama.cpp](https://github.com/ggml-org/llama.cpp) (`brew install llama.cpp`) and the 113M
|
| 86 |
+
models write a one-sentence answer around the verified quote. Without it, a template is used. The quote is always shown.
|
| 87 |
+
|
| 88 |
+
## 3. Model properties
|
| 89 |
+
|
| 90 |
+
**Architecture.** A pipeline of small transformer encoders, each with one job, plus optional 113M decoders for the
|
| 91 |
+
written answer line.
|
| 92 |
+
|
| 93 |
+
| component | role | parameters | file |
|
| 94 |
+
|---|---|---|---|
|
| 95 |
+
| Ranker | orders candidate sentences by relevance to the question | 22M | `models/ranker` |
|
| 96 |
+
| Verifier | scores whether a sentence states the answer; this score is the confidence | 33M | `models/verifier` |
|
| 97 |
+
| Reader | marks the exact answer span inside the chosen sentence | 33M | `deepset/minilm-uncased-squad2`, fetched at run time |
|
| 98 |
+
| Verbaliser (optional) | writes the answer line using only words already on the page | 113M | `gguf/tinyqa-1-moss-verbaliser-Q8_0.gguf` |
|
| 99 |
+
| Glue decoder (optional) | fallback answer-line writer | 113M | `gguf/tinyqa-1-moss-glue-Q8_0.gguf` |
|
| 100 |
+
| Planner (optional) | rewrites queries for retries and supplies answer frames | 113M | `gguf/tinyqa-1-moss-planner-Q8_0.gguf` |
|
| 101 |
+
|
| 102 |
+
**Parameters.** 89M for the core answering path (ranker, verifier, reader), 429M with all three optional decoders.
|
| 103 |
+
|
| 104 |
+
**Input.** A natural-language question in English.
|
| 105 |
+
|
| 106 |
+
**Output.** One verified sentence quoted verbatim from a source, the short answer span within it, the source link, a
|
| 107 |
+
verified or not-verified flag, and the number of independent sources that agree. Optionally, a one-line written answer.
|
| 108 |
+
|
| 109 |
+
**Verification.** An answer is marked verified when the verifier scores it at 1.5 or above, or when three independent
|
| 110 |
+
sources state the same short answer and the verifier does not score against it. Unverified results are labelled as such
|
| 111 |
+
and never presented as the answer.
|
| 112 |
+
|
| 113 |
+
**Hardware.** CPU only; no GPU needed. The core encoders take about 360 MB in fp32, and each optional decoder is 117 MB at
|
| 114 |
+
Q8. Search time dominates latency on the web; with a local corpus, a full answer takes a few hundred milliseconds.
|
| 115 |
+
|
| 116 |
+
## 4. Training
|
| 117 |
+
|
| 118 |
+
The ranker and verifier are fine-tuned from public MS MARCO cross-encoders. The 113M decoders were pretrained from
|
| 119 |
+
scratch on public educational web text and then fine-tuned. Training data was drawn from publicly available sources and
|
| 120 |
+
synthetically generated, then filtered and deduplicated.
|
| 121 |
+
|
| 122 |
+
No benchmark questions were used in training. The verifier's training questions also exclude every subject that appears
|
| 123 |
+
in the benchmarks, and websites that host the benchmarks were excluded as sources in the benchmark runs.
|
| 124 |
+
|
| 125 |
+
## 5. Evaluations
|
| 126 |
+
|
| 127 |
+
All results use the official SimpleQA grader prompt with `gpt-4.1-2025-04-14` on the full benchmark sets.
|
| 128 |
+
|
| 129 |
+
**Moss is evaluated open-book.** It answers from retrieved text, exactly as it runs in use. The frontier models it is
|
| 130 |
+
compared with below are evaluated **closed-book**, answering from memory alone. The comparison shows what a very small
|
| 131 |
+
retrieval system can reach against much larger models; it is not a like-for-like test of the same setting.
|
| 132 |
+
|
| 133 |
+
### SimpleQA Verified (1,000 questions)
|
| 134 |
+
|
| 135 |
+
| system | setting | parameters | score |
|
| 136 |
+
|---|---|---|---|
|
| 137 |
+
| Gemini 3.1 Pro Preview | closed-book | undisclosed | 77.5 |
|
| 138 |
+
| **RysoAI TinyQA-1 Moss** (F-score) | **open-book, DuckDuckGo** | **89M** | **77.1** |
|
| 139 |
+
| GPT-6 Astra | closed-book | undisclosed | 75.8 |
|
| 140 |
+
| Gemini 4 Argon | closed-book | undisclosed | 75.6 |
|
| 141 |
+
| Gemini 3.8 Flash | closed-book | undisclosed | 74.6 |
|
| 142 |
+
| **RysoAI TinyQA-1 Moss** (F-score) | **open-book, Google** | **89M** | **74.0** |
|
| 143 |
+
| GPT-6.1 Sol | closed-book | undisclosed | 73.8 |
|
| 144 |
+
| Gemini 3 Pro Preview | closed-book | undisclosed | 72.1 |
|
| 145 |
+
| GPT-5.6 Sol | closed-book | undisclosed | 69.2 |
|
| 146 |
+
| Claude Opus 5 | closed-book | undisclosed | 63.3 |
|
| 147 |
+
| Claude Opus 4.6 | closed-book | undisclosed | 45.2 |
|
| 148 |
+
|
| 149 |
+
Closed-book scores are from the public [SimpleQA Verified leaderboard](https://www.kaggle.com/benchmarks/deepmind/simpleqa-verified)
|
| 150 |
+
(snapshot of 19 November 2026). The leaderboard reports a single score; the benchmark paper's headline metric is F-score.
|
| 151 |
+
|
| 152 |
+
### Detailed results
|
| 153 |
+
|
| 154 |
+
| benchmark | search | correct | incorrect | not attempted | precision when answering | F-score |
|
| 155 |
+
|---|---|---|---|---|---|---|
|
| 156 |
+
| SimpleQA Verified | DuckDuckGo | 71.3 | 13.7 | 15.0 | 83.9 | 77.1 |
|
| 157 |
+
| SimpleQA Verified, verified answers only | DuckDuckGo | 60.9 | 6.2 | 32.9 | **90.8** | 72.9 |
|
| 158 |
+
| SimpleQA Verified | Google | 69.6 | 18.6 | 11.8 | 78.9 | 74.0 |
|
| 159 |
+
| SimpleQA Verified, verified answers only | Google | 59.2 | 7.5 | 33.3 | 88.8 | 71.0 |
|
| 160 |
+
| PopQA, 1,000 least-popular subjects | Google | 47.4 | 48.5 | 4.1 | 49.4 | 48.4 |
|
| 161 |
+
| PopQA, verified answers only | Google | 42.1 | 23.6 | 34.3 | 64.1 | 50.8 |
|
| 162 |
+
| FreshQA, 600 | Google | 39.5 | 52.3 | 8.2 | 43.0 | 41.2 |
|
| 163 |
+
| FreshQA, verified answers only | Google | 30.8 | 20.2 | 49.0 | 60.5 | 40.8 |
|
| 164 |
+
|
| 165 |
+
"Verified answers only" counts every answer Moss does not verify as not attempted. That is how Moss behaves when told to
|
| 166 |
+
answer only when sure. The graded answer is the short answer followed by the quoted sentence, as Moss displays it. FreshQA
|
| 167 |
+
gold answers date from August 2025, so its fast-changing questions are partly out of date against the live web.
|
| 168 |
+
|
| 169 |
+
Summaries of every graded run are in `results/`.
|
| 170 |
+
|
| 171 |
+
## 6. Limitations
|
| 172 |
+
|
| 173 |
+
- Moss answers questions whose answer is stated in a single sentence of the retrieved text. Questions that need
|
| 174 |
+
arithmetic, comparison or combining facts from several sources are outside its scope.
|
| 175 |
+
- Its accuracy follows the quality of what it retrieves. A verified quote reflects what the source says.
|
| 176 |
+
- Results above are for web search, where engines return passages already focused on the question. Local collections
|
| 177 |
+
are searched with a built-in keyword index.
|
| 178 |
+
- English only.
|
| 179 |
+
|
| 180 |
+
## 7. License
|
| 181 |
+
|
| 182 |
+
Code and weights in this repository are released under the Apache 2.0 license. The reader model,
|
| 183 |
+
[deepset/minilm-uncased-squad2](https://huggingface.co/deepset/minilm-uncased-squad2), is licensed CC-BY-4.0 and is
|
| 184 |
+
downloaded from its own repository at run time. See `NOTICE.md` for full attributions.
|
| 185 |
+
|
| 186 |
+
## Citation
|
| 187 |
+
|
| 188 |
+
```bibtex
|
| 189 |
+
@misc{ryso_tinyqa1_moss_2026,
|
| 190 |
+
title = {RysoAI TinyQA-1 Moss},
|
| 191 |
+
author = {{RysoAI}},
|
| 192 |
+
year = {2026},
|
| 193 |
+
url = {https://ryso.ai}
|
| 194 |
+
}
|
| 195 |
+
```
|
SHA256SUMS
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30 ./LICENSE
|
| 2 |
+
0954bc2b4e2a508b699dc31c346ae008fa40ac40be59c0ff01988d4e100e297b ./NOTICE.md
|
| 3 |
+
6cbfa9bd0a052427518da40d3b2bbb69f2a887aa4cc6851a0bbb1eb3537d39e6 ./README.md
|
| 4 |
+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ./code/tinyqa/__init__.py
|
| 5 |
+
cb58baa781b915bff4830b832ea0687d75aab0efd792f89e0f43c50bbca5d0c9 ./code/tinyqa/cli.py
|
| 6 |
+
f6d367b02c25e64f4cee86c89064192561748152891eab797ac7f83a0e0f720c ./code/tinyqa/extract.py
|
| 7 |
+
097e101c069b1d140d6d95cfd6afaa6cbab6dfc03da08c528ddac54f1b4ba7f4 ./code/tinyqa/pipeline.py
|
| 8 |
+
d9c9ba91dc99ceeed92cd08fdb3fe126a929929e2cf25a2585509f0dd7609492 ./code/tinyqa/server.py
|
| 9 |
+
a6effd97e8d20ba744f1779940417ba601729d8bec165f8f3a940db138dabb62 ./code/tinyqa/sieve.py
|
| 10 |
+
bdb15946920cdac9ea17eaeefa38095dd2fa17516dcf0bf582f781d685554520 ./gguf/tinyqa-1-moss-glue-Q8_0.gguf
|
| 11 |
+
4a963495409d2838fcc3136c0d573b1d4d907e5d043c6cc6e4652ddae7d857c5 ./gguf/tinyqa-1-moss-planner-Q8_0.gguf
|
| 12 |
+
dbd60b72ec1e5668c2e29e8bb70e393495a3d814e51ea9086fe39ebd649b52e4 ./gguf/tinyqa-1-moss-verbaliser-Q8_0.gguf
|
| 13 |
+
1890f7157c851bfea48ea028bb61d035a3f0909373a74795bc71b1e720ceccc6 ./models/ranker/config.json
|
| 14 |
+
7dde2650d4e130fa5681e2537fc1875a83971f4f28a346b7ceb26ae1a8758f30 ./models/ranker/model.safetensors
|
| 15 |
+
851ca67100d372ca3ae031a6abd168f53489eebfd7d89523f35c5c9b4d372c3c ./models/ranker/tokenizer.json
|
| 16 |
+
649e41f8cf1cb1b67acc193795ccaef07bcaa3c4e0fc7d286ba8255fab79cffa ./models/ranker/tokenizer_config.json
|
| 17 |
+
e4288df3d671124dd6d41ee93e147b4fb268cdd2b72df1a6e369239488edd2ec ./models/verifier/config.json
|
| 18 |
+
14f34669c51af8f27ea206b29d5bb0de45e2b69030db0927bb41e8f9cb632b2d ./models/verifier/model.safetensors
|
| 19 |
+
5d5b662e421ea9fac075174bb0688ee0d9431699900b90662acd44b2a350503a ./models/verifier/special_tokens_map.json
|
| 20 |
+
851ca67100d372ca3ae031a6abd168f53489eebfd7d89523f35c5c9b4d372c3c ./models/verifier/tokenizer.json
|
| 21 |
+
7b082b48a08a0b5c5939d99472e33addce3d96202155e33f7928cecd171186a0 ./models/verifier/tokenizer_config.json
|
| 22 |
+
07eced375cec144d27c900241f3e339478dec958f92fddbc551f295c992038a3 ./models/verifier/vocab.txt
|
| 23 |
+
31c1b475b54d1a772ce64fd25f446fe15063ab5789786d62f8ffced6526a7549 ./moss.sh
|
| 24 |
+
3cb3eb5f41a5191a28c7602324ee680cb34f2df5907b06603e7382ca521d8253 ./requirements.txt
|
| 25 |
+
16095ae79e1a75787c2e673a9c4f39a76a77aba0eb7af9faad3252a7aefb8f8f ./results/freshqa_600_serper_summary.json
|
| 26 |
+
74a4fefd1e361e24f32c84e1f47e9ba429b18248b42402fa39e6f16647655ba7 ./results/popqa_1000_serper_summary.json
|
| 27 |
+
4221c9e3e20152b5a7b978ba8b3f7db9ed8e59122eec01ef371fd8f235872654 ./results/repro.json
|
| 28 |
+
1ca547aeff5e8188e40dc7051064968bc2f411d8361427be2a43cd02afbd50a9 ./results/simpleqa_1000_ddgs_summary.json
|
| 29 |
+
9675ed2d23bd2a48e19635f2cbb82a1faaa36a3de6e244a7960682187f815139 ./results/simpleqa_1000_serper_summary.json
|
code/tinyqa/__init__.py
ADDED
|
File without changes
|
code/tinyqa/cli.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, os, sys, urllib.parse, urllib.request
|
| 2 |
+
URL, PROV, ARGS = (sys.argv[1], os.environ.get('MOSS_PROVIDER', 'ddgs'), sys.argv[2:])
|
| 3 |
+
if ARGS[:1] == ['--local']:
|
| 4 |
+
PROV, ARGS = ('local', ARGS[1:])
|
| 5 |
+
NAMES = {'ddgs': 'DuckDuckGo', 'serper': 'Google', 'local': 'the local index'}
|
| 6 |
+
|
| 7 |
+
def ask(q):
|
| 8 |
+
try:
|
| 9 |
+
with urllib.request.urlopen(f'{URL}/ask?q={urllib.parse.quote(q)}&provider={PROV}', timeout=180) as r:
|
| 10 |
+
d = json.load(r)
|
| 11 |
+
except Exception as ex:
|
| 12 |
+
print(f'the model service stopped answering ({type(ex).__name__}); run ./moss.sh start')
|
| 13 |
+
return
|
| 14 |
+
if d.get('tier') == 1:
|
| 15 |
+
if d.get('lead'):
|
| 16 |
+
print(d['lead'].replace('**', ''))
|
| 17 |
+
print(' “' + d['cited'] + '”' + (' (stated by %d sources)' % d['support'] if (d.get('support') or 0) >= 2 else ''))
|
| 18 |
+
print(' ' + str(d.get('url')))
|
| 19 |
+
elif d.get('tier') == 3 and (not d.get('cited')):
|
| 20 |
+
print('No results.' + (' The local index is empty or missing: run ./moss.sh index <folder> first.' if PROV == 'local' else ''))
|
| 21 |
+
else:
|
| 22 |
+
print('No verified answer.')
|
| 23 |
+
if ARGS:
|
| 24 |
+
ask(' '.join(ARGS))
|
| 25 |
+
else:
|
| 26 |
+
print(f'RysoAI TinyQA-1 Moss, answering from {NAMES[PROV]}. Type a question, or press Enter on an empty line to quit.')
|
| 27 |
+
while True:
|
| 28 |
+
try:
|
| 29 |
+
q = input('\n? ').strip()
|
| 30 |
+
except (EOFError, KeyboardInterrupt):
|
| 31 |
+
print()
|
| 32 |
+
break
|
| 33 |
+
if not q:
|
| 34 |
+
break
|
| 35 |
+
ask(q)
|
code/tinyqa/extract.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
import os, re
|
| 3 |
+
MODEL = os.environ.get('MOSS_READER_SPAN', 'deepset/minilm-uncased-squad2')
|
| 4 |
+
_QA = None
|
| 5 |
+
_OFF = os.environ.get('MOSS_EXTRACT', '1') == '0'
|
| 6 |
+
|
| 7 |
+
class _SpanModel:
|
| 8 |
+
|
| 9 |
+
def __init__(self, name):
|
| 10 |
+
import torch
|
| 11 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
|
| 12 |
+
torch.set_num_threads(int(os.environ.get('MOSS_EXTRACT_THREADS', '4')))
|
| 13 |
+
self.tok = AutoTokenizer.from_pretrained(name)
|
| 14 |
+
self.model = AutoModelForQuestionAnswering.from_pretrained(name).eval()
|
| 15 |
+
|
| 16 |
+
def __call__(self, question, context, max_answer_tokens=24):
|
| 17 |
+
import torch
|
| 18 |
+
enc = self.tok(question, context, truncation='only_second', max_length=384, return_offsets_mapping=True, return_tensors='pt')
|
| 19 |
+
offsets = enc.pop('offset_mapping')[0].tolist()
|
| 20 |
+
seq_ids = enc.sequence_ids(0)
|
| 21 |
+
with torch.no_grad():
|
| 22 |
+
out = self.model(**enc)
|
| 23 |
+
start, end = (out.start_logits[0], out.end_logits[0])
|
| 24 |
+
null = float(start[0] + end[0])
|
| 25 |
+
ctx_idx = [i for i, sid in enumerate(seq_ids) if sid == 1]
|
| 26 |
+
if not ctx_idx:
|
| 27 |
+
return {'answer': '', 'score': 0.0}
|
| 28 |
+
best, best_s = (None, -1000000000.0)
|
| 29 |
+
s_top = sorted(ctx_idx, key=lambda i: -float(start[i]))[:20]
|
| 30 |
+
e_top = sorted(ctx_idx, key=lambda i: -float(end[i]))[:20]
|
| 31 |
+
for i in s_top:
|
| 32 |
+
for j in e_top:
|
| 33 |
+
if j < i or j - i + 1 > max_answer_tokens:
|
| 34 |
+
continue
|
| 35 |
+
sc = float(start[i] + end[j])
|
| 36 |
+
if sc > best_s:
|
| 37 |
+
best_s, best = (sc, (i, j))
|
| 38 |
+
if best is None or best_s <= null:
|
| 39 |
+
return {'answer': '', 'score': 0.0, 'null_margin': null - best_s if best else None}
|
| 40 |
+
a, b = (offsets[best[0]][0], offsets[best[1]][1])
|
| 41 |
+
span = context[a:b]
|
| 42 |
+
import math
|
| 43 |
+
conf = 1.0 / (1.0 + math.exp(-(best_s - null) / 2.0))
|
| 44 |
+
return {'answer': span, 'score': conf}
|
| 45 |
+
|
| 46 |
+
def get():
|
| 47 |
+
global _QA, _OFF
|
| 48 |
+
if _OFF:
|
| 49 |
+
return None
|
| 50 |
+
if _QA is None:
|
| 51 |
+
try:
|
| 52 |
+
os.environ.setdefault('TOKENIZERS_PARALLELISM', 'false')
|
| 53 |
+
_QA = _SpanModel(MODEL)
|
| 54 |
+
except Exception:
|
| 55 |
+
_OFF = True
|
| 56 |
+
return None
|
| 57 |
+
return _QA
|
| 58 |
+
_DATE = re.compile('\\b(?:\\d{1,2}\\s+)?(?:january|february|march|april|may|june|july|august|september|october|november|december)\\b.*?\\d{4}|\\b(?:1[0-9]{3}|20[0-9]{2})\\b', re.I)
|
| 59 |
+
_NUM = re.compile('\\d[\\d,.]*')
|
| 60 |
+
_NAME = re.compile("^[A-Z][\\w'’.-]*(?:\\s+(?:of|the|de|da|di|von|van|and|&)\\s+)?(?:\\s*[A-Z][\\w'’.-]*){0,5}$")
|
| 61 |
+
|
| 62 |
+
def type_ok(span: str, answer_type: str | None) -> bool:
|
| 63 |
+
s = span.strip()
|
| 64 |
+
if not s or len(s) > 80:
|
| 65 |
+
return False
|
| 66 |
+
if answer_type == 'date':
|
| 67 |
+
return bool(_DATE.search(s))
|
| 68 |
+
if answer_type == 'number':
|
| 69 |
+
return bool(_NUM.search(s))
|
| 70 |
+
if answer_type in ('person', 'place', 'organization'):
|
| 71 |
+
return bool(_NAME.match(s)) or (s[:1].isupper() and len(s.split()) <= 6)
|
| 72 |
+
return True
|
| 73 |
+
|
| 74 |
+
def normalize(s: str) -> str:
|
| 75 |
+
return re.sub('[^a-z0-9 ]', '', s.lower()).strip()
|
| 76 |
+
|
| 77 |
+
def extract(question: str, candidates: list[tuple[str, str]], answer_type: str | None=None, min_score: float=0.15) -> dict | None:
|
| 78 |
+
qa = get()
|
| 79 |
+
if qa is None or not candidates:
|
| 80 |
+
return None
|
| 81 |
+
best, votes = (None, {})
|
| 82 |
+
for ctx, tag in candidates[:4]:
|
| 83 |
+
try:
|
| 84 |
+
r = qa(question, ctx[:2000])
|
| 85 |
+
except Exception:
|
| 86 |
+
continue
|
| 87 |
+
span = (r.get('answer') or '').strip(' .,;:"\'“”')
|
| 88 |
+
score = float(r.get('score') or 0.0)
|
| 89 |
+
if not span or score < min_score or (not type_ok(span, answer_type)):
|
| 90 |
+
continue
|
| 91 |
+
key = normalize(span)
|
| 92 |
+
votes[key] = votes.get(key, 0) + 1
|
| 93 |
+
if best is None or score > best['score']:
|
| 94 |
+
best = {'answer': span, 'score': round(score, 3), 'tag': tag}
|
| 95 |
+
if best is None:
|
| 96 |
+
return None
|
| 97 |
+
best['votes'] = votes.get(normalize(best['answer']), 1)
|
| 98 |
+
return best
|
code/tinyqa/pipeline.py
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections, json, os, random, re, string, sys, time
|
| 2 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 3 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 4 |
+
BK = os.environ.get('MOSS_HOME', os.path.dirname(os.path.dirname(HERE)))
|
| 5 |
+
DATA = os.environ.get('MOSS_DATA', os.path.join(BK, 'data'))
|
| 6 |
+
os.makedirs(DATA, exist_ok=True)
|
| 7 |
+
CACHE = os.environ.get('MOSS_WEBQA_CACHE', os.path.join(DATA, 'webqa_cache.json'))
|
| 8 |
+
|
| 9 |
+
def normalize(s):
|
| 10 |
+
s = s.lower()
|
| 11 |
+
s = ''.join((ch for ch in s if ch not in set(string.punctuation)))
|
| 12 |
+
s = re.sub('\\b(a|an|the)\\b', ' ', s)
|
| 13 |
+
return ' '.join(s.split())
|
| 14 |
+
|
| 15 |
+
def contains(text, answers):
|
| 16 |
+
t = normalize(text)
|
| 17 |
+
return any((normalize(a) and normalize(a) in t for a in answers))
|
| 18 |
+
CACHE_DDGS = os.path.join(DATA, 'webqa_cache.json')
|
| 19 |
+
CACHE_SERPER = os.path.join(DATA, 'webqa_cache_serper.json')
|
| 20 |
+
_caches = {'ddgs': json.load(open(CACHE_DDGS)) if os.path.exists(CACHE_DDGS) else {}, 'serper': json.load(open(CACHE_SERPER)) if os.path.exists(CACHE_SERPER) else {}}
|
| 21 |
+
|
| 22 |
+
def default_provider():
|
| 23 |
+
return os.environ.get('MOSS_SEARCH') or 'ddgs'
|
| 24 |
+
|
| 25 |
+
def _merge_save(path, mem):
|
| 26 |
+
import fcntl
|
| 27 |
+
with open(path, 'a+') as f:
|
| 28 |
+
fcntl.flock(f, fcntl.LOCK_EX)
|
| 29 |
+
f.seek(0)
|
| 30 |
+
try:
|
| 31 |
+
disk = json.load(f)
|
| 32 |
+
except Exception:
|
| 33 |
+
disk = {}
|
| 34 |
+
disk.update(mem)
|
| 35 |
+
mem.update(disk)
|
| 36 |
+
f.seek(0)
|
| 37 |
+
f.truncate()
|
| 38 |
+
json.dump(disk, f)
|
| 39 |
+
fcntl.flock(f, fcntl.LOCK_UN)
|
| 40 |
+
|
| 41 |
+
def save_caches():
|
| 42 |
+
_merge_save(CACHE_DDGS, _caches['ddgs'])
|
| 43 |
+
_merge_save(CACHE_SERPER, _caches['serper'])
|
| 44 |
+
if 'searxng' in _caches:
|
| 45 |
+
_merge_save(os.path.join(DATA, 'webqa_cache_searxng.json'), _caches['searxng'])
|
| 46 |
+
_caches['searxng'] = json.load(open(os.path.join(DATA, 'webqa_cache_searxng.json'))) if os.path.exists(os.path.join(DATA, 'webqa_cache_searxng.json')) else {}
|
| 47 |
+
_cache = _caches[default_provider()]
|
| 48 |
+
SERPER_LEDGER = os.path.join(DATA, 'serper_calls.json')
|
| 49 |
+
import threading
|
| 50 |
+
_LEDGER_LOCK = threading.Lock()
|
| 51 |
+
|
| 52 |
+
def _count_serper():
|
| 53 |
+
import fcntl
|
| 54 |
+
with _LEDGER_LOCK, open(SERPER_LEDGER, 'a+') as f:
|
| 55 |
+
fcntl.flock(f, fcntl.LOCK_EX)
|
| 56 |
+
f.seek(0)
|
| 57 |
+
try:
|
| 58 |
+
d = json.load(f)
|
| 59 |
+
except Exception:
|
| 60 |
+
d = {'calls': 0}
|
| 61 |
+
d['calls'] = d.get('calls', 0) + 1
|
| 62 |
+
d['last'] = time.strftime('%Y-%m-%d %H:%M')
|
| 63 |
+
f.seek(0)
|
| 64 |
+
f.truncate()
|
| 65 |
+
json.dump(d, f)
|
| 66 |
+
fcntl.flock(f, fcntl.LOCK_UN)
|
| 67 |
+
|
| 68 |
+
def search_serper(q, k=10):
|
| 69 |
+
import urllib.request
|
| 70 |
+
for attempt in range(3):
|
| 71 |
+
try:
|
| 72 |
+
return _search_serper_once(q, k)
|
| 73 |
+
except Exception as ex:
|
| 74 |
+
if '429' not in str(ex) or attempt == 2:
|
| 75 |
+
raise
|
| 76 |
+
time.sleep(3 + 4 * attempt)
|
| 77 |
+
|
| 78 |
+
def _search_serper_once(q, k=10):
|
| 79 |
+
import urllib.request
|
| 80 |
+
_count_serper()
|
| 81 |
+
req = urllib.request.Request('https://google.serper.dev/search', data=json.dumps({'q': q, 'num': k}).encode(), headers={'X-API-KEY': os.environ['SERPER_API_KEY'], 'Content-Type': 'application/json'})
|
| 82 |
+
with urllib.request.urlopen(req, timeout=20) as r:
|
| 83 |
+
d = json.load(r)
|
| 84 |
+
out = []
|
| 85 |
+
ab = d.get('answerBox') or {}
|
| 86 |
+
if ab.get('answer') or ab.get('snippet'):
|
| 87 |
+
out.append({'title': ab.get('title', 'Answer box'), 'body': ' '.join((x for x in (ab.get('answer'), ab.get('snippet')) if x)), 'href': ab.get('link', '')})
|
| 88 |
+
kg = d.get('knowledgeGraph') or {}
|
| 89 |
+
if kg.get('description'):
|
| 90 |
+
out.append({'title': kg.get('title', ''), 'body': f"{kg.get('title', '')} is {kg.get('type', '')}. {kg['description']}", 'href': kg.get('website', '') or kg.get('descriptionLink', '')})
|
| 91 |
+
for x in d.get('organic', [])[:k]:
|
| 92 |
+
out.append({'title': x.get('title', ''), 'body': x.get('snippet', ''), 'href': x.get('link', '')})
|
| 93 |
+
return out
|
| 94 |
+
|
| 95 |
+
def search_searxng(q, k=10):
|
| 96 |
+
import urllib.request, urllib.parse
|
| 97 |
+
url = os.environ['SEARXNG_URL'].rstrip('/') + '/search?' + urllib.parse.urlencode({'q': q, 'format': 'json', 'language': 'en', 'safesearch': 0})
|
| 98 |
+
with urllib.request.urlopen(urllib.request.Request(url, headers={'User-Agent': 'moss/0.1'}), timeout=25) as r:
|
| 99 |
+
d = json.load(r)
|
| 100 |
+
out = []
|
| 101 |
+
for a in d.get('answers', [])[:2]:
|
| 102 |
+
out.append({'title': 'Answer', 'body': a if isinstance(a, str) else str(a.get('answer', a)), 'href': ''})
|
| 103 |
+
for x in d.get('results', [])[:k]:
|
| 104 |
+
out.append({'title': x.get('title', ''), 'body': x.get('content', ''), 'href': x.get('url', '')})
|
| 105 |
+
return out
|
| 106 |
+
LOCAL_DB = os.environ.get('MOSS_CORPUS_DB', os.path.join(DATA, 'corpus.sqlite'))
|
| 107 |
+
|
| 108 |
+
def _passages(text, size=420):
|
| 109 |
+
for para in re.split('\\n\\s*\\n', text):
|
| 110 |
+
para = ' '.join(para.split())
|
| 111 |
+
if not para or para.startswith('#'):
|
| 112 |
+
continue
|
| 113 |
+
cur = ''
|
| 114 |
+
for sent in _SENT.split(para):
|
| 115 |
+
if cur and len(cur) + len(sent) > size:
|
| 116 |
+
yield cur
|
| 117 |
+
cur = ''
|
| 118 |
+
cur = (cur + ' ' + sent).strip()
|
| 119 |
+
if cur:
|
| 120 |
+
yield cur
|
| 121 |
+
|
| 122 |
+
def index_corpus(src, db=LOCAL_DB):
|
| 123 |
+
import sqlite3
|
| 124 |
+
os.makedirs(os.path.dirname(os.path.abspath(db)), exist_ok=True)
|
| 125 |
+
if os.path.exists(db):
|
| 126 |
+
os.remove(db)
|
| 127 |
+
con = sqlite3.connect(db)
|
| 128 |
+
con.execute("CREATE VIRTUAL TABLE p USING fts5(title, body, href UNINDEXED, tokenize='porter unicode61')")
|
| 129 |
+
|
| 130 |
+
def docs():
|
| 131 |
+
if os.path.isfile(src) and src.endswith('.jsonl'):
|
| 132 |
+
for i, line in enumerate(open(src, encoding='utf-8', errors='ignore')):
|
| 133 |
+
d = json.loads(line)
|
| 134 |
+
yield (d.get('title') or f'document {i + 1}', d.get('text', ''), d.get('url') or f'{os.path.basename(src)}#{i + 1}')
|
| 135 |
+
return
|
| 136 |
+
for root, _, files in os.walk(src):
|
| 137 |
+
for fn in sorted(files):
|
| 138 |
+
if not fn.lower().endswith(('.txt', '.md', '.markdown')):
|
| 139 |
+
continue
|
| 140 |
+
path = os.path.join(root, fn)
|
| 141 |
+
text = open(path, encoding='utf-8', errors='ignore').read()
|
| 142 |
+
m = re.search('^#\\s+(.+)$', text, re.M)
|
| 143 |
+
title = m.group(1).strip() if m else os.path.splitext(fn)[0].replace('_', ' ').replace('-', ' ')
|
| 144 |
+
yield (title, text, 'file://' + os.path.abspath(path))
|
| 145 |
+
n = 0
|
| 146 |
+
for title, text, href in docs():
|
| 147 |
+
rows = [(title, ps, href) for ps in _passages(text)]
|
| 148 |
+
con.executemany('INSERT INTO p VALUES (?, ?, ?)', rows)
|
| 149 |
+
n += len(rows)
|
| 150 |
+
con.commit()
|
| 151 |
+
con.close()
|
| 152 |
+
return n
|
| 153 |
+
|
| 154 |
+
def search_local(q, k=10, db=LOCAL_DB):
|
| 155 |
+
import sqlite3
|
| 156 |
+
if not os.path.exists(db):
|
| 157 |
+
return []
|
| 158 |
+
terms = [t for t in re.findall('[a-z0-9]+', q.lower()) if t not in QSTOP and len(t) > 1]
|
| 159 |
+
if not terms:
|
| 160 |
+
return []
|
| 161 |
+
con = sqlite3.connect(db)
|
| 162 |
+
try:
|
| 163 |
+
rows = con.execute('SELECT title, body, href FROM p WHERE p MATCH ? ORDER BY bm25(p, 2.0, 1.0) LIMIT ?', (' OR '.join((f'"{t}"' for t in terms)), k)).fetchall()
|
| 164 |
+
finally:
|
| 165 |
+
con.close()
|
| 166 |
+
return [{'title': t, 'body': b, 'href': h} for t, b, h in rows]
|
| 167 |
+
|
| 168 |
+
def search(q, k=10, provider=None):
|
| 169 |
+
provider = provider or default_provider()
|
| 170 |
+
if provider == 'local':
|
| 171 |
+
return search_local(q, k)
|
| 172 |
+
if provider == 'serper' and (not os.environ.get('SERPER_API_KEY')):
|
| 173 |
+
provider = 'ddgs'
|
| 174 |
+
if provider == 'searxng' and (not os.environ.get('SEARXNG_URL')):
|
| 175 |
+
provider = 'ddgs'
|
| 176 |
+
c = _caches[provider]
|
| 177 |
+
if provider == 'searxng':
|
| 178 |
+
if q in c:
|
| 179 |
+
return c[q]
|
| 180 |
+
try:
|
| 181 |
+
r = search_searxng(q, k)
|
| 182 |
+
res = [{'title': clean_title(x['title']), 'body': clean_body(x['body']), 'href': x['href']} for x in r]
|
| 183 |
+
if res:
|
| 184 |
+
c[q] = res
|
| 185 |
+
return res
|
| 186 |
+
except Exception as ex:
|
| 187 |
+
print(f'[webqa] searxng failed ({type(ex).__name__}); falling back to DuckDuckGo', flush=True)
|
| 188 |
+
c = _caches['ddgs']
|
| 189 |
+
if q in c:
|
| 190 |
+
return c[q]
|
| 191 |
+
if q in c:
|
| 192 |
+
return c[q]
|
| 193 |
+
if provider == 'serper':
|
| 194 |
+
try:
|
| 195 |
+
r = search_serper(q, k)
|
| 196 |
+
res = [{'title': clean_title(x['title']), 'body': clean_body(x['body']), 'href': x['href']} for x in r]
|
| 197 |
+
if res:
|
| 198 |
+
c[q] = res
|
| 199 |
+
return res
|
| 200 |
+
except Exception as ex:
|
| 201 |
+
print(f'[webqa] serper failed ({type(ex).__name__}); falling back to DuckDuckGo', flush=True)
|
| 202 |
+
c = _caches['ddgs']
|
| 203 |
+
if q in c:
|
| 204 |
+
return c[q]
|
| 205 |
+
from ddgs import DDGS
|
| 206 |
+
r = []
|
| 207 |
+
for attempt, backend in enumerate(('auto', 'google', 'bing', 'auto')):
|
| 208 |
+
try:
|
| 209 |
+
r = DDGS().text(q, max_results=k, backend=backend) or []
|
| 210 |
+
if r:
|
| 211 |
+
break
|
| 212 |
+
except Exception as ex:
|
| 213 |
+
r = []
|
| 214 |
+
time.sleep(1.5 + 2 * attempt)
|
| 215 |
+
res = [{'title': clean_title(x.get('title', '')), 'body': clean_body(x.get('body', '')), 'href': x.get('href', '')} for x in r]
|
| 216 |
+
if res:
|
| 217 |
+
c[q] = res
|
| 218 |
+
return res
|
| 219 |
+
_SENT = re.compile('(?<=[.!?])\\s+(?=[A-Z0-9\\"\'(])')
|
| 220 |
+
_DATE = re.compile('^(?:[A-Z][a-z]{2} \\d{1,2}, \\d{4}|\\d{1,2} [A-Z][a-z]{2} \\d{4})\\s*[·•-]\\s*')
|
| 221 |
+
|
| 222 |
+
def clean_title(t):
|
| 223 |
+
t = re.sub('([a-z]{4,})([A-Z][a-z]{2,})', '\\1 | \\2', t.strip())
|
| 224 |
+
t = re.split('\\s+\\|\\s+', t.strip())[0]
|
| 225 |
+
return t[:110].rstrip()
|
| 226 |
+
|
| 227 |
+
def clean_body(b):
|
| 228 |
+
return _DATE.sub('', b.strip())
|
| 229 |
+
STRICT = os.environ.get('MOSS_STRICT') == '1'
|
| 230 |
+
BLOCK = [d for d in os.environ.get('MOSS_BLOCK_DOMAINS', 'huggingface.co,kaggle.com,github.com,paperswithcode.com,simple-evals,simpleqa,freshqa,popqa').split(',') if d]
|
| 231 |
+
PAGES = int(os.environ.get('MOSS_PAGES', '0'))
|
| 232 |
+
PAGE_DIR = os.path.join(DATA, 'pages')
|
| 233 |
+
os.makedirs(PAGE_DIR, exist_ok=True)
|
| 234 |
+
_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36'
|
| 235 |
+
|
| 236 |
+
def fetch_text(url, timeout=12):
|
| 237 |
+
import hashlib, urllib.request, socket
|
| 238 |
+
socket.setdefaulttimeout(timeout)
|
| 239 |
+
p = os.path.join(PAGE_DIR, hashlib.sha1(url.encode()).hexdigest() + '.txt')
|
| 240 |
+
if os.path.exists(p):
|
| 241 |
+
return open(p).read()
|
| 242 |
+
txt = ''
|
| 243 |
+
try:
|
| 244 |
+
import trafilatura
|
| 245 |
+
req = urllib.request.Request(url, headers={'User-Agent': _UA, 'Accept-Language': 'en'})
|
| 246 |
+
html = urllib.request.urlopen(req, timeout=timeout).read(2000000).decode('utf-8', 'ignore')
|
| 247 |
+
txt = trafilatura.extract(html, include_comments=False, include_tables=True) or ''
|
| 248 |
+
except Exception:
|
| 249 |
+
txt = ''
|
| 250 |
+
open(p, 'w').write(txt)
|
| 251 |
+
return txt
|
| 252 |
+
|
| 253 |
+
def page_candidates(q, results, n_pages, cap=150):
|
| 254 |
+
qt = {t for t in re.findall('[a-z0-9]+', q.lower()) if t not in QWORDS and len(t) > 2}
|
| 255 |
+
out = []
|
| 256 |
+
for r in results[:n_pages]:
|
| 257 |
+
if not r.get('href') or any((b in r['href'].lower() for b in BLOCK)):
|
| 258 |
+
continue
|
| 259 |
+
txt = fetch_text(r['href'])
|
| 260 |
+
for s in _SENT.split(' '.join(txt.split())):
|
| 261 |
+
s = s.strip()
|
| 262 |
+
if 25 <= len(s) <= 400 and len(qt & set(re.findall('[a-z0-9]+', s.lower()))) >= max(1, min(2, len(qt) // 3)):
|
| 263 |
+
out.append({'sent': s, 'title': r['title'], 'url': r['href'], 'body': s, 'from_page': True})
|
| 264 |
+
if len(out) > cap:
|
| 265 |
+
out.sort(key=lambda c: -len(qt & set(re.findall('[a-z0-9]+', c['sent'].lower()))))
|
| 266 |
+
out = out[:cap]
|
| 267 |
+
return out
|
| 268 |
+
PROSE = os.environ.get('MOSS_PROSE', '1') == '1'
|
| 269 |
+
SOURCE_PENALTY = os.environ.get('MOSS_SOURCE_PENALTY', '0') == '1'
|
| 270 |
+
QUOTABLE = os.environ.get('MOSS_QUOTABLE', '0') == '1'
|
| 271 |
+
SOCIAL = ('reddit.com', 'quora.com', 'facebook.com', 'instagram.com', 'tiktok.com', 'pinterest.', 'youtube.com', 'answers.com', 'brainly.', 'quizlet', 'x.com/', 'twitter.com')
|
| 272 |
+
_ROW = re.compile('^\\s*\\d+[.,)]\\s')
|
| 273 |
+
|
| 274 |
+
def is_prose(s):
|
| 275 |
+
if len(re.findall('[A-Za-z]{3,}', s)) < 4 or _ROW.match(s) or '|' in s or (s.count('·') >= 2):
|
| 276 |
+
return False
|
| 277 |
+
if ';' in s and len(s.split()) < 10:
|
| 278 |
+
return False
|
| 279 |
+
words = s.split()
|
| 280 |
+
if s.count(' – ') + s.count(' — ') >= 4:
|
| 281 |
+
return False
|
| 282 |
+
if len(words) > 45 and (s.count(' – ') + s.count(' — ') >= 2 or sum((w[:1].isupper() for w in words)) / len(words) > 0.5):
|
| 283 |
+
return False
|
| 284 |
+
return sum((1 for ch in s if ch.isdigit() or ch in ',;·|')) / max(1, len(s)) <= 0.25
|
| 285 |
+
CUTS = os.environ.get('MOSS_CUTS', '1') == '1'
|
| 286 |
+
_GLUE = re.compile('(?<=[a-z0-9][.!?])(?=[A-Z][a-z])|\\s*(?:\\.\\.\\.|…)\\s*')
|
| 287 |
+
|
| 288 |
+
def cuts(s):
|
| 289 |
+
parts = [p.strip(' ,;:') for p in _GLUE.split(s)]
|
| 290 |
+
parts = [p for p in parts if len(p) > 15]
|
| 291 |
+
return parts if len(parts) > 1 else []
|
| 292 |
+
_BOILER = re.compile('^(?:See full list on \\S+\\s*)?(?:[A-Z][a-z]{2}\\.? \\d{1,2}, \\d{4}\\s*[·—–-]\\s*)?(?:\\d{1,2} [A-Z][a-z]{2,8} \\d{4}\\s*[·—–-]\\s*)?')
|
| 293 |
+
|
| 294 |
+
def candidates(results, q=None):
|
| 295 |
+
out = []
|
| 296 |
+
if PAGES and q:
|
| 297 |
+
out += page_candidates(q, results, PAGES)
|
| 298 |
+
for r in results:
|
| 299 |
+
if any((b in (r.get('href', '') + ' ' + r.get('title', '')).lower() for b in BLOCK)):
|
| 300 |
+
continue
|
| 301 |
+
for s in _SENT.split(re.sub('\\s*\\[\\d{1,3}\\]', '', r['body']).strip()):
|
| 302 |
+
s = _BOILER.sub('', s.strip()).strip()
|
| 303 |
+
for t in [s] + (cuts(s) if CUTS else []):
|
| 304 |
+
if len(t) > 15 and (not PROSE or is_prose(t)):
|
| 305 |
+
out.append({'sent': t, 'title': clean_title(r['title']), 'url': r['href'], 'body': r['body']})
|
| 306 |
+
return out
|
| 307 |
+
|
| 308 |
+
def _cap(t):
|
| 309 |
+
return t[:1].upper() + t[1:]
|
| 310 |
+
_PAST = {'end': 'ended', 'begin': 'began', 'start': 'started', 'happen': 'happened', 'die': 'died', 'occur': 'occurred', 'open': 'opened', 'close': 'closed', 'finish': 'finished', 'take place': 'took place'}
|
| 311 |
+
|
| 312 |
+
def lead(q, span):
|
| 313 |
+
s = re.sub('\\s+', ' ', q.strip().rstrip('?').strip())
|
| 314 |
+
b = f'**{span}**'
|
| 315 |
+
prep = '' if re.match('^(?:between|from|in|on|at|during|around|about|circa|since|after|before)\\b', span, re.I) else 'in '
|
| 316 |
+
m = re.match('^who (was|is|were|are) (.+)$', s, re.I)
|
| 317 |
+
if m:
|
| 318 |
+
return f'{_cap(m.group(2))} {m.group(1).lower()} {b}.'
|
| 319 |
+
m = re.match('^who (founded|created|invented|wrote|directed|discovered|built|designed|painted|composed|developed|produced|started|established|won|scored) (.+)$', s, re.I)
|
| 320 |
+
if m:
|
| 321 |
+
return f'{_cap(m.group(2))} was {m.group(1).lower()} by {b}.'
|
| 322 |
+
m = re.match('^(what|which) (is|was|are|were) (.+)$', s, re.I)
|
| 323 |
+
if m:
|
| 324 |
+
return f'{_cap(m.group(3))} {m.group(2).lower()} {b}.'
|
| 325 |
+
m = re.match('^where (is|was|are|were) (.+?)(?: located| based| situated)?$', s, re.I)
|
| 326 |
+
if m:
|
| 327 |
+
return f'{_cap(m.group(2))} {m.group(1).lower()} {prep}{b}.'
|
| 328 |
+
m = re.match('^when (was|were|is) (.+?) (born|founded|released|built|established|created|published|launched|invented|discovered|completed|opened|formed|made|written|elected|crowned|signed)$', s, re.I)
|
| 329 |
+
if m:
|
| 330 |
+
return f'{_cap(m.group(2))} {m.group(1).lower()} {m.group(3).lower()} {prep}{b}.'
|
| 331 |
+
m = re.match('^when did (.+?) (end|begin|start|happen|die|occur|open|close|take place|finish)$', s, re.I)
|
| 332 |
+
if m:
|
| 333 |
+
return f'{_cap(m.group(1))} {_PAST[m.group(2).lower()]} {prep}{b}.'
|
| 334 |
+
return None
|
| 335 |
+
QSTOP = {'who', 'what', 'when', 'where', 'which', 'was', 'is', 'are', 'were', 'the', 'did', 'does', 'for', 'of', 'in', 'on', 'at', 'to', 'and', 'how', 'many', 'much', 'a', 'an', 'by', 'from', 'with', 'do', 'has', 'have', 'had', 'that', 'this'}
|
| 336 |
+
VERBALIZE = os.environ.get('MOSS_VERBALIZE', 'template')
|
| 337 |
+
DECODER_URL = os.environ.get('MOSS_DECODER', 'http://127.0.0.1:8089')
|
| 338 |
+
PLANNER_URL = os.environ.get('MOSS_PLANNER', 'http://127.0.0.1:8093')
|
| 339 |
+
VERBALISER_URL = os.environ.get('MOSS_VERBALISER', '')
|
| 340 |
+
VERB_TAU = float(os.environ.get('MOSS_VERB_TAU', '0.0'))
|
| 341 |
+
VERB_SPAN = os.environ.get('MOSS_VERB_SPAN', '0') == '1'
|
| 342 |
+
_FUNC = {'the', 'a', 'an', 'is', 'was', 'are', 'were', 'of', 'in', 'on', 'at', 'to', 'for', 'by', 'and', 'or', 'with', 'from', 'as', 'its', 'it', 'that', 'this', 'which', 'who', 'what', 'when', 'where', 'how', 'did', 'does', 'do', 'has', 'have', 'had', 'been', 'be', 'named', 'called', 's'}
|
| 343 |
+
|
| 344 |
+
def _wordsl(t):
|
| 345 |
+
return re.findall('[a-z0-9]+', t.lower())
|
| 346 |
+
|
| 347 |
+
def _post_json(url, body, timeout=20):
|
| 348 |
+
import urllib.request
|
| 349 |
+
req = urllib.request.Request(url, data=json.dumps(body).encode(), headers={'Content-Type': 'application/json'})
|
| 350 |
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
| 351 |
+
return json.loads(r.read())
|
| 352 |
+
|
| 353 |
+
def _tidy_lead(t):
|
| 354 |
+
t = re.sub('\\s+', ' ', t).strip().rstrip('.').strip()
|
| 355 |
+
return t[:1].upper() + t[1:] + '.' if t else t
|
| 356 |
+
|
| 357 |
+
def own_lead(q, span, cited, title, natural=True, vscore=None, info=None, q_user=None):
|
| 358 |
+
import collections
|
| 359 |
+
qc = collections.Counter(_wordsl(q))
|
| 360 |
+
sw = set(_wordsl(span))
|
| 361 |
+
ew = set(_wordsl(cited)) | set(_wordsl(title)) if natural else set()
|
| 362 |
+
for w, n in collections.Counter(_wordsl(q_user or '')).items():
|
| 363 |
+
qc[w] = max(qc[w], n)
|
| 364 |
+
|
| 365 |
+
def content_free(text):
|
| 366 |
+
cc = collections.Counter((w for w in _wordsl(text) if w not in _FUNC and w not in sw))
|
| 367 |
+
return all((w in qc and cc[w] <= qc[w] or w in ew for w in cc))
|
| 368 |
+
if VERBALISER_URL and natural:
|
| 369 |
+
try:
|
| 370 |
+
vp = f'<|evidence|>\n[E1] ({title}) {cited}\n<|question|> {q.strip()}\n' + (f'<|span|> {span.strip()}\n' if VERB_SPAN else '') + '<|answer|>'
|
| 371 |
+
d = _post_json(f'{VERBALISER_URL}/completion', {'prompt': vp, 'n_predict': 64, 'temperature': 0.0, 'stop': ['<|end|>'], 'cache_prompt': False}, timeout=10)
|
| 372 |
+
t = re.sub('\\s+', ' ', d.get('content', '').split('<|end|>')[0]).strip()
|
| 373 |
+
v = None
|
| 374 |
+
ok = t and t != '<abstain>' and (3 <= len(t.split()) <= 45) and (normalize(span) in normalize(t)) and content_free(t)
|
| 375 |
+
if ok and vscore is not None:
|
| 376 |
+
v = float(vscore(t))
|
| 377 |
+
ok = v >= VERB_TAU
|
| 378 |
+
if info is not None:
|
| 379 |
+
info.update({'verbaliser': t or None, 'verbaliser_v': None if v is None else round(v, 2)})
|
| 380 |
+
if ok:
|
| 381 |
+
i = t.lower().find(span.lower())
|
| 382 |
+
t = t[:i] + f'**{t[i:i + len(span)]}**' + t[i + len(span):] if i >= 0 else t
|
| 383 |
+
return (_tidy_lead(t), 'verbaliser')
|
| 384 |
+
except Exception:
|
| 385 |
+
pass
|
| 386 |
+
try:
|
| 387 |
+
g = gbnf(1, allowed=[1]).replace('root ::= "<abstain>" | answer', 'root ::= answer')
|
| 388 |
+
d = _post_json(f'{DECODER_URL}/completion', {'prompt': f'<|evidence|>\n[E1] ({title}) {cited}\n<|question|> {q.strip()}\n<|answer|>', 'n_predict': 40, 'temperature': 0.0, 'stop': ['<|end|>'], 'grammar': g, 'cache_prompt': False}, timeout=10)
|
| 389 |
+
parts, abst = parse_answer(d.get('content', ''))
|
| 390 |
+
if not abst and sum((1 for k, _ in parts if k == 'ref')) == 1:
|
| 391 |
+
glue = ' '.join((v for k, v in parts if k == 'glue'))
|
| 392 |
+
inserted = normalize(span) not in normalize(glue)
|
| 393 |
+
if not inserted:
|
| 394 |
+
t = ''.join(('' if k == 'ref' else v for k, v in parts))
|
| 395 |
+
i = t.find(span)
|
| 396 |
+
t = t[:i] + f'**{span}**' + t[i + len(span):] if i >= 0 else t
|
| 397 |
+
else:
|
| 398 |
+
t = ''.join((f'**{span}**' if k == 'ref' else v for k, v in parts))
|
| 399 |
+
dup = bool((set(_wordsl(glue)) & sw) - (set(qc) if natural else set())) and (inserted or not natural)
|
| 400 |
+
if content_free(glue) and (not dup) and (3 <= len(t.split()) <= 30):
|
| 401 |
+
return (_tidy_lead(t), 'decoder')
|
| 402 |
+
except Exception:
|
| 403 |
+
pass
|
| 404 |
+
try:
|
| 405 |
+
d = _post_json(f'{PLANNER_URL}/completion', {'prompt': f'<|question|> {q.strip()}\n<|plan|>', 'n_predict': 200, 'temperature': 0.0, 'stop': ['<|end|>'], 'cache_prompt': False}, timeout=15)
|
| 406 |
+
m = re.search('"hypothetical"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"', d.get('content', ''))
|
| 407 |
+
hyp = json.loads('"' + m.group(1) + '"') if m else ''
|
| 408 |
+
if hyp.count('____') == 1 and content_free(hyp.replace('____', ' ')) and (3 <= len(hyp.split()) <= 30):
|
| 409 |
+
return (_tidy_lead(hyp.replace('____', f'**{span}**')), 'planner')
|
| 410 |
+
except Exception:
|
| 411 |
+
pass
|
| 412 |
+
return (None, None)
|
| 413 |
+
|
| 414 |
+
def quote_clean(q, sent, span):
|
| 415 |
+
if not sent or len(sent) > 230 or sent.rstrip()[-1:] not in '.!?' or ('...' in sent) or ('…' in sent):
|
| 416 |
+
return False
|
| 417 |
+
if span and normalize(span) not in normalize(sent):
|
| 418 |
+
return False
|
| 419 |
+
cw = [w for w in re.findall('[a-z0-9]+', q.lower()) if w not in QSTOP and len(w) > 2]
|
| 420 |
+
ns = normalize(sent)
|
| 421 |
+
return sum((1 for w in cw if w in ns)) >= max(1, len(cw) // 2)
|
| 422 |
+
FALLBACK = os.environ.get('MOSS_FALLBACK', '0') == '1'
|
| 423 |
+
RETRY_TAU = float(os.environ.get('MOSS_RETRY_TAU', '5.5'))
|
| 424 |
+
PLANNER_RETRY = os.environ.get('MOSS_PLANNER_RETRY', '0') == '1'
|
| 425 |
+
RETRY_PROVIDER = os.environ.get('MOSS_RETRY_PROVIDER', 'serper')
|
| 426 |
+
AGREE = int(os.environ.get('MOSS_AGREE', '3'))
|
| 427 |
+
SIEVE_RETRY = os.environ.get('MOSS_SIEVE_RETRY', '0') == '1'
|
| 428 |
+
_NAMES = re.compile("\\b[A-Z][\\w'’.-]+(?:\\s+(?:(?:de|da|van|von|of|the|du|del|di|la|le|&)\\s+)?[A-Z][\\w'’.-]+){0,3}")
|
| 429 |
+
_QCAP = {'The', 'This', 'That', 'What', 'When', 'Where', 'Which', 'Who', 'How', 'Why', 'In', 'On', 'At', 'For', 'From', 'With', 'Name', 'Is', 'Was', 'Are', 'Were', 'Did', 'Does', 'Do'}
|
| 430 |
+
_FORUMS = '-site:reddit.com -site:quora.com -site:facebook.com -site:pinterest.com -site:youtube.com -site:answers.com'
|
| 431 |
+
|
| 432 |
+
def retry_queries(q):
|
| 433 |
+
out = [('noforum', f"{q.rstrip('?')} {_FORUMS}")]
|
| 434 |
+
ns = [m.strip() for m in _NAMES.findall(q) if m.split()[0] not in _QCAP and len(m) > 2]
|
| 435 |
+
if ns:
|
| 436 |
+
rest = q
|
| 437 |
+
for n in ns:
|
| 438 |
+
rest = rest.replace(n, '')
|
| 439 |
+
rest = re.sub('^\\s*(who|what|which|when|where|how)\\s+(was|is|were|are|did|does|do)\\s+', '', rest.strip().rstrip('?'), flags=re.I)
|
| 440 |
+
out.append(('names', ' '.join((f'"{n}"' for n in ns)) + ' ' + re.sub('\\s+', ' ', rest).strip()))
|
| 441 |
+
l = lead(q, '')
|
| 442 |
+
if l:
|
| 443 |
+
l = l.replace(' ****.', '').replace('****.', '').strip().rstrip('.')
|
| 444 |
+
if 3 <= len(l.split()) <= 12:
|
| 445 |
+
out.append(('stub', f'"{l}"'))
|
| 446 |
+
if PLANNER_RETRY:
|
| 447 |
+
try:
|
| 448 |
+
d = _post_json(f'{PLANNER_URL}/completion', {'prompt': f'<|question|> {q.strip()}\n<|plan|>', 'n_predict': 240, 'temperature': 0.0, 'stop': ['<|end|>'], 'cache_prompt': False}, timeout=15)
|
| 449 |
+
txt = d.get('content', '')
|
| 450 |
+
m = re.search('"hypothetical"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"', txt)
|
| 451 |
+
hyp = json.loads('"' + m.group(1) + '"') if m else ''
|
| 452 |
+
terms = re.findall('"([^"]{2,40})"', txt.split('"search_terms"')[1].split(']')[0]) if '"search_terms"' in txt else []
|
| 453 |
+
ents = re.findall('"([^"]{2,40})"', txt.split('"entities"')[1].split(']')[0]) if '"entities"' in txt else []
|
| 454 |
+
tq = ' '.join(dict.fromkeys(ents + terms))
|
| 455 |
+
if len(tq.split()) >= 2:
|
| 456 |
+
out.append(('plan_terms', tq[:160]))
|
| 457 |
+
h = re.sub('\\s+', ' ', hyp.replace('____', ' ')).strip(' .')
|
| 458 |
+
import collections as _c
|
| 459 |
+
qc = _c.Counter(_wordsl(q))
|
| 460 |
+
hc = _c.Counter((w for w in _wordsl(h) if w not in _FUNC))
|
| 461 |
+
if 3 <= len(h.split()) <= 14 and all((hc[w] <= qc.get(w, 0) + (0 if w in qc else 1) for w in hc)):
|
| 462 |
+
out.append(('plan_stub', f'"{h}"'))
|
| 463 |
+
except Exception:
|
| 464 |
+
pass
|
| 465 |
+
return out
|
| 466 |
+
SPELL = os.environ.get('MOSS_SPELL', '1') == '1'
|
| 467 |
+
TAU_V = float(os.environ.get('MOSS_TAU_V', '3.0'))
|
| 468 |
+
|
| 469 |
+
def _lev(a, b):
|
| 470 |
+
if abs(len(a) - len(b)) > 3:
|
| 471 |
+
return 9
|
| 472 |
+
d = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]
|
| 473 |
+
for i in range(len(a) + 1):
|
| 474 |
+
d[i][0] = i
|
| 475 |
+
for j in range(len(b) + 1):
|
| 476 |
+
d[0][j] = j
|
| 477 |
+
for i in range(1, len(a) + 1):
|
| 478 |
+
for j in range(1, len(b) + 1):
|
| 479 |
+
c = a[i - 1] != b[j - 1]
|
| 480 |
+
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + c)
|
| 481 |
+
if i > 1 and j > 1 and (a[i - 1] == b[j - 2]) and (a[i - 2] == b[j - 1]):
|
| 482 |
+
d[i][j] = min(d[i][j], d[i - 2][j - 2] + 1)
|
| 483 |
+
return d[-1][-1]
|
| 484 |
+
|
| 485 |
+
def corpus_spelling(q, results):
|
| 486 |
+
import collections
|
| 487 |
+
vocab = collections.Counter()
|
| 488 |
+
for r in results:
|
| 489 |
+
for w in set(re.findall('[a-z]{4,}', (r.get('title', '') + ' ' + r.get('body', '')).lower())):
|
| 490 |
+
vocab[w] += 1
|
| 491 |
+
fixes = {}
|
| 492 |
+
for w in re.findall('\\b[a-z]{5,}\\b', q):
|
| 493 |
+
if w in vocab or w in QSTOP or w in _FUNC:
|
| 494 |
+
continue
|
| 495 |
+
best = min(((_lev(w, v), -n, v) for v, n in vocab.items() if n >= 2 and abs(len(v) - len(w)) <= 3), default=None)
|
| 496 |
+
if best and 0 < best[0] <= (3 if len(w) >= 8 else 2):
|
| 497 |
+
fixes[w] = best[2]
|
| 498 |
+
out = q
|
| 499 |
+
for w, v in fixes.items():
|
| 500 |
+
out = re.sub('\\b' + re.escape(w) + '\\b', v, out)
|
| 501 |
+
return (out, fixes)
|
| 502 |
+
QWORDS = set('a an the of in on at to for by with and or is are was were be been being who what when where which how why did does do that this these those it its as from into than then there their his her he she they them many much can could should would will i you my me your have has had not no about tell explain give list name wont dont cant whats isnt doesnt didnt im ive'.split())
|
| 503 |
+
MAX_EVIDENCE = 16
|
| 504 |
+
REF_TOKENS = [f'<q E{i}>' for i in range(1, MAX_EVIDENCE + 1)]
|
| 505 |
+
ABSTAIN = '<abstain>'
|
| 506 |
+
BOS_EVIDENCE, BOS_QUESTION, BOS_ANSWER, EOS_ANSWER = ('<|evidence|>', '<|question|>', '<|answer|>', '<|end|>')
|
| 507 |
+
|
| 508 |
+
def gbnf(n_evidence: int, max_glue_tokens: int=40, allowed: list[int] | None=None) -> str:
|
| 509 |
+
ids = allowed or list(range(1, n_evidence + 1))
|
| 510 |
+
refs = ' | '.join((f'"<q E{i}>"' for i in ids))
|
| 511 |
+
return f'root ::= "{ABSTAIN}" | answer\nanswer ::= segment+ glue?\nsegment ::= glue? ref\nref ::= {refs}\nglue ::= [^<]{{1,{max_glue_tokens * 5}}}\n'
|
| 512 |
+
REF_RE = re.compile('<q E(\\d+)>')
|
| 513 |
+
|
| 514 |
+
def parse_answer(text: str) -> tuple[list[tuple[str, str]], bool]:
|
| 515 |
+
text = text.split(EOS_ANSWER)[0].strip()
|
| 516 |
+
if text.startswith(ABSTAIN):
|
| 517 |
+
return ([], True)
|
| 518 |
+
parts: list[tuple[str, str]] = []
|
| 519 |
+
pos = 0
|
| 520 |
+
for m in REF_RE.finditer(text):
|
| 521 |
+
glue = text[pos:m.start()]
|
| 522 |
+
if glue.strip():
|
| 523 |
+
parts.append(('glue', glue))
|
| 524 |
+
parts.append(('ref', f'E{m.group(1)}'))
|
| 525 |
+
pos = m.end()
|
| 526 |
+
tail = text[pos:]
|
| 527 |
+
if tail.strip():
|
| 528 |
+
parts.append(('glue', tail))
|
| 529 |
+
return (parts, False)
|
| 530 |
+
|
| 531 |
+
class Stack:
|
| 532 |
+
|
| 533 |
+
def __init__(self):
|
| 534 |
+
from sentence_transformers import CrossEncoder
|
| 535 |
+
dev = os.environ.get('MOSS_DEVICE', 'cpu')
|
| 536 |
+
self.rank = CrossEncoder(os.environ.get('MOSS_RANKER') or os.path.join(BK, 'models', 'ranker'), max_length=256, device=dev)
|
| 537 |
+
self.verify = CrossEncoder(os.environ.get('MOSS_VERIFIER') or os.path.join(BK, 'models', 'verifier'), max_length=256, device=dev)
|
| 538 |
+
from .extract import extract as _extract
|
| 539 |
+
self.extract = _extract
|
| 540 |
+
self.hhem = None
|
| 541 |
+
if os.environ.get('MOSS_HHEM') == '1':
|
| 542 |
+
try:
|
| 543 |
+
from transformers import AutoModelForSequenceClassification
|
| 544 |
+
self.hhem = AutoModelForSequenceClassification.from_pretrained('vectara/hallucination_evaluation_model', trust_remote_code=True)
|
| 545 |
+
except Exception as ex:
|
| 546 |
+
print(f'[webqa] HHEM unavailable: {type(ex).__name__}: {str(ex)[:120]}', flush=True)
|
| 547 |
+
|
| 548 |
+
def _sieve(self):
|
| 549 |
+
if not hasattr(self, '_sv'):
|
| 550 |
+
from .sieve import Sieve
|
| 551 |
+
sv = Sieve.__new__(Sieve)
|
| 552 |
+
sv.verify = self.verify
|
| 553 |
+
self._sv = sv
|
| 554 |
+
return self._sv
|
| 555 |
+
|
| 556 |
+
def answer_iter(self, q, tau_v=None, tau_lo=-4.0, provider=None, verbalize=None):
|
| 557 |
+
if tau_v is None:
|
| 558 |
+
tau_v = TAU_V
|
| 559 |
+
t0 = time.time()
|
| 560 |
+
res = search(q, provider=provider)
|
| 561 |
+
t1 = time.time()
|
| 562 |
+
q_user = q
|
| 563 |
+
fixes = {}
|
| 564 |
+
if SPELL and res:
|
| 565 |
+
q, fixes = corpus_spelling(q, res)
|
| 566 |
+
yield {'stage': 'search', 'ms': round(1000 * (t1 - t0)), 'n': len(res), 'cached': t1 - t0 < 0.05, 'provider': provider or default_provider(), 'spelled': fixes or None}
|
| 567 |
+
cands = candidates(res, q)
|
| 568 |
+
if not cands:
|
| 569 |
+
yield {'stage': 'done', 'tier': 3, 'why': 'no results', 'ms_search': round(1000 * (t1 - t0)), 'ms_models': 0, 'results': res}
|
| 570 |
+
return
|
| 571 |
+
ta = time.time()
|
| 572 |
+
s1 = self.rank.predict([(q, f"{c['title']}. {c['sent']}") for c in cands], batch_size=32, show_progress_bar=False)
|
| 573 |
+
order = sorted(range(len(cands)), key=lambda i: -float(s1[i]))[:8]
|
| 574 |
+
tb = time.time()
|
| 575 |
+
yield {'stage': 'rank', 'ms': round(1000 * (tb - ta)), 'n': len(cands), 'top': [cands[i]['sent'][:90] for i in order[:3]]}
|
| 576 |
+
s2 = self.verify.predict([(q, f"{cands[i]['title']}. {cands[i]['sent']}") for i in order], batch_size=32, show_progress_bar=False)
|
| 577 |
+
pen = (lambda c: 2.5 if any((f in c['url'].lower() for f in SOCIAL)) else 0.0) if SOURCE_PENALTY else lambda c: 0.0
|
| 578 |
+
|
| 579 |
+
def quotable(c):
|
| 580 |
+
if not QUOTABLE:
|
| 581 |
+
return 0.0
|
| 582 |
+
t = c['sent']
|
| 583 |
+
return (0.3 if t[-1:] in '.!?' else 0.0) + (0.3 if len(t) <= 220 else 0.0) + (0.2 if t[:1].isupper() else 0.0) - (0.5 if '...' in t or '…' in t else 0.0)
|
| 584 |
+
ver = [j for j in range(len(order)) if float(s2[j]) >= tau_v]
|
| 585 |
+
best = max(ver, key=lambda j: float(s2[j]) - pen(cands[order[j]]) + quotable(cands[order[j]])) if ver else max(range(len(order)), key=lambda j: float(s2[j]))
|
| 586 |
+
c = cands[order[best]]
|
| 587 |
+
score2 = float(s2[best])
|
| 588 |
+
tc = time.time()
|
| 589 |
+
tier = 1 if score2 >= tau_v else 2 if score2 >= tau_lo else 3
|
| 590 |
+
yield {'stage': 'verify', 'ms': round(1000 * (tc - tb)), 'score': round(score2, 2), 'tier': tier}
|
| 591 |
+
retry = None
|
| 592 |
+
if FALLBACK and tier != 1:
|
| 593 |
+
rprov = RETRY_PROVIDER if RETRY_PROVIDER == 'serper' and os.environ.get('SERPER_API_KEY') else provider
|
| 594 |
+
for name, rq in retry_queries(q):
|
| 595 |
+
tr = time.time()
|
| 596 |
+
more = [x for x in candidates(search(rq, provider=rprov), q) if x['sent'] not in {cc['sent'] for cc in cands}]
|
| 597 |
+
if not more:
|
| 598 |
+
continue
|
| 599 |
+
r1 = self.rank.predict([(q, f"{x['title']}. {x['sent']}") for x in more], batch_size=32, show_progress_bar=False)
|
| 600 |
+
ro = sorted(range(len(more)), key=lambda i: -float(r1[i]))[:8]
|
| 601 |
+
r2 = self.verify.predict([(q, f"{more[i]['title']}. {more[i]['sent']}") for i in ro], batch_size=32, show_progress_bar=False)
|
| 602 |
+
rb = max(range(len(ro)), key=lambda j: float(r2[j]) - pen(more[ro[j]]) + quotable(more[ro[j]]))
|
| 603 |
+
rv = float(r2[rb])
|
| 604 |
+
yield {'stage': 'retry', 'ms': round(1000 * (time.time() - tr)), 'query': rq, 'name': name, 'score': round(rv, 2), 'n': len(more), 'taken': rv >= RETRY_TAU}
|
| 605 |
+
if rv >= RETRY_TAU:
|
| 606 |
+
c = more[ro[rb]]
|
| 607 |
+
score2 = rv
|
| 608 |
+
tier = 1
|
| 609 |
+
retry = name
|
| 610 |
+
res = res + search(rq, provider=rprov)
|
| 611 |
+
break
|
| 612 |
+
tc = time.time()
|
| 613 |
+
span = self.extract(q, [(f"{c['title'].split(' | ')[0].strip()}. {c['body']}", 'E1')], answer_type=None)
|
| 614 |
+
if span:
|
| 615 |
+
span['answer'] = re.sub('\\b(\\w+)\\1\\b', '\\1', span['answer']).strip()
|
| 616 |
+
span['answer'] = re.sub('\\b(\\w+(?:\\s\\w+)?)\\s+\\1\\b', '\\1', span['answer']).strip()
|
| 617 |
+
if not span and re.match('^(?:who|which)\\b', q.strip(), re.I):
|
| 618 |
+
head = re.split('\\s+[-|—–:]\\s+', c['title'])[0].strip()
|
| 619 |
+
if 2 <= len(head.split()) <= 5 and head[:1].isupper():
|
| 620 |
+
span = {'answer': head, 'score': 0.0, 'kind': 'title'}
|
| 621 |
+
spans = {}
|
| 622 |
+
for j, i in enumerate(order if os.environ.get('MOSS_CONSENSUS') == '1' else []):
|
| 623 |
+
cj = cands[i]
|
| 624 |
+
sp = self.extract(q, [(f"{cj['title'].split(' | ')[0].strip()}. {cj['body']}", 'E1')], answer_type=None)
|
| 625 |
+
if not sp:
|
| 626 |
+
continue
|
| 627 |
+
key = normalize(re.sub('\\b(\\w+)\\1\\b', '\\1', sp['answer']))
|
| 628 |
+
if not key or len(key) > 80:
|
| 629 |
+
continue
|
| 630 |
+
e = spans.setdefault(key, {'answer': sp['answer'], 'sources': set(), 'best_v': -99.0, 'cand': None})
|
| 631 |
+
e['best_v'] = max(e['best_v'], float(s2[j]))
|
| 632 |
+
e['cand'] = e['cand'] or cj
|
| 633 |
+
for key, e in spans.items():
|
| 634 |
+
e['sources'] = {r['href'] for r in res if key in normalize(r['title'] + ' ' + r['body'])}
|
| 635 |
+
cons = max(spans.values(), key=lambda e: (len(e['sources']), e['best_v'])) if spans else None
|
| 636 |
+
pkey = normalize(span['answer']) if span else ''
|
| 637 |
+
support = len({r.get('href') or r['body'] for r in res if pkey and pkey in normalize(r['title'] + ' ' + r['body'])}) if span else 0
|
| 638 |
+
if STRICT and tier == 1 and (support < 2):
|
| 639 |
+
tier = 2
|
| 640 |
+
verified_by = 'verifier' if tier == 1 else None
|
| 641 |
+
if AGREE and tier != 1 and span and (support >= AGREE) and (score2 >= 0.0):
|
| 642 |
+
tier = 1
|
| 643 |
+
verified_by = 'agreement'
|
| 644 |
+
sieve_ev = None
|
| 645 |
+
if SIEVE_RETRY and tier != 1 and re.match('^(?:which|who)\\b', q.strip(), re.I) and (not span or support <= 1):
|
| 646 |
+
try:
|
| 647 |
+
ts = time.time()
|
| 648 |
+
sv = self._sieve()
|
| 649 |
+
out = sv.run(q, provider=rprov if FALLBACK else provider, k_ent=8) or {}
|
| 650 |
+
ent = out.get('sieve')
|
| 651 |
+
ok = ent and out.get('of') and (out['covered'] >= max(2, out['of'] - 1)) and (out.get('runner_up') is None or out['covered'] > (out.get('runner_covered') or 0))
|
| 652 |
+
sieve_ev = {'stage': 'sieve', 'ms': round(1000 * (time.time() - ts)), 'entity': ent, 'covered': out.get('covered'), 'of': out.get('of'), 'runner': out.get('runner_up'), 'taken': bool(ok)}
|
| 653 |
+
if ok:
|
| 654 |
+
span = {'answer': ent, 'score': 0.0, 'kind': 'sieve'}
|
| 655 |
+
pkey = normalize(ent)
|
| 656 |
+
if out.get('sent'):
|
| 657 |
+
c = {'sent': out['sent'], 'title': out.get('title') or '', 'url': out.get('url') or '', 'body': out['sent']}
|
| 658 |
+
score2 = float(out.get('v') or -99.0)
|
| 659 |
+
support = len({r.get('href') or r['body'] for r in res if pkey in normalize(r['title'] + ' ' + r['body'])}) + 1
|
| 660 |
+
tier = 1 if score2 >= tau_v else 2
|
| 661 |
+
retry = 'sieve'
|
| 662 |
+
verified_by = 'verifier' if tier == 1 else None
|
| 663 |
+
except Exception as ex:
|
| 664 |
+
sieve_ev = {'stage': 'sieve', 'ms': 0, 'error': type(ex).__name__}
|
| 665 |
+
if sieve_ev:
|
| 666 |
+
yield sieve_ev
|
| 667 |
+
td = time.time()
|
| 668 |
+
yield {'stage': 'extract', 'ms': round(1000 * (td - tc)), 'span': span['answer'] if span else None, 'support': support, 'consensus': cons['answer'] if cons else None, 'consensus_support': len(cons['sources']) if cons else 0}
|
| 669 |
+
hh = None
|
| 670 |
+
if self.hhem is not None and span:
|
| 671 |
+
try:
|
| 672 |
+
hh = float(self.hhem.predict([(c['body'], f"The answer to the question '{q}' is {span['answer']}.")])[0])
|
| 673 |
+
except Exception:
|
| 674 |
+
hh = None
|
| 675 |
+
ld, ld_by = (None, None)
|
| 676 |
+
vmode = verbalize or VERBALIZE
|
| 677 |
+
linfo = {}
|
| 678 |
+
if span and tier == 1 and (vmode != 'none'):
|
| 679 |
+
if vmode in ('own', 'own-strict'):
|
| 680 |
+
ttl = c['title'].split(' | ')[0].split(' - ')[0].strip()
|
| 681 |
+
ld, ld_by = own_lead(q, span['answer'], c['sent'], ttl, natural=vmode == 'own', info=linfo, q_user=q_user, vscore=lambda t, _q=q, _t=ttl: float(self.verify.predict([(_q, f'{_t}. {t}')], batch_size=8, show_progress_bar=False)[0]))
|
| 682 |
+
if not ld:
|
| 683 |
+
ld, ld_by = (lead(q, span['answer']), 'template' if lead(q, span['answer']) else None)
|
| 684 |
+
te = time.time()
|
| 685 |
+
yield {'stage': 'check', 'ms': round(1000 * (te - td)), 'hhem': None if hh is None else round(hh, 3), 'lead_by': ld_by, **linfo}
|
| 686 |
+
yield {'stage': 'done', 'tier': tier, 'score2': round(score2, 2), 'top_rank': round(float(s1[order[0]]), 2), 'cited': c['sent'], 'title': c['title'], 'url': c['url'], 'span': span['answer'] if span else None, 'span_score': round(span['score'], 2) if span else None, 'hhem': None if hh is None else round(hh, 3), 'support': support, 'lead': ld, 'lead_by': ld_by, 'lead_info': linfo or None, 'quote_clean': quote_clean(q, c['sent'], span['answer'] if span else None), 'retry': retry, 'verified_by': verified_by, 'consensus': cons['answer'] if cons else None, 'consensus_support': len(cons['sources']) if cons else 0, 'consensus_cited': cons['cand']['sent'] if cons else None, 'consensus_title': cons['cand']['title'] if cons else None, 'consensus_url': cons['cand']['url'] if cons else None, 'consensus_v': round(cons['best_v'], 2) if cons else None, 'ms_search': round(1000 * (t1 - t0)), 'ms_models': round(1000 * (te - t1)), 'results': res, 'spelled': fixes or None, 'q': q_user}
|
| 687 |
+
|
| 688 |
+
def answer(self, q, tau_v=None, tau_lo=-4.0, provider=None, verbalize=None):
|
| 689 |
+
for ev in self.answer_iter(q, tau_v, tau_lo, provider, verbalize):
|
| 690 |
+
if ev['stage'] == 'done':
|
| 691 |
+
return {k: v for k, v in ev.items() if k != 'stage'}
|
code/tinyqa/server.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse, json, os, sys, threading, urllib.parse
|
| 2 |
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
| 3 |
+
from tinyqa import pipeline as webqa
|
| 4 |
+
STACK = None
|
| 5 |
+
LOCK = threading.Lock()
|
| 6 |
+
KEEP = ('tier', 'lead', 'cited', 'span', 'support', 'url', 'title', 'verified_by')
|
| 7 |
+
|
| 8 |
+
class H(BaseHTTPRequestHandler):
|
| 9 |
+
|
| 10 |
+
def log_message(self, *a):
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
def _json(self, obj, code=200):
|
| 14 |
+
body = json.dumps(obj, ensure_ascii=False).encode()
|
| 15 |
+
self.send_response(code)
|
| 16 |
+
self.send_header('Content-Type', 'application/json')
|
| 17 |
+
self.send_header('Content-Length', str(len(body)))
|
| 18 |
+
self.end_headers()
|
| 19 |
+
self.wfile.write(body)
|
| 20 |
+
|
| 21 |
+
def do_GET(self):
|
| 22 |
+
u = urllib.parse.urlparse(self.path)
|
| 23 |
+
if u.path == '/health':
|
| 24 |
+
return self._json({'ok': True, 'models': STACK is not None})
|
| 25 |
+
if u.path != '/ask':
|
| 26 |
+
return self._json({'error': 'not found'}, 404)
|
| 27 |
+
qs = urllib.parse.parse_qs(u.query)
|
| 28 |
+
q = qs.get('q', [''])[0].strip()
|
| 29 |
+
provider = qs.get('provider', ['ddgs'])[0]
|
| 30 |
+
if not q:
|
| 31 |
+
return self._json({'tier': 3, 'why': 'empty question'})
|
| 32 |
+
with LOCK:
|
| 33 |
+
out = STACK.answer(q, provider=provider)
|
| 34 |
+
webqa.save_caches()
|
| 35 |
+
self._json({k: out.get(k) for k in KEEP})
|
| 36 |
+
|
| 37 |
+
def main():
|
| 38 |
+
global STACK
|
| 39 |
+
ap = argparse.ArgumentParser()
|
| 40 |
+
ap.add_argument('--port', type=int, default=8091)
|
| 41 |
+
a = ap.parse_args()
|
| 42 |
+
s = webqa.Stack()
|
| 43 |
+
s.rank.predict([('warm up', 'warm up')], show_progress_bar=False)
|
| 44 |
+
s.verify.predict([('warm up', 'warm up')], show_progress_bar=False)
|
| 45 |
+
STACK = s
|
| 46 |
+
print(f'[moss] models loaded on 127.0.0.1:{a.port}', flush=True)
|
| 47 |
+
ThreadingHTTPServer(('127.0.0.1', a.port), H).serve_forever()
|
| 48 |
+
if __name__ == '__main__':
|
| 49 |
+
main()
|
code/tinyqa/sieve.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections, json, os, re, sys, time
|
| 2 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 3 |
+
from . import pipeline as webqa
|
| 4 |
+
from .pipeline import QWORDS
|
| 5 |
+
_NAME = re.compile("\\b[A-Z][\\w'’.-]+(?:\\s+(?:(?:de|da|van|von|of|the|du|del|di|la|le)\\s+)?[A-Z][\\w'’.-]+){1,3}")
|
| 6 |
+
STOPCAP = {'The', 'This', 'That', 'These', 'There', 'What', 'When', 'Where', 'Which', 'Who', 'How', 'Why', 'In', 'On', 'At', 'For', 'From', 'With', 'After', 'Before', 'During', 'Since', 'His', 'Her', 'Its', 'Their', 'A', 'An', 'Of', 'To', 'By', 'And', 'Or', 'But', 'It', 'He', 'She', 'They', 'We', 'You', 'I', 'Yes', 'No'}
|
| 7 |
+
|
| 8 |
+
def content_words(q):
|
| 9 |
+
return [t for t in re.findall('[a-z0-9]+', q.lower()) if t not in QWORDS and len(t) > 2]
|
| 10 |
+
|
| 11 |
+
def entities_in(texts, exclude):
|
| 12 |
+
c = collections.Counter()
|
| 13 |
+
for t in texts:
|
| 14 |
+
for m in _NAME.findall(t):
|
| 15 |
+
m = m.strip(" .,'’")
|
| 16 |
+
toks = m.split()
|
| 17 |
+
if toks[0] in STOPCAP or len(m) > 40 or m.lower() in exclude:
|
| 18 |
+
continue
|
| 19 |
+
if any((w.lower() in exclude for w in toks)) and len(toks) <= 2:
|
| 20 |
+
continue
|
| 21 |
+
c[m] += 1
|
| 22 |
+
return c
|
| 23 |
+
|
| 24 |
+
def covers(text, w):
|
| 25 |
+
return re.search('(?<![a-z0-9])' + re.escape(w) + '(?![a-z0-9])', text.lower()) is not None
|
| 26 |
+
|
| 27 |
+
class Sieve:
|
| 28 |
+
|
| 29 |
+
def run(self, q, provider=None, k_ent=8):
|
| 30 |
+
t0 = time.time()
|
| 31 |
+
res = webqa.search(q, provider=provider)
|
| 32 |
+
cw = content_words(q)
|
| 33 |
+
qlow = {w for w in cw}
|
| 34 |
+
texts = [r['title'] + '. ' + r['body'] for r in res]
|
| 35 |
+
if webqa.PAGES:
|
| 36 |
+
texts += [c['sent'] for c in webqa.page_candidates(q, res, webqa.PAGES)]
|
| 37 |
+
ents = [e for e, _ in entities_in(texts, qlow).most_common(k_ent * 2) if not any((w in qlow for w in e.lower().split()))][:k_ent]
|
| 38 |
+
if not ents:
|
| 39 |
+
return {'sieve': None, 'why': 'no candidate entities', 'ms': round(1000 * (time.time() - t0))}
|
| 40 |
+
probe = ' '.join([w for w in cw if not any((w in e.lower() for e in ents))][:6])
|
| 41 |
+
with ThreadPoolExecutor(8) as ex:
|
| 42 |
+
packs = list(ex.map(lambda e: webqa.search(f'{e} {probe}', provider=provider), ents))
|
| 43 |
+
scored = []
|
| 44 |
+
for e, pack in zip(ents, packs):
|
| 45 |
+
hay = ' '.join((r['title'] + ' ' + r['body'] for r in pack))
|
| 46 |
+
cov = [w for w in cw if covers(hay, w)]
|
| 47 |
+
sents = [(r, s) for r in pack for s in webqa._SENT.split(r['body']) if len(s) > 20 and e.split()[-1].lower() in s.lower()]
|
| 48 |
+
best = None
|
| 49 |
+
if sents:
|
| 50 |
+
sc = self.verify.predict([(q, f"{r['title']}. {s}") for r, s in sents[:16]], batch_size=32, show_progress_bar=False)
|
| 51 |
+
j = max(range(len(sc)), key=lambda i: float(sc[i]))
|
| 52 |
+
best = (float(sc[j]), sents[j][1], sents[j][0])
|
| 53 |
+
scored.append({'entity': e, 'covered': len(cov), 'cov_words': cov, 'v': best[0] if best else -99.0, 'sent': best[1] if best else None, 'url': best[2]['href'] if best else None, 'title': best[2]['title'] if best else None})
|
| 54 |
+
scored.sort(key=lambda x: (-x['covered'], -x['v']))
|
| 55 |
+
top = scored[0]
|
| 56 |
+
runner = scored[1] if len(scored) > 1 else None
|
| 57 |
+
return {'sieve': top['entity'], 'covered': top['covered'], 'of': len(cw), 'cov_words': top['cov_words'], 'v': round(top['v'], 2), 'sent': top['sent'], 'url': top['url'], 'title': top['title'], 'runner_up': runner['entity'] if runner else None, 'runner_covered': runner['covered'] if runner else None, 'candidates': [s['entity'] for s in scored], 'ms': round(1000 * (time.time() - t0))}
|
gguf/tinyqa-1-moss-glue-Q8_0.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bdb15946920cdac9ea17eaeefa38095dd2fa17516dcf0bf582f781d685554520
|
| 3 |
+
size 122229888
|
gguf/tinyqa-1-moss-planner-Q8_0.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a963495409d2838fcc3136c0d573b1d4d907e5d043c6cc6e4652ddae7d857c5
|
| 3 |
+
size 122229888
|
gguf/tinyqa-1-moss-verbaliser-Q8_0.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dbd60b72ec1e5668c2e29e8bb70e393495a3d814e51ea9086fe39ebd649b52e4
|
| 3 |
+
size 122229888
|
models/ranker/config.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"eos_token_id": null,
|
| 11 |
+
"gradient_checkpointing": false,
|
| 12 |
+
"hidden_act": "gelu",
|
| 13 |
+
"hidden_dropout_prob": 0.1,
|
| 14 |
+
"hidden_size": 384,
|
| 15 |
+
"id2label": {
|
| 16 |
+
"0": "LABEL_0"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 1536,
|
| 20 |
+
"is_decoder": false,
|
| 21 |
+
"label2id": {
|
| 22 |
+
"LABEL_0": 0
|
| 23 |
+
},
|
| 24 |
+
"layer_norm_eps": 1e-12,
|
| 25 |
+
"max_position_embeddings": 512,
|
| 26 |
+
"model_type": "bert",
|
| 27 |
+
"num_attention_heads": 12,
|
| 28 |
+
"num_hidden_layers": 6,
|
| 29 |
+
"pad_token_id": 0,
|
| 30 |
+
"position_embedding_type": "absolute",
|
| 31 |
+
"sbert_ce_default_activation_function": "torch.nn.modules.linear.Identity",
|
| 32 |
+
"tie_word_embeddings": true,
|
| 33 |
+
"transformers_version": "5.22.1",
|
| 34 |
+
"type_vocab_size": 2,
|
| 35 |
+
"use_cache": true,
|
| 36 |
+
"vocab_size": 30522
|
| 37 |
+
}
|
models/ranker/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7dde2650d4e130fa5681e2537fc1875a83971f4f28a346b7ceb26ae1a8758f30
|
| 3 |
+
size 90866412
|
models/ranker/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/ranker/tokenizer_config.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"clean_up_tokenization_spaces": true,
|
| 4 |
+
"cls_token": "[CLS]",
|
| 5 |
+
"do_basic_tokenize": true,
|
| 6 |
+
"do_lower_case": true,
|
| 7 |
+
"is_local": false,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"mask_token": "[MASK]",
|
| 10 |
+
"model_max_length": 512,
|
| 11 |
+
"never_split": null,
|
| 12 |
+
"pad_token": "[PAD]",
|
| 13 |
+
"sep_token": "[SEP]",
|
| 14 |
+
"strip_accents": null,
|
| 15 |
+
"tokenize_chinese_chars": true,
|
| 16 |
+
"tokenizer_class": "BertTokenizer",
|
| 17 |
+
"unk_token": "[UNK]"
|
| 18 |
+
}
|
models/verifier/config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"BertForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"classifier_dropout": null,
|
| 7 |
+
"gradient_checkpointing": false,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 384,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "LABEL_0"
|
| 13 |
+
},
|
| 14 |
+
"initializer_range": 0.02,
|
| 15 |
+
"intermediate_size": 1536,
|
| 16 |
+
"label2id": {
|
| 17 |
+
"LABEL_0": 0
|
| 18 |
+
},
|
| 19 |
+
"layer_norm_eps": 1e-12,
|
| 20 |
+
"max_position_embeddings": 512,
|
| 21 |
+
"model_type": "bert",
|
| 22 |
+
"num_attention_heads": 12,
|
| 23 |
+
"num_hidden_layers": 12,
|
| 24 |
+
"pad_token_id": 0,
|
| 25 |
+
"position_embedding_type": "absolute",
|
| 26 |
+
"sbert_ce_default_activation_function": "torch.nn.modules.linear.Identity",
|
| 27 |
+
"torch_dtype": "float32",
|
| 28 |
+
"transformers_version": "4.51.3",
|
| 29 |
+
"type_vocab_size": 2,
|
| 30 |
+
"use_cache": true,
|
| 31 |
+
"vocab_size": 30522
|
| 32 |
+
}
|
models/verifier/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14f34669c51af8f27ea206b29d5bb0de45e2b69030db0927bb41e8f9cb632b2d
|
| 3 |
+
size 133464836
|
models/verifier/special_tokens_map.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": {
|
| 3 |
+
"content": "[CLS]",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"mask_token": {
|
| 10 |
+
"content": "[MASK]",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "[PAD]",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"sep_token": {
|
| 24 |
+
"content": "[SEP]",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"unk_token": {
|
| 31 |
+
"content": "[UNK]",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
}
|
| 37 |
+
}
|
models/verifier/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/verifier/tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "BertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
models/verifier/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
moss.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# RysoAI TinyQA-1 Moss: load the models in the background, then ask questions from the terminal.
|
| 3 |
+
# ./moss.sh setup one-off: Python 3.11 venv with CPU torch and the pinned packages (~1 GB download)
|
| 4 |
+
# ./moss.sh start load the models in the background (DuckDuckGo search, no keys needed)
|
| 5 |
+
# ./moss.sh ask "Who painted the Night Watch?" one answer (needs ./moss.sh start)
|
| 6 |
+
# ./moss.sh ask type questions one after another; add --local to answer from the index
|
| 7 |
+
# ./moss.sh index ~/Documents/notes index a folder of .txt/.md files (or a .jsonl of {"title","text"}) for offline use
|
| 8 |
+
# ./moss.sh ask --local "What is the boiling point of water at altitude?" answer from the indexed files, no network
|
| 9 |
+
# ./moss.sh stop | status
|
| 10 |
+
# Optional: put SERPER_API_KEY=... in .env next to this script for Google results and verifier-gated retries.
|
| 11 |
+
set -uo pipefail
|
| 12 |
+
ROOT=$(cd "$(dirname "$0")" && pwd); CODE="$ROOT/code"; PY="$ROOT/.venv/bin/python"; PORT=${MOSS_PORT:-8091}; URL="http://127.0.0.1:$PORT"
|
| 13 |
+
LOGS="$ROOT/data"; mkdir -p "$LOGS"
|
| 14 |
+
stop_all() { pkill -f "tinyqa.server --port $PORT" 2>/dev/null; pkill -f "llama-server.*--port 80(89|93|95)" 2>/dev/null; true; }
|
| 15 |
+
case "${1:-start}" in
|
| 16 |
+
setup)
|
| 17 |
+
command -v python3.11 >/dev/null || { echo "needs Python 3.11 (macOS: brew install python@3.11)"; exit 1; }
|
| 18 |
+
python3.11 -m venv "$ROOT/.venv" && "$ROOT/.venv/bin/pip" install -q --upgrade pip && "$ROOT/.venv/bin/pip" install -q -r "$ROOT/requirements.txt" || exit 1
|
| 19 |
+
command -v llama-server >/dev/null || echo "optional: install llama.cpp (macOS: brew install llama.cpp) so the 113M models write the answer line; without it a template writes it"
|
| 20 |
+
echo "setup done; next: ./moss.sh start";;
|
| 21 |
+
start)
|
| 22 |
+
[ -x "$PY" ] || { echo "run ./moss.sh setup first"; exit 1; }
|
| 23 |
+
stop_all; sleep 1
|
| 24 |
+
[ -f "$ROOT/.env" ] && set -a && . "$ROOT/.env" && set +a
|
| 25 |
+
export MOSS_HOME="$ROOT" MOSS_VERIFIER="$ROOT/models/verifier" MOSS_RANKER="$ROOT/models/ranker" MOSS_TAU_V=1.5
|
| 26 |
+
export MOSS_SOURCE_PENALTY=1 MOSS_QUOTABLE=1 MOSS_SEARCH=ddgs
|
| 27 |
+
export MOSS_BLOCK_DOMAINS="${MOSS_BLOCK_DOMAINS:-}" # no sites blocked unless you list some
|
| 28 |
+
# retries for uncertified answers go to Google; DuckDuckGo retries take 10-40 s, so without a Serper key they stay off
|
| 29 |
+
if [ -n "${SERPER_API_KEY:-}" ]; then export MOSS_FALLBACK=1 MOSS_PLANNER_RETRY=1 MOSS_SIEVE_RETRY=1; else export MOSS_FALLBACK=0 MOSS_PLANNER_RETRY=0 MOSS_SIEVE_RETRY=0; fi
|
| 30 |
+
if command -v llama-server >/dev/null; then
|
| 31 |
+
export MOSS_VERBALIZE=own MOSS_VERBALISER=http://127.0.0.1:8095
|
| 32 |
+
(nohup llama-server -m "$ROOT/gguf/tinyqa-1-moss-glue-Q8_0.gguf" -c 2048 --port 8089 -t 4 --special > "$LOGS/decoder.log" 2>&1 &)
|
| 33 |
+
(nohup llama-server -m "$ROOT/gguf/tinyqa-1-moss-planner-Q8_0.gguf" -c 1024 --port 8093 -t 4 --special > "$LOGS/planner.log" 2>&1 &)
|
| 34 |
+
(nohup llama-server -m "$ROOT/gguf/tinyqa-1-moss-verbaliser-Q8_0.gguf" -c 1024 --port 8095 -t 4 --special > "$LOGS/verbaliser.log" 2>&1 &)
|
| 35 |
+
else export MOSS_VERBALIZE=template; echo "llama-server not found: the answer line comes from a template"; fi
|
| 36 |
+
(cd "$CODE" && nohup "$PY" -m tinyqa.server --port "$PORT" > "$LOGS/moss.log" 2>&1 &)
|
| 37 |
+
for i in $(seq 1 180); do curl -s -m 1 "$URL/health" | grep -q '"models": true' && { echo "ready: ./moss.sh ask \"your question\""; exit 0; }; sleep 1; done
|
| 38 |
+
echo "did not start; see $LOGS/moss.log"; exit 1;;
|
| 39 |
+
index)
|
| 40 |
+
[ -x "$PY" ] || { echo "run ./moss.sh setup first"; exit 1; }
|
| 41 |
+
src=${2:?usage: ./moss.sh index <folder-or-jsonl>}; src=$(cd "$(dirname "$src")" && pwd)/$(basename "$src")
|
| 42 |
+
(cd "$CODE" && MOSS_HOME="$ROOT" "$PY" -c 'import sys; from tinyqa import pipeline; print(f"indexed {pipeline.index_corpus(sys.argv[1]):,} passages from {sys.argv[1]}")' "$src" 2>&1 | grep -v -i warning)
|
| 43 |
+
echo "ready to use: ./moss.sh ask --local \"your question\"";;
|
| 44 |
+
stop) stop_all; echo stopped;;
|
| 45 |
+
status) curl -s -m 1 "$URL/health" | grep -q '"models": true' && echo running || echo "not running";;
|
| 46 |
+
ask)
|
| 47 |
+
curl -s -m 1 "$URL/health" | grep -q '"models": true' || { echo "not running: ./moss.sh start first"; exit 1; }
|
| 48 |
+
[ -f "$ROOT/.env" ] && set -a && . "$ROOT/.env" && set +a
|
| 49 |
+
shift; cd "$CODE" && MOSS_PROVIDER=$([ -n "${SERPER_API_KEY:-}" ] && echo serper || echo ddgs) "$PY" -m tinyqa.cli "$URL" "$@";;
|
| 50 |
+
*) sed -n 2,9p "$0";;
|
| 51 |
+
esac
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# RysoAI TinyQA-1 Moss, tested on Python 3.11, CPU only.
|
| 2 |
+
torch==2.15.0
|
| 3 |
+
transformers==5.22.1
|
| 4 |
+
sentence-transformers==6.2.0
|
| 5 |
+
ddgs==9.16.1
|
| 6 |
+
numpy==2.4.6
|
| 7 |
+
trafilatura==2.3.1
|
results/freshqa_600_serper_summary.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bench": "freshqa",
|
| 3 |
+
"n": 600,
|
| 4 |
+
"search": "serper",
|
| 5 |
+
"judge": "gpt-4.1-2025-04-14",
|
| 6 |
+
"attempt_all": {
|
| 7 |
+
"n": 600,
|
| 8 |
+
"correct": 0.395,
|
| 9 |
+
"incorrect": 0.523,
|
| 10 |
+
"not_attempted": 0.082,
|
| 11 |
+
"correct_given_attempted": 0.43,
|
| 12 |
+
"f_score": 0.412
|
| 13 |
+
},
|
| 14 |
+
"verified_only": {
|
| 15 |
+
"n": 600,
|
| 16 |
+
"correct": 0.308,
|
| 17 |
+
"incorrect": 0.202,
|
| 18 |
+
"not_attempted": 0.49,
|
| 19 |
+
"correct_given_attempted": 0.605,
|
| 20 |
+
"f_score": 0.408
|
| 21 |
+
},
|
| 22 |
+
"consensus": {
|
| 23 |
+
"n": 600,
|
| 24 |
+
"correct": 0.395,
|
| 25 |
+
"incorrect": 0.523,
|
| 26 |
+
"not_attempted": 0.082,
|
| 27 |
+
"correct_given_attempted": 0.43,
|
| 28 |
+
"f_score": 0.412
|
| 29 |
+
},
|
| 30 |
+
"verified_and_agreed": {
|
| 31 |
+
"n": 600,
|
| 32 |
+
"correct": 0.265,
|
| 33 |
+
"incorrect": 0.132,
|
| 34 |
+
"not_attempted": 0.603,
|
| 35 |
+
"correct_given_attempted": 0.668,
|
| 36 |
+
"f_score": 0.379
|
| 37 |
+
},
|
| 38 |
+
"containment": 0.358,
|
| 39 |
+
"by_group": {
|
| 40 |
+
"fast-changing": {
|
| 41 |
+
"n": 155,
|
| 42 |
+
"attempt_all": 0.135,
|
| 43 |
+
"verified_only_f": 0.131
|
| 44 |
+
},
|
| 45 |
+
"never-changing": {
|
| 46 |
+
"n": 223,
|
| 47 |
+
"attempt_all": 0.574,
|
| 48 |
+
"verified_only_f": 0.571
|
| 49 |
+
},
|
| 50 |
+
"slow-changing": {
|
| 51 |
+
"n": 222,
|
| 52 |
+
"attempt_all": 0.396,
|
| 53 |
+
"verified_only_f": 0.412
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
results/popqa_1000_serper_summary.json
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bench": "popqa",
|
| 3 |
+
"n": 1000,
|
| 4 |
+
"search": "serper",
|
| 5 |
+
"judge": "gpt-4.1-2025-04-14",
|
| 6 |
+
"attempt_all": {
|
| 7 |
+
"n": 1000,
|
| 8 |
+
"correct": 0.474,
|
| 9 |
+
"incorrect": 0.485,
|
| 10 |
+
"not_attempted": 0.041,
|
| 11 |
+
"correct_given_attempted": 0.494,
|
| 12 |
+
"f_score": 0.484
|
| 13 |
+
},
|
| 14 |
+
"verified_only": {
|
| 15 |
+
"n": 1000,
|
| 16 |
+
"correct": 0.421,
|
| 17 |
+
"incorrect": 0.236,
|
| 18 |
+
"not_attempted": 0.343,
|
| 19 |
+
"correct_given_attempted": 0.641,
|
| 20 |
+
"f_score": 0.508
|
| 21 |
+
},
|
| 22 |
+
"consensus": {
|
| 23 |
+
"n": 1000,
|
| 24 |
+
"correct": 0.474,
|
| 25 |
+
"incorrect": 0.485,
|
| 26 |
+
"not_attempted": 0.041,
|
| 27 |
+
"correct_given_attempted": 0.494,
|
| 28 |
+
"f_score": 0.484
|
| 29 |
+
},
|
| 30 |
+
"verified_and_agreed": {
|
| 31 |
+
"n": 1000,
|
| 32 |
+
"correct": 0.323,
|
| 33 |
+
"incorrect": 0.146,
|
| 34 |
+
"not_attempted": 0.531,
|
| 35 |
+
"correct_given_attempted": 0.689,
|
| 36 |
+
"f_score": 0.44
|
| 37 |
+
},
|
| 38 |
+
"containment": 0.492,
|
| 39 |
+
"by_group": {
|
| 40 |
+
"author": {
|
| 41 |
+
"n": 175,
|
| 42 |
+
"attempt_all": 0.371,
|
| 43 |
+
"verified_only_f": 0.414
|
| 44 |
+
},
|
| 45 |
+
"capital": {
|
| 46 |
+
"n": 21,
|
| 47 |
+
"attempt_all": 0.619,
|
| 48 |
+
"verified_only_f": 0.667
|
| 49 |
+
},
|
| 50 |
+
"capital of": {
|
| 51 |
+
"n": 3,
|
| 52 |
+
"attempt_all": 0.0,
|
| 53 |
+
"verified_only_f": 0.0
|
| 54 |
+
},
|
| 55 |
+
"composer": {
|
| 56 |
+
"n": 42,
|
| 57 |
+
"attempt_all": 0.31,
|
| 58 |
+
"verified_only_f": 0.343
|
| 59 |
+
},
|
| 60 |
+
"country": {
|
| 61 |
+
"n": 114,
|
| 62 |
+
"attempt_all": 0.684,
|
| 63 |
+
"verified_only_f": 0.751
|
| 64 |
+
},
|
| 65 |
+
"director": {
|
| 66 |
+
"n": 121,
|
| 67 |
+
"attempt_all": 0.289,
|
| 68 |
+
"verified_only_f": 0.33
|
| 69 |
+
},
|
| 70 |
+
"father": {
|
| 71 |
+
"n": 31,
|
| 72 |
+
"attempt_all": 0.581,
|
| 73 |
+
"verified_only_f": 0.615
|
| 74 |
+
},
|
| 75 |
+
"genre": {
|
| 76 |
+
"n": 91,
|
| 77 |
+
"attempt_all": 0.198,
|
| 78 |
+
"verified_only_f": 0.206
|
| 79 |
+
},
|
| 80 |
+
"mother": {
|
| 81 |
+
"n": 4,
|
| 82 |
+
"attempt_all": 0.5,
|
| 83 |
+
"verified_only_f": 0.333
|
| 84 |
+
},
|
| 85 |
+
"occupation": {
|
| 86 |
+
"n": 72,
|
| 87 |
+
"attempt_all": 0.764,
|
| 88 |
+
"verified_only_f": 0.758
|
| 89 |
+
},
|
| 90 |
+
"place of birth": {
|
| 91 |
+
"n": 98,
|
| 92 |
+
"attempt_all": 0.704,
|
| 93 |
+
"verified_only_f": 0.737
|
| 94 |
+
},
|
| 95 |
+
"producer": {
|
| 96 |
+
"n": 61,
|
| 97 |
+
"attempt_all": 0.115,
|
| 98 |
+
"verified_only_f": 0.13
|
| 99 |
+
},
|
| 100 |
+
"religion": {
|
| 101 |
+
"n": 18,
|
| 102 |
+
"attempt_all": 0.889,
|
| 103 |
+
"verified_only_f": 0.839
|
| 104 |
+
},
|
| 105 |
+
"screenwriter": {
|
| 106 |
+
"n": 62,
|
| 107 |
+
"attempt_all": 0.242,
|
| 108 |
+
"verified_only_f": 0.304
|
| 109 |
+
},
|
| 110 |
+
"sport": {
|
| 111 |
+
"n": 87,
|
| 112 |
+
"attempt_all": 0.805,
|
| 113 |
+
"verified_only_f": 0.727
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
results/repro.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"simpleqa_1000_ddgs": {
|
| 3 |
+
"n": 1000,
|
| 4 |
+
"compared": 1000,
|
| 5 |
+
"identical": 996,
|
| 6 |
+
"differ": 4,
|
| 7 |
+
"official_correct": 71.3,
|
| 8 |
+
"release_correct_bounds": [
|
| 9 |
+
71.3,
|
| 10 |
+
71.7
|
| 11 |
+
],
|
| 12 |
+
"official_verified_correct": 60.9,
|
| 13 |
+
"release_verified_correct_bounds": [
|
| 14 |
+
60.9,
|
| 15 |
+
61.3
|
| 16 |
+
],
|
| 17 |
+
"tier_changes": 4
|
| 18 |
+
},
|
| 19 |
+
"simpleqa_1000_serper": {
|
| 20 |
+
"n": 1000,
|
| 21 |
+
"compared": 1000,
|
| 22 |
+
"identical": 1000,
|
| 23 |
+
"differ": 0,
|
| 24 |
+
"official_correct": 69.6,
|
| 25 |
+
"release_correct_bounds": [
|
| 26 |
+
69.6,
|
| 27 |
+
69.6
|
| 28 |
+
],
|
| 29 |
+
"official_verified_correct": 59.2,
|
| 30 |
+
"release_verified_correct_bounds": [
|
| 31 |
+
59.2,
|
| 32 |
+
59.2
|
| 33 |
+
],
|
| 34 |
+
"tier_changes": 0
|
| 35 |
+
},
|
| 36 |
+
"freshqa_600_serper": {
|
| 37 |
+
"n": 600,
|
| 38 |
+
"compared": 600,
|
| 39 |
+
"identical": 600,
|
| 40 |
+
"differ": 0,
|
| 41 |
+
"official_correct": 39.5,
|
| 42 |
+
"release_correct_bounds": [
|
| 43 |
+
39.5,
|
| 44 |
+
39.5
|
| 45 |
+
],
|
| 46 |
+
"official_verified_correct": 30.8,
|
| 47 |
+
"release_verified_correct_bounds": [
|
| 48 |
+
30.8,
|
| 49 |
+
30.8
|
| 50 |
+
],
|
| 51 |
+
"tier_changes": 0
|
| 52 |
+
},
|
| 53 |
+
"popqa_1000_serper": {
|
| 54 |
+
"n": 1000,
|
| 55 |
+
"compared": 991,
|
| 56 |
+
"identical": 991,
|
| 57 |
+
"differ": 0,
|
| 58 |
+
"official_correct": 47.4,
|
| 59 |
+
"release_correct_bounds": [
|
| 60 |
+
47.4,
|
| 61 |
+
47.4
|
| 62 |
+
],
|
| 63 |
+
"official_verified_correct": 42.1,
|
| 64 |
+
"release_verified_correct_bounds": [
|
| 65 |
+
42.1,
|
| 66 |
+
42.1
|
| 67 |
+
],
|
| 68 |
+
"tier_changes": 0
|
| 69 |
+
}
|
| 70 |
+
}
|
results/simpleqa_1000_ddgs_summary.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bench": "simpleqa",
|
| 3 |
+
"n": 1000,
|
| 4 |
+
"search": "ddgs",
|
| 5 |
+
"judge": "gpt-4.1-2025-04-14",
|
| 6 |
+
"attempt_all": {
|
| 7 |
+
"n": 1000,
|
| 8 |
+
"correct": 0.713,
|
| 9 |
+
"incorrect": 0.137,
|
| 10 |
+
"not_attempted": 0.15,
|
| 11 |
+
"correct_given_attempted": 0.839,
|
| 12 |
+
"f_score": 0.771
|
| 13 |
+
},
|
| 14 |
+
"verified_only": {
|
| 15 |
+
"n": 1000,
|
| 16 |
+
"correct": 0.609,
|
| 17 |
+
"incorrect": 0.062,
|
| 18 |
+
"not_attempted": 0.329,
|
| 19 |
+
"correct_given_attempted": 0.908,
|
| 20 |
+
"f_score": 0.729
|
| 21 |
+
},
|
| 22 |
+
"consensus": {
|
| 23 |
+
"n": 1000,
|
| 24 |
+
"correct": 0.713,
|
| 25 |
+
"incorrect": 0.137,
|
| 26 |
+
"not_attempted": 0.15,
|
| 27 |
+
"correct_given_attempted": 0.839,
|
| 28 |
+
"f_score": 0.771
|
| 29 |
+
},
|
| 30 |
+
"verified_and_agreed": {
|
| 31 |
+
"n": 1000,
|
| 32 |
+
"correct": 0.518,
|
| 33 |
+
"incorrect": 0.045,
|
| 34 |
+
"not_attempted": 0.437,
|
| 35 |
+
"correct_given_attempted": 0.92,
|
| 36 |
+
"f_score": 0.663
|
| 37 |
+
},
|
| 38 |
+
"containment": 0.535,
|
| 39 |
+
"by_group": {
|
| 40 |
+
"Art": {
|
| 41 |
+
"n": 145,
|
| 42 |
+
"attempt_all": 0.71,
|
| 43 |
+
"verified_only_f": 0.771
|
| 44 |
+
},
|
| 45 |
+
"Geography": {
|
| 46 |
+
"n": 111,
|
| 47 |
+
"attempt_all": 0.82,
|
| 48 |
+
"verified_only_f": 0.819
|
| 49 |
+
},
|
| 50 |
+
"History": {
|
| 51 |
+
"n": 52,
|
| 52 |
+
"attempt_all": 0.75,
|
| 53 |
+
"verified_only_f": 0.764
|
| 54 |
+
},
|
| 55 |
+
"Music": {
|
| 56 |
+
"n": 102,
|
| 57 |
+
"attempt_all": 0.765,
|
| 58 |
+
"verified_only_f": 0.74
|
| 59 |
+
},
|
| 60 |
+
"Other": {
|
| 61 |
+
"n": 102,
|
| 62 |
+
"attempt_all": 0.716,
|
| 63 |
+
"verified_only_f": 0.743
|
| 64 |
+
},
|
| 65 |
+
"Politics": {
|
| 66 |
+
"n": 176,
|
| 67 |
+
"attempt_all": 0.705,
|
| 68 |
+
"verified_only_f": 0.727
|
| 69 |
+
},
|
| 70 |
+
"Science and technology": {
|
| 71 |
+
"n": 160,
|
| 72 |
+
"attempt_all": 0.65,
|
| 73 |
+
"verified_only_f": 0.62
|
| 74 |
+
},
|
| 75 |
+
"Sports": {
|
| 76 |
+
"n": 117,
|
| 77 |
+
"attempt_all": 0.684,
|
| 78 |
+
"verified_only_f": 0.728
|
| 79 |
+
},
|
| 80 |
+
"TV shows": {
|
| 81 |
+
"n": 20,
|
| 82 |
+
"attempt_all": 0.85,
|
| 83 |
+
"verified_only_f": 0.824
|
| 84 |
+
},
|
| 85 |
+
"Video games": {
|
| 86 |
+
"n": 15,
|
| 87 |
+
"attempt_all": 0.267,
|
| 88 |
+
"verified_only_f": 0.19
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
}
|
results/simpleqa_1000_serper_summary.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bench": "simpleqa",
|
| 3 |
+
"n": 1000,
|
| 4 |
+
"search": "serper",
|
| 5 |
+
"judge": "gpt-4.1-2025-04-14",
|
| 6 |
+
"attempt_all": {
|
| 7 |
+
"n": 1000,
|
| 8 |
+
"correct": 0.696,
|
| 9 |
+
"incorrect": 0.186,
|
| 10 |
+
"not_attempted": 0.118,
|
| 11 |
+
"correct_given_attempted": 0.789,
|
| 12 |
+
"f_score": 0.74
|
| 13 |
+
},
|
| 14 |
+
"verified_only": {
|
| 15 |
+
"n": 1000,
|
| 16 |
+
"correct": 0.592,
|
| 17 |
+
"incorrect": 0.075,
|
| 18 |
+
"not_attempted": 0.333,
|
| 19 |
+
"correct_given_attempted": 0.888,
|
| 20 |
+
"f_score": 0.71
|
| 21 |
+
},
|
| 22 |
+
"consensus": {
|
| 23 |
+
"n": 1000,
|
| 24 |
+
"correct": 0.696,
|
| 25 |
+
"incorrect": 0.186,
|
| 26 |
+
"not_attempted": 0.118,
|
| 27 |
+
"correct_given_attempted": 0.789,
|
| 28 |
+
"f_score": 0.74
|
| 29 |
+
},
|
| 30 |
+
"verified_and_agreed": {
|
| 31 |
+
"n": 1000,
|
| 32 |
+
"correct": 0.443,
|
| 33 |
+
"incorrect": 0.042,
|
| 34 |
+
"not_attempted": 0.515,
|
| 35 |
+
"correct_given_attempted": 0.913,
|
| 36 |
+
"f_score": 0.597
|
| 37 |
+
},
|
| 38 |
+
"containment": 0.531,
|
| 39 |
+
"by_group": {
|
| 40 |
+
"Art": {
|
| 41 |
+
"n": 145,
|
| 42 |
+
"attempt_all": 0.697,
|
| 43 |
+
"verified_only_f": 0.714
|
| 44 |
+
},
|
| 45 |
+
"Geography": {
|
| 46 |
+
"n": 111,
|
| 47 |
+
"attempt_all": 0.766,
|
| 48 |
+
"verified_only_f": 0.774
|
| 49 |
+
},
|
| 50 |
+
"History": {
|
| 51 |
+
"n": 52,
|
| 52 |
+
"attempt_all": 0.731,
|
| 53 |
+
"verified_only_f": 0.744
|
| 54 |
+
},
|
| 55 |
+
"Music": {
|
| 56 |
+
"n": 102,
|
| 57 |
+
"attempt_all": 0.657,
|
| 58 |
+
"verified_only_f": 0.663
|
| 59 |
+
},
|
| 60 |
+
"Other": {
|
| 61 |
+
"n": 102,
|
| 62 |
+
"attempt_all": 0.775,
|
| 63 |
+
"verified_only_f": 0.768
|
| 64 |
+
},
|
| 65 |
+
"Politics": {
|
| 66 |
+
"n": 176,
|
| 67 |
+
"attempt_all": 0.693,
|
| 68 |
+
"verified_only_f": 0.73
|
| 69 |
+
},
|
| 70 |
+
"Science and technology": {
|
| 71 |
+
"n": 160,
|
| 72 |
+
"attempt_all": 0.637,
|
| 73 |
+
"verified_only_f": 0.64
|
| 74 |
+
},
|
| 75 |
+
"Sports": {
|
| 76 |
+
"n": 117,
|
| 77 |
+
"attempt_all": 0.675,
|
| 78 |
+
"verified_only_f": 0.677
|
| 79 |
+
},
|
| 80 |
+
"TV shows": {
|
| 81 |
+
"n": 20,
|
| 82 |
+
"attempt_all": 0.8,
|
| 83 |
+
"verified_only_f": 0.824
|
| 84 |
+
},
|
| 85 |
+
"Video games": {
|
| 86 |
+
"n": 15,
|
| 87 |
+
"attempt_all": 0.467,
|
| 88 |
+
"verified_only_f": 0.476
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
}
|