finesse-benchmark-database 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- finesse_benchmark_database-0.1.0/PKG-INFO +23 -0
- finesse_benchmark_database-0.1.0/README.md +3 -0
- finesse_benchmark_database-0.1.0/licence +202 -0
- finesse_benchmark_database-0.1.0/pyproject.toml +19 -0
- finesse_benchmark_database-0.1.0/src/finesse_benchmark_database/__init__.py +47 -0
- finesse_benchmark_database-0.1.0/src/finesse_benchmark_database/chunker.py +154 -0
- finesse_benchmark_database-0.1.0/src/finesse_benchmark_database/config.py +79 -0
- finesse_benchmark_database-0.1.0/src/finesse_benchmark_database/main.py +72 -0
- finesse_benchmark_database-0.1.0/src/finesse_benchmark_database/writer.py +83 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: finesse-benchmark-database
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Data generation factory for atomic probes in Finesse benchmark. Generates probes_atomic.jsonl from Wikimedia Wikipedia.
|
|
5
|
+
License-File: licence
|
|
6
|
+
Author: winter.sci.dev
|
|
7
|
+
Author-email: enzoescipy@gmail.com
|
|
8
|
+
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Dist: datasets (>=4.3.0,<5.0.0)
|
|
16
|
+
Requires-Dist: torch (>=2.1.0,<3.0.0)
|
|
17
|
+
Requires-Dist: transformers (>=4.35.0,<5.0.0)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
license: apache-2.0
|
|
22
|
+
---
|
|
23
|
+
|
|
@@ -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.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "finesse-benchmark-database"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Data generation factory for atomic probes in Finesse benchmark. Generates probes_atomic.jsonl from Wikimedia Wikipedia."
|
|
5
|
+
authors = ["winter.sci.dev <enzoescipy@gmail.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
packages = [{include = "finesse_benchmark_database", from = "src"}]
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "^3.10"
|
|
11
|
+
datasets = "^4.3.0"
|
|
12
|
+
transformers = "^4.35.0"
|
|
13
|
+
torch = "^2.1.0" # For tokenizer if needed
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["poetry-core"]
|
|
19
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""finesse-benchmark-database: Multilingual Atomic Probe Generator for Long-Context Evaluation
|
|
2
|
+
|
|
3
|
+
This package provides a flexible, configurable library for generating high-quality, traceable datasets of 'strings of beads'—
|
|
4
|
+
atomic 64-token text chunks sourced from multilingual Wikipedia articles. It serves as the foundational data generation
|
|
5
|
+
pipeline for the Finesse long-context benchmarking framework, ensuring reproducibility, semantic diversity, and
|
|
6
|
+
complete metadata tracking for advanced LLM evaluation.
|
|
7
|
+
|
|
8
|
+
Core Principles:
|
|
9
|
+
- Atomic Beads: Exact 64-token chunks (discard incompletes) to test pure memory granularity.
|
|
10
|
+
- Traceable Origins: Each bead/string includes full metadata (dataset, article_id, lang) for debugging and verification.
|
|
11
|
+
- Multilingual Balance: Supports 10+ languages with configurable quotas for fair coverage.
|
|
12
|
+
- Library-First Design: Instantiable via ProbeConfig for custom experiments; no globals or hardcoding.
|
|
13
|
+
- JSONL Output: Efficient streaming format for large-scale datasets.
|
|
14
|
+
|
|
15
|
+
Key Components:
|
|
16
|
+
- ProbeConfig: Dataclass for all settings (languages, samples, chunk size, etc.).
|
|
17
|
+
- generate_all_strings_of_beads(config): Produces list of {'source': metadata, 'beads': [text_chunks]} dicts.
|
|
18
|
+
- write_strings_to_probes_atomic(config, strings): Serializes to JSONL with auto-assigned string_ids.
|
|
19
|
+
|
|
20
|
+
Example Usage:
|
|
21
|
+
from finesse_benchmark_database import ProbeConfig, generate_all_strings_of_beads, write_strings_to_probes_atomic
|
|
22
|
+
|
|
23
|
+
config = ProbeConfig(
|
|
24
|
+
languages=['en', 'ko'],
|
|
25
|
+
samples_per_language=100,
|
|
26
|
+
chunk_token_size=64,
|
|
27
|
+
output_file='my_probes.jsonl',
|
|
28
|
+
seed=42
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
beads_strings = generate_all_strings_of_beads(config)
|
|
32
|
+
write_strings_to_probes_atomic(config, beads_strings)
|
|
33
|
+
# Outputs my_probes.jsonl with ~200 traceable strings of beads.
|
|
34
|
+
|
|
35
|
+
Installation:
|
|
36
|
+
pip install finesse-benchmark-database
|
|
37
|
+
# Or via Poetry: poetry add finesse-benchmark-database
|
|
38
|
+
|
|
39
|
+
This package powers the creation of ~1M+ atomic probes for rigorous long-context memory testing.
|
|
40
|
+
See main.py for a full pipeline example.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
__version__ = "0.1.0"
|
|
44
|
+
|
|
45
|
+
from .config import ProbeConfig
|
|
46
|
+
from .chunker import generate_all_strings_of_beads
|
|
47
|
+
from .writer import write_strings_to_probes_atomic
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""Chunker module for Finesse Benchmark Database Generator
|
|
2
|
+
|
|
3
|
+
This module implements the 'Gemstone Necklace Crafter' aka the atomic bead generator.
|
|
4
|
+
It transforms raw Wikimedia Wikipedia documents into 'strings of beads': sequential chains
|
|
5
|
+
of exactly 64-token atomic beads from each source article, preserving semantic flow within
|
|
6
|
+
each string while ensuring atomicity and reproducibility across languages.
|
|
7
|
+
|
|
8
|
+
Key Principles:
|
|
9
|
+
- Uses official reference tokenizer: bert-base-multilingual-cased for universal fairness.
|
|
10
|
+
- Exactly 64-token beads only; discard all incomplete final chunks (golden rule).
|
|
11
|
+
- One 'string' per Wikipedia article, with beads in original sequential order.
|
|
12
|
+
- Balanced collection: samples_per_language strings per language.
|
|
13
|
+
- Streaming processing for efficiency on massive datasets.
|
|
14
|
+
- Logged progress for transparency and debugging.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
from chunker import generate_all_strings_of_beads
|
|
18
|
+
strings_of_beads = generate_all_strings_of_beads()
|
|
19
|
+
# Result: List[Dict] where each inner dict contains 'source' and 'beads' keys.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import logging
|
|
23
|
+
import random
|
|
24
|
+
from typing import List, Dict
|
|
25
|
+
|
|
26
|
+
from .config import ProbeConfig
|
|
27
|
+
from datasets import load_dataset
|
|
28
|
+
from transformers import AutoTokenizer
|
|
29
|
+
|
|
30
|
+
# Configure logging for progress tracking
|
|
31
|
+
logging.basicConfig(level=logging.INFO)
|
|
32
|
+
logger = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
def generate_all_strings_of_beads(config: ProbeConfig) -> List[Dict]:
|
|
35
|
+
"""
|
|
36
|
+
Generate all 'strings of beads' across languages using the official tokenizer.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
config: ProbeConfig instance with all parameters (languages, samples_per_language, etc.).
|
|
40
|
+
|
|
41
|
+
For each language:
|
|
42
|
+
- Stream Wikipedia articles.
|
|
43
|
+
- For each article (up to config.samples_per_language):
|
|
44
|
+
- Tokenize the full text.
|
|
45
|
+
- Sequentially slice into 64-token chunks.
|
|
46
|
+
- Decode only exact 64-token chunks to bead texts.
|
|
47
|
+
- Form a 'string' as [bead1, bead2, ...] if at least one bead exists.
|
|
48
|
+
- Collect all strings into a global 2D list.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
List of dictionaries: Outer list by language/order, inner dicts contain 'source' and 'beads' keys.
|
|
52
|
+
"""
|
|
53
|
+
# Set global seed for reproducibility
|
|
54
|
+
random.seed(config.seed)
|
|
55
|
+
|
|
56
|
+
# Load the official reference tokenizer (our 'public scale')
|
|
57
|
+
logger.info(f"Loading official tokenizer: {config.tokenizer_name}")
|
|
58
|
+
tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name)
|
|
59
|
+
|
|
60
|
+
all_strings_of_beads: List[Dict] = []
|
|
61
|
+
|
|
62
|
+
if config.languages is None:
|
|
63
|
+
raise ValueError("config.languages must be set to a list of language codes.")
|
|
64
|
+
|
|
65
|
+
for lang in config.languages:
|
|
66
|
+
logger.info(f"Starting processing for language: {lang} (target: {config.samples_per_language} strings)")
|
|
67
|
+
|
|
68
|
+
# Load streaming dataset with the specified split
|
|
69
|
+
dataset = load_dataset(
|
|
70
|
+
"wikimedia/wikipedia",
|
|
71
|
+
f"20231101.{lang}",
|
|
72
|
+
streaming=True,
|
|
73
|
+
split="train"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
strings_for_lang: List[Dict] = []
|
|
77
|
+
article_count = 0
|
|
78
|
+
|
|
79
|
+
for example in dataset:
|
|
80
|
+
if len(strings_for_lang) >= config.samples_per_language:
|
|
81
|
+
break
|
|
82
|
+
|
|
83
|
+
# Extract and clean text
|
|
84
|
+
text = example.get("text", "").strip()
|
|
85
|
+
if not text:
|
|
86
|
+
continue
|
|
87
|
+
|
|
88
|
+
# Extract article ID for metadata
|
|
89
|
+
article_id = example.get("id", "")
|
|
90
|
+
|
|
91
|
+
# Tokenize the full article
|
|
92
|
+
tokens = tokenizer.encode(text, add_special_tokens=False)
|
|
93
|
+
|
|
94
|
+
# Sequentially chunk into exact config.chunk_token_size-token beads
|
|
95
|
+
beads: List[str] = []
|
|
96
|
+
for i in range(0, len(tokens), config.chunk_token_size):
|
|
97
|
+
chunk_tokens = tokens[i:i + config.chunk_token_size]
|
|
98
|
+
|
|
99
|
+
# Golden rule: Only accept exactly 64 tokens; discard incompletes
|
|
100
|
+
if len(chunk_tokens) == config.chunk_token_size:
|
|
101
|
+
bead_text = tokenizer.decode(chunk_tokens, skip_special_tokens=True).strip()
|
|
102
|
+
if bead_text: # Ensure non-empty after decoding
|
|
103
|
+
beads.append(bead_text)
|
|
104
|
+
|
|
105
|
+
# Only add the string if it has at least one bead
|
|
106
|
+
if beads:
|
|
107
|
+
string_data = {
|
|
108
|
+
"source": {
|
|
109
|
+
"dataset": "wikimedia/wikipedia",
|
|
110
|
+
"article_id": article_id,
|
|
111
|
+
"lang": lang
|
|
112
|
+
},
|
|
113
|
+
"beads": beads
|
|
114
|
+
}
|
|
115
|
+
strings_for_lang.append(string_data)
|
|
116
|
+
article_count += 1
|
|
117
|
+
|
|
118
|
+
# Log progress every 100 articles
|
|
119
|
+
if article_count % 100 == 0:
|
|
120
|
+
logger.info(
|
|
121
|
+
f"Language {lang}: Processed {article_count} articles, "
|
|
122
|
+
f"collected {len(strings_for_lang)} strings so far"
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
# Add language's strings to the global collection
|
|
126
|
+
all_strings_of_beads.extend(strings_for_lang)
|
|
127
|
+
logger.info(f"Completed {lang}: {len(strings_for_lang)} strings generated "
|
|
128
|
+
f"(from {article_count} articles)")
|
|
129
|
+
|
|
130
|
+
total_strings = len(all_strings_of_beads)
|
|
131
|
+
logger.info(f"Generation complete: {total_strings} total strings of beads across {len(config.languages)} languages")
|
|
132
|
+
|
|
133
|
+
return all_strings_of_beads
|
|
134
|
+
|
|
135
|
+
if __name__ == "__main__":
|
|
136
|
+
# Example library usage: Create config and generate
|
|
137
|
+
from config import ProbeConfig
|
|
138
|
+
|
|
139
|
+
# User creates and populates config
|
|
140
|
+
test_config = ProbeConfig(
|
|
141
|
+
languages=['en', 'ko'], # Test with 2 languages
|
|
142
|
+
samples_per_language=5, # Small sample for demo
|
|
143
|
+
chunk_token_size=64,
|
|
144
|
+
tokenizer_name="google-bert/bert-base-multilingual-cased",
|
|
145
|
+
output_file="probes_atomic.jsonl",
|
|
146
|
+
seed=42
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Generate and print summary
|
|
150
|
+
strings = generate_all_strings_of_beads(test_config)
|
|
151
|
+
print(f"Generated {len(strings)} strings of beads.")
|
|
152
|
+
if strings:
|
|
153
|
+
avg_beads_per_string = sum(len(s['beads']) for s in strings) / len(strings)
|
|
154
|
+
print(f"Average beads per string: {avg_beads_per_string:.2f}")
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Configuration module for Finesse Benchmark Database Generator
|
|
2
|
+
|
|
3
|
+
This module holds all configurable parameters for generating atomic probes from Wikimedia Wikipedia datasets.
|
|
4
|
+
Based on the 'Beads and String' model: 64-token atomic beads from diverse languages, ensuring semantic continuity within strings but independence across probes.
|
|
5
|
+
|
|
6
|
+
Key Principles:
|
|
7
|
+
- Fixed 64-token chunk size for atomic beads.
|
|
8
|
+
- Balanced sampling across languages for global diversity.
|
|
9
|
+
- Seeded randomness for perfect reproducibility.
|
|
10
|
+
- Output in probes_atomic.jsonl format for dynamic assembly in evaluation.
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
from config import tokenizer_name, languages, chunk_token_size, samples_per_language, output_file, seed
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
import random
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class ProbeConfig:
|
|
21
|
+
"""Central configuration for probe generation.
|
|
22
|
+
|
|
23
|
+
This dataclass serves as a flexible template for library users.
|
|
24
|
+
Instantiate and populate it with desired values before passing to generate functions.
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
config = ProbeConfig(
|
|
28
|
+
languages=['en', 'ko'],
|
|
29
|
+
samples_per_language=10,
|
|
30
|
+
chunk_token_size=64
|
|
31
|
+
)
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# Tokenizer for tokenization (default: multilingual BERT)
|
|
35
|
+
tokenizer_name: str = "google-bert/bert-base-multilingual-cased"
|
|
36
|
+
|
|
37
|
+
# Languages for balanced multilingual coverage (must be set by user)
|
|
38
|
+
languages: list[str] = None
|
|
39
|
+
|
|
40
|
+
# Atomic bead size (golden rule from design; override for custom experiments)
|
|
41
|
+
chunk_token_size: int = 64
|
|
42
|
+
|
|
43
|
+
# Number of 'strings of beads' (source documents) per language: The number of complete
|
|
44
|
+
# Wikipedia articles to process per language. Each document is chunked sequentially into
|
|
45
|
+
# multiple 64-token atomic beads, preserving original order and semantic flow within
|
|
46
|
+
# the string. This is NOT the total count of individual beads (which will be much higher,
|
|
47
|
+
# depending on document lengths), but the number of such connected 'necklaces' or
|
|
48
|
+
# 'strings' for balanced multilingual coverage.
|
|
49
|
+
samples_per_language: int = 10000
|
|
50
|
+
|
|
51
|
+
# Output file for atomic probes
|
|
52
|
+
output_file: str = "probes_atomic.jsonl"
|
|
53
|
+
|
|
54
|
+
# Fixed seed for reproducibility (immutable law; set to None for non-deterministic runs)
|
|
55
|
+
seed: int = 42
|
|
56
|
+
|
|
57
|
+
def get_config() -> ProbeConfig:
|
|
58
|
+
"""Instantiate and return the configuration with languages initialized."""
|
|
59
|
+
config = ProbeConfig()
|
|
60
|
+
config.languages = [
|
|
61
|
+
'en', # English
|
|
62
|
+
'ko', # Korean
|
|
63
|
+
'es', # Spanish
|
|
64
|
+
'ja', # Japanese
|
|
65
|
+
'ru', # Russian
|
|
66
|
+
'zh', # Chinese
|
|
67
|
+
'ar', # Arabic
|
|
68
|
+
'id', # Indonesian
|
|
69
|
+
'de', # German
|
|
70
|
+
'vi', # Vietnamese
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
# Set global seed for all randomness
|
|
74
|
+
random.seed(config.seed)
|
|
75
|
+
|
|
76
|
+
return config
|
|
77
|
+
|
|
78
|
+
# Default config instance
|
|
79
|
+
CONFIG = get_config()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Main orchestration module for Finesse Benchmark Database Generator
|
|
2
|
+
|
|
3
|
+
This script serves as the 'Conductor' that orchestrates the entire pipeline: from configuration setup
|
|
4
|
+
through atomic bead generation to final JSONL serialization. It ties together config, chunker, and writer
|
|
5
|
+
for end-to-end execution of our 'Gemstone Necklace' production process.
|
|
6
|
+
|
|
7
|
+
Key Principles:
|
|
8
|
+
- Ensures all modules use the shared CONFIG for consistency.
|
|
9
|
+
- Executes chunking first (memory-intensive), then writing (I/O-focused).
|
|
10
|
+
- Comprehensive logging for audit trail and debugging.
|
|
11
|
+
- Designed for one-shot full generation; scale via external orchestration if needed.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
python main.py
|
|
15
|
+
# Runs the full pipeline: generates ~100,000 strings of beads and writes to probes_atomic.jsonl
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from .config import ProbeConfig
|
|
21
|
+
from .chunker import generate_all_strings_of_beads
|
|
22
|
+
from .writer import write_strings_to_probes_atomic
|
|
23
|
+
|
|
24
|
+
# Configure logging for the entire pipeline
|
|
25
|
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
def main() -> None:
|
|
29
|
+
"""Execute the full Finesse benchmark database generation pipeline as a library example.
|
|
30
|
+
|
|
31
|
+
This demonstrates how users would create a ProbeConfig, generate data, and write output.
|
|
32
|
+
For production, adjust config parameters as needed (e.g., more languages, larger samples).
|
|
33
|
+
"""
|
|
34
|
+
logger.info("=== Finesse Benchmark Database Pipeline Started (Library Example) ===")
|
|
35
|
+
|
|
36
|
+
# Step 1: User creates and configures ProbeConfig for this run
|
|
37
|
+
logger.info("Creating test configuration...")
|
|
38
|
+
test_config = ProbeConfig(
|
|
39
|
+
languages=['en'], # Single language for quick demo
|
|
40
|
+
samples_per_language=5, # Small sample for testing
|
|
41
|
+
chunk_token_size=64,
|
|
42
|
+
tokenizer_name="google-bert/bert-base-multilingual-cased",
|
|
43
|
+
output_file="test_probes_atomic.jsonl",
|
|
44
|
+
seed=42
|
|
45
|
+
)
|
|
46
|
+
logger.info(f"Config set: {len(test_config.languages)} languages, {test_config.chunk_token_size}-token beads, "
|
|
47
|
+
f"{test_config.samples_per_language} strings per language")
|
|
48
|
+
|
|
49
|
+
# Step 2: Generate all structured 'strings of beads' using the chunker
|
|
50
|
+
logger.info("Starting bead generation with chunker...")
|
|
51
|
+
all_strings_of_beads = generate_all_strings_of_beads(test_config)
|
|
52
|
+
total_strings = len(all_strings_of_beads)
|
|
53
|
+
logger.info(f"Bead generation complete: {total_strings} total strings produced "
|
|
54
|
+
f"(~{total_strings / len(test_config.languages):.0f} per language)")
|
|
55
|
+
|
|
56
|
+
# Step 3: Serialize to the atomic probes JSONL file using the writer
|
|
57
|
+
logger.info(f"Starting serialization to {test_config.output_file}...")
|
|
58
|
+
write_strings_to_probes_atomic(test_config, all_strings_of_beads)
|
|
59
|
+
logger.info(f"Serialization complete: All {total_strings} strings saved with metadata.")
|
|
60
|
+
|
|
61
|
+
# Final summary
|
|
62
|
+
estimated_beads = sum(len(s['beads']) for s in all_strings_of_beads)
|
|
63
|
+
logger.info("=== Pipeline Summary (Test Run) ===")
|
|
64
|
+
logger.info(f"- Total strings: {total_strings}")
|
|
65
|
+
logger.info(f"- Total atomic beads: {estimated_beads}")
|
|
66
|
+
logger.info(f"- Coverage: {len(set(s['source']['lang'] for s in all_strings_of_beads))} languages")
|
|
67
|
+
logger.info(f"- Output file: {test_config.output_file}")
|
|
68
|
+
logger.info("For full production: Increase samples_per_language and add more languages in config.")
|
|
69
|
+
logger.info("=== Finesse Benchmark Database Generation Example Finished Successfully ===")
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
main()
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Writer module for Finesse Benchmark Database Generator
|
|
2
|
+
|
|
3
|
+
This module implements the 'Eternal Scribe': it takes the structured 'strings of beads' output from chunker.py
|
|
4
|
+
and serializes them into probes_atomic.jsonl format. Each line is an independent JSON object with metadata
|
|
5
|
+
for full traceability, ensuring the dataset is reproducible, queryable, and efficient for large-scale use.
|
|
6
|
+
|
|
7
|
+
Key Principles:
|
|
8
|
+
- JSONL format for streaming efficiency (one complete JSON object per line).
|
|
9
|
+
- Assigns immutable 'string_id' for unique identification.
|
|
10
|
+
- Preserves all source metadata (dataset, article_id, lang) for debugging and verification.
|
|
11
|
+
- UTF-8 encoding to handle multilingual content without corruption.
|
|
12
|
+
- Logged serialization progress for transparency.
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
from writer import write_strings_to_probes_atomic
|
|
16
|
+
from chunker import generate_all_strings_of_beads
|
|
17
|
+
strings = generate_all_strings_of_beads()
|
|
18
|
+
write_strings_to_probes_atomic(strings)
|
|
19
|
+
# Results in probes_atomic.jsonl with all probes serialized.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import json
|
|
23
|
+
import logging
|
|
24
|
+
from typing import List, Dict
|
|
25
|
+
|
|
26
|
+
from .config import ProbeConfig
|
|
27
|
+
|
|
28
|
+
# Configure logging for progress tracking
|
|
29
|
+
logging.basicConfig(level=logging.INFO)
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
def write_strings_to_probes_atomic(config: ProbeConfig, all_strings_of_beads: List[Dict]) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Write the structured strings of beads to the atomic probes JSONL file.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
config: ProbeConfig instance specifying output_file and SEED.
|
|
38
|
+
all_strings_of_beads: List of dicts from chunker.py, each with 'source' and 'beads'.
|
|
39
|
+
|
|
40
|
+
Side Effects:
|
|
41
|
+
Creates/appends to config.output_file.
|
|
42
|
+
Each string gets a sequential 'string_id' assigned.
|
|
43
|
+
"""
|
|
44
|
+
output_path = config.output_file
|
|
45
|
+
logger.info(f"Starting serialization to {output_path}. Total strings: {len(all_strings_of_beads)}")
|
|
46
|
+
|
|
47
|
+
with open(output_path, 'w', encoding='utf-8') as file:
|
|
48
|
+
for i, string_data in enumerate(all_strings_of_beads):
|
|
49
|
+
# Assign unique string_id (immutable global identifier)
|
|
50
|
+
string_data['string_id'] = i
|
|
51
|
+
|
|
52
|
+
# Serialize to JSON line
|
|
53
|
+
json_line = json.dumps(string_data, ensure_ascii=False, separators=(',', ':'))
|
|
54
|
+
file.write(json_line + '\n')
|
|
55
|
+
|
|
56
|
+
# Log progress every 1000 strings
|
|
57
|
+
if (i + 1) % 1000 == 0:
|
|
58
|
+
logger.info(f"Serialized {i + 1} strings to {output_path}")
|
|
59
|
+
|
|
60
|
+
total_written = len(all_strings_of_beads)
|
|
61
|
+
logger.info(f"Serialization complete: {total_written} strings written to {output_path}")
|
|
62
|
+
logger.info(f"File structure: Each line is a JSON object with 'string_id', 'source' (metadata), and 'beads' ({config.chunk_token_size}-token chunks).")
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
# Example library usage: Create config and run full pipeline
|
|
66
|
+
from config import ProbeConfig
|
|
67
|
+
from chunker import generate_all_strings_of_beads
|
|
68
|
+
|
|
69
|
+
# User creates and populates config for a small test run
|
|
70
|
+
demo_config = ProbeConfig(
|
|
71
|
+
languages=['en'], # Single language for quick demo
|
|
72
|
+
samples_per_language=3, # Very small sample
|
|
73
|
+
chunk_token_size=64,
|
|
74
|
+
tokenizer_name="google-bert/bert-base-multilingual-cased",
|
|
75
|
+
output_file="demo_probes_atomic.jsonl",
|
|
76
|
+
seed=42
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
print("Generating strings of beads...")
|
|
80
|
+
strings = generate_all_strings_of_beads(demo_config)
|
|
81
|
+
print(f"Generated {len(strings)} strings. Now serializing...")
|
|
82
|
+
write_strings_to_probes_atomic(demo_config, strings)
|
|
83
|
+
print("Pipeline complete. Check demo_probes_atomic.jsonl for output.")
|