paperlab-space 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.
Files changed (51) hide show
  1. paperlab_space-0.1.0/.github/workflows/ci.yml +23 -0
  2. paperlab_space-0.1.0/.github/workflows/publish.yml +26 -0
  3. paperlab_space-0.1.0/.gitignore +11 -0
  4. paperlab_space-0.1.0/CITATION.cff +16 -0
  5. paperlab_space-0.1.0/LICENSE +202 -0
  6. paperlab_space-0.1.0/PKG-INFO +155 -0
  7. paperlab_space-0.1.0/PLAN.md +120 -0
  8. paperlab_space-0.1.0/README.md +131 -0
  9. paperlab_space-0.1.0/examples/sentiment/data.csv +13 -0
  10. paperlab_space-0.1.0/examples/sentiment/run.yaml +28 -0
  11. paperlab_space-0.1.0/pyproject.toml +75 -0
  12. paperlab_space-0.1.0/src/paperlab_space/__init__.py +51 -0
  13. paperlab_space-0.1.0/src/paperlab_space/_cli.py +230 -0
  14. paperlab_space-0.1.0/src/paperlab_space/cli.py +22 -0
  15. paperlab_space-0.1.0/src/paperlab_space/config.py +196 -0
  16. paperlab_space-0.1.0/src/paperlab_space/data/__init__.py +17 -0
  17. paperlab_space-0.1.0/src/paperlab_space/data/load.py +260 -0
  18. paperlab_space-0.1.0/src/paperlab_space/data/mapping.py +149 -0
  19. paperlab_space-0.1.0/src/paperlab_space/data/validate.py +157 -0
  20. paperlab_space-0.1.0/src/paperlab_space/errors.py +17 -0
  21. paperlab_space-0.1.0/src/paperlab_space/export/__init__.py +34 -0
  22. paperlab_space-0.1.0/src/paperlab_space/export/excel.py +147 -0
  23. paperlab_space-0.1.0/src/paperlab_space/export/latex.py +117 -0
  24. paperlab_space-0.1.0/src/paperlab_space/export/repro.py +52 -0
  25. paperlab_space-0.1.0/src/paperlab_space/metrics/__init__.py +66 -0
  26. paperlab_space-0.1.0/src/paperlab_space/metrics/base.py +71 -0
  27. paperlab_space-0.1.0/src/paperlab_space/metrics/builtin.py +231 -0
  28. paperlab_space-0.1.0/src/paperlab_space/metrics/normalize.py +103 -0
  29. paperlab_space-0.1.0/src/paperlab_space/prompt.py +94 -0
  30. paperlab_space-0.1.0/src/paperlab_space/py.typed +0 -0
  31. paperlab_space-0.1.0/src/paperlab_space/results.py +179 -0
  32. paperlab_space-0.1.0/src/paperlab_space/runner/__init__.py +26 -0
  33. paperlab_space-0.1.0/src/paperlab_space/runner/backend.py +199 -0
  34. paperlab_space-0.1.0/src/paperlab_space/runner/estimate.py +174 -0
  35. paperlab_space-0.1.0/src/paperlab_space/runner/ratelimit.py +70 -0
  36. paperlab_space-0.1.0/src/paperlab_space/runner/runner.py +224 -0
  37. paperlab_space-0.1.0/tests/__init__.py +0 -0
  38. paperlab_space-0.1.0/tests/conftest.py +37 -0
  39. paperlab_space-0.1.0/tests/fakes.py +60 -0
  40. paperlab_space-0.1.0/tests/test_cli.py +84 -0
  41. paperlab_space-0.1.0/tests/test_config.py +75 -0
  42. paperlab_space-0.1.0/tests/test_estimate.py +66 -0
  43. paperlab_space-0.1.0/tests/test_examples.py +36 -0
  44. paperlab_space-0.1.0/tests/test_export.py +96 -0
  45. paperlab_space-0.1.0/tests/test_live.py +52 -0
  46. paperlab_space-0.1.0/tests/test_load.py +123 -0
  47. paperlab_space-0.1.0/tests/test_mapping.py +78 -0
  48. paperlab_space-0.1.0/tests/test_metrics.py +147 -0
  49. paperlab_space-0.1.0/tests/test_prompt.py +45 -0
  50. paperlab_space-0.1.0/tests/test_runner.py +180 -0
  51. paperlab_space-0.1.0/uv.lock +3187 -0
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v6
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - run: uv sync
20
+ - run: uv run ruff check .
21
+ - run: uv run ruff format --check .
22
+ - run: uv run mypy src tests
23
+ - run: uv run pytest
@@ -0,0 +1,26 @@
1
+ name: Publish to PyPI
2
+
3
+ # Runs when a GitHub release is published. Uses PyPI trusted publishing, so no API
4
+ # token is stored: configure the publisher once at https://pypi.org/manage/account/publishing/
5
+ # (project paperlab-space, workflow publish.yml, environment pypi).
6
+ on:
7
+ release:
8
+ types: [published]
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ permissions:
15
+ id-token: write
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: astral-sh/setup-uv@v6
19
+ - name: Check the tag matches the package version
20
+ run: |
21
+ version=$(grep -Po '^__version__ = "\K[^"]+' src/paperlab_space/__init__.py)
22
+ test "v$version" = "${GITHUB_REF_NAME}" || { echo "Tag ${GITHUB_REF_NAME} != v$version"; exit 1; }
23
+ - run: uv sync
24
+ - run: uv run pytest
25
+ - run: uv build
26
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ .DS_Store
@@ -0,0 +1,16 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use paperlab-space in your research, please cite it as below."
3
+ title: "paperlab-space: no-code LLM evaluation on spreadsheet data"
4
+ type: software
5
+ authors:
6
+ - name: "PaperLab.space contributors"
7
+ repository-code: "https://github.com/paperlab-space/paperlab-core"
8
+ url: "https://paperlab.space"
9
+ license: Apache-2.0
10
+ version: 0.1.0
11
+ date-released: 2026-10-17
12
+ keywords:
13
+ - large language models
14
+ - evaluation
15
+ - reproducibility
16
+ - multilingual
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 PaperLab.space contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.5
2
+ Name: paperlab-space
3
+ Version: 0.1.0
4
+ Summary: Open-source engine for evaluating LLMs on spreadsheet data and producing paper-ready results.
5
+ Project-URL: Homepage, https://paperlab.space
6
+ Project-URL: Repository, https://github.com/paperlab-space/paperlab-core
7
+ Author: PaperLab.space contributors
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: benchmark,evaluation,latex,llm,research
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: charset-normalizer>=3.3
17
+ Requires-Dist: litellm>=1.50
18
+ Requires-Dist: openpyxl>=3.1
19
+ Requires-Dist: pydantic>=2.7
20
+ Requires-Dist: pyyaml>=6.0
21
+ Provides-Extra: cli
22
+ Requires-Dist: typer>=0.12; extra == 'cli'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # PaperLab.space core
26
+
27
+ ```bash
28
+ pip install 'paperlab-space[cli]'
29
+ ```
30
+
31
+ Evaluate LLMs on your own spreadsheet data and get paper-ready results.
32
+
33
+ Give it an Excel or CSV file, say which columns are inputs and answers, pick models and metrics, and get back an Excel workbook of outputs and scores, a LaTeX table for your paper, and a reproducibility config. `paperlab-space` is the open-source engine behind [PaperLab.space](https://paperlab.space); use it from the command line or from Python.
34
+
35
+ - **Spreadsheets in:** `.xlsx` (any sheet), `.csv`, `.tsv`, with encoding detection and Unicode-safe handling for non-Latin scripts. Validation catches empty cells, duplicate IDs, and garbled text before you spend API calls.
36
+ - **Any model:** OpenRouter (including free models), Gemini, OpenAI, Anthropic, Ollama, and everything else [LiteLLM](https://docs.litellm.ai/docs/providers) supports, run side by side. You bring your own API keys.
37
+ - **Robust runs:** per-model rate limits tuned for free tiers, retries with backoff, and resume after interruption. A cost and time estimate is shown before anything is sent.
38
+ - **Metrics:** exact match, accuracy (with label extraction from chatty answers), precision/recall/F1, token F1. Tokenisation handles Chinese, Japanese, Thai, and Burmese.
39
+ - **Paper-ready output:** Excel, a booktabs LaTeX table, and a YAML config recording model versions, prompt, seed, metric settings, and a hash of your data.
40
+
41
+ > **Status:** early release (0.1). See [PLAN.md](PLAN.md) for the roadmap: BLEU/chrF/ROUGE, LLM-as-judge, and significance tests are next.
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install 'paperlab-space[cli]'
47
+ ```
48
+
49
+ Until the first PyPI release, install from GitHub:
50
+
51
+ ```bash
52
+ pip install 'paperlab-space[cli] @ git+https://github.com/paperlab-space/paperlab-core'
53
+ ```
54
+
55
+ ## Quickstart (command line)
56
+
57
+ ```bash
58
+ export OPENROUTER_API_KEY=sk-or-... # free key from https://openrouter.ai
59
+ export GEMINI_API_KEY=... # free key from https://aistudio.google.com
60
+
61
+ paperlab-space init my_data.xlsx # writes run.yaml, guessing the column roles
62
+ paperlab-space validate my_data.xlsx -i question -e answer # check the data, preview JSONL
63
+ paperlab-space estimate run.yaml # tokens, cost, and time; no requests sent
64
+ paperlab-space run run.yaml # writes results-run/
65
+ ```
66
+
67
+ `run.yaml` looks like this (see [examples/sentiment](examples/sentiment)):
68
+
69
+ ```yaml
70
+ dataset:
71
+ path: data.csv
72
+ mapping:
73
+ input: text # column(s) available to the prompt
74
+ context: [language] # extra columns available to the prompt
75
+ expected: label # the answer key (never shown to the model)
76
+ id: id
77
+ prompt: |-
78
+ Classify the sentiment of this {language} text as "positive" or "negative".
79
+ Text: {text}
80
+ models:
81
+ - openrouter/nvidia/nemotron-3-super-120b-a12b:free
82
+ - id: gemini/gemini-2.5-flash
83
+ temperature: 0
84
+ metrics:
85
+ - name: accuracy
86
+ labels: [positive, negative]
87
+ - f1
88
+ seed: 42
89
+ ```
90
+
91
+ The output folder contains:
92
+
93
+ | File | What it is |
94
+ | --- | --- |
95
+ | `results.xlsx` | Summary sheet (scores, failures, cost), per-row outputs and scores, and the config |
96
+ | `table.tex` | A booktabs table to `\input{}` into your paper |
97
+ | `run.yaml` | The reproducibility config: re-run with `paperlab-space run run.yaml` |
98
+ | `results.json` | Everything, for `paperlab-space run run.yaml --resume results.json` after an interruption |
99
+
100
+ Free models change often; `paperlab-space run` stops a model early with a clear message if its ID no longer exists. Browse current free models at [openrouter.ai/models](https://openrouter.ai/models?q=free).
101
+
102
+ ## Quickstart (Python)
103
+
104
+ ```python
105
+ from paperlab_space import ColumnMapping, RunConfig, estimate, export, load_dataset, run
106
+
107
+ data = load_dataset("my_data.xlsx", sheet="test")
108
+ config = RunConfig(
109
+ mapping=ColumnMapping(input="question", expected="answer"),
110
+ prompt="Answer briefly: {question}",
111
+ models=["openrouter/nvidia/nemotron-3-super-120b-a12b:free", "gemini/gemini-2.5-flash"],
112
+ metrics=["exact_match", "token_f1"],
113
+ )
114
+ print(estimate(config, data))
115
+ results = run(config, data)
116
+ print(results.scores["gemini-2.5-flash"]["exact_match"].value)
117
+ export.write_all(results, "results/")
118
+ ```
119
+
120
+ `run` works in scripts and Jupyter notebooks. Use `await arun(...)` inside your own async code.
121
+
122
+ ## Metrics
123
+
124
+ Run `paperlab-space metrics` for the list. Every metric takes normalisation options in the config:
125
+
126
+ ```yaml
127
+ metrics:
128
+ - exact_match # case-insensitive, trims punctuation like "Paris."
129
+ - name: exact_match
130
+ label: exact_match_strict # same metric again with different options
131
+ ignore_case: false
132
+ trim_punctuation: false
133
+ - name: f1
134
+ average: macro # macro | micro | weighted
135
+ ```
136
+
137
+ Custom metrics subclass `paperlab_space.metrics.Metric` and use the `@register` decorator.
138
+
139
+ ## Citing
140
+
141
+ If paperlab-space helps your research, please cite it. See [CITATION.cff](CITATION.cff), or use "Cite this repository" on GitHub.
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ uv sync
147
+ uv run pytest # unit tests, no network
148
+ uv run pytest -m live # real-provider smoke tests (needs API keys)
149
+ uv run ruff check . && uv run ruff format --check .
150
+ uv run mypy src tests
151
+ ```
152
+
153
+ ## License
154
+
155
+ [Apache 2.0](LICENSE)
@@ -0,0 +1,120 @@
1
+ # PaperLab.space core plan
2
+
3
+ This repo (`paperlab-core`) holds the open-source evaluation engine behind [PaperLab.space](https://paperlab.space). It takes a spreadsheet, runs one or more LLMs over it, scores the outputs, and writes paper-ready results. It is a plain Python library plus a small CLI, published to PyPI as `paperlab-space` (`import paperlab_space`, command `paperlab-space`). The bare name `paperlab` belongs to an unrelated PyPI project, so the package name carries the `.space` brand, as the PRD intends.
4
+
5
+ ## Scope and boundary
6
+
7
+ Core is pure **input → eval → output**. It never imports web code: no database, auth, HTTP server, payments, or job-queue infrastructure. Anything stateful across sessions belongs to the platform.
8
+
9
+ | In core | Not in core (platform) |
10
+ | --- | --- |
11
+ | Excel/CSV loading, column mapping, validation, JSONL conversion | File upload, storage, user accounts |
12
+ | Prompt templating | Prompt editor UI |
13
+ | Model runner: LiteLLM wrapper, per-provider rate limiting, retries, checkpoint/resume to a local file | Distributed job queue, workers, progress over websockets |
14
+ | Metrics | Credits, billing, cost markup |
15
+ | Excel / LaTeX / reproducibility-config export | Run history, sharing |
16
+ | Cost and time estimates (from token counts and public prices) | Managed API keys, encrypted key storage |
17
+
18
+ The platform calls core through its public API only. If the platform needs a hook (e.g. a progress callback), core exposes a generic one.
19
+
20
+ ## Tech choices
21
+
22
+ - Python ≥ 3.10, `src/` layout, built with hatchling, managed with `uv`
23
+ - `openpyxl` + the standard `csv` module for input (no pandas: lighter installs and full control over cell-to-text conversion), `charset-normalizer` for legacy CSV encodings
24
+ - `pydantic` v2 for config models (serialisable, validated, clear error messages)
25
+ - `litellm` for one interface to every provider, imported lazily so `import paperlab_space` stays fast
26
+ - `asyncio` runner with an even-spacing rate limiter per model
27
+ - Own `{column}` placeholder syntax (column names may contain spaces; `{{`/`}}` for literal braces)
28
+ - `ruff` for lint/format, `pytest` for tests, `mypy --strict` for types
29
+ - `typer` for the CLI (optional extra: `pip install 'paperlab-space[cli]'`)
30
+
31
+ ## Package layout
32
+
33
+ ```
34
+ src/paperlab_space/
35
+ data/ load.py (Excel/CSV -> Dataset), mapping.py (ColumnMapping, JSONL), validate.py
36
+ prompt.py PromptTemplate
37
+ config.py RunConfig, ModelSpec, MetricSpec (the single object describing a run)
38
+ runner/ backend.py (LiteLLM + Backend protocol), ratelimit.py, runner.py, estimate.py
39
+ metrics/ base.py (interface + registry), builtin.py, normalize.py
40
+ results.py RunResults, JSON save/load
41
+ export/ excel.py, latex.py, repro.py
42
+ _cli.py the `paperlab` command
43
+ ```
44
+
45
+ Central object: **`RunConfig`**, which holds data source, column mapping, prompt template, models (+ temperature, seed, max tokens, rate limit), and metrics. The same object drives a run and is written out as the reproducibility config, so a run is reproducible from its exported config alone.
46
+
47
+ ## Public API
48
+
49
+ ```python
50
+ from paperlab_space import ColumnMapping, RunConfig, estimate, export, load_dataset, run
51
+
52
+ data = load_dataset("data.xlsx", sheet="test")
53
+ mapping = ColumnMapping(input="sentence", expected="gold", id="row_id")
54
+ print(data.map(mapping).validate()) # empty cells, duplicate IDs, encoding issues
55
+
56
+ config = RunConfig(
57
+ mapping=mapping,
58
+ prompt="Translate to English: {sentence}",
59
+ models=["openrouter/nvidia/nemotron-3-super-120b-a12b:free", "gemini/gemini-2.5-flash"],
60
+ metrics=["exact_match", "token_f1"],
61
+ )
62
+ print(estimate(config, data)) # tokens, cost, time per model
63
+ results = run(config, data, on_progress=print)
64
+ export.write_all(results, "results/") # results.xlsx, table.tex, run.yaml, results.json
65
+ ```
66
+
67
+ The platform plugs in through: `LiteLLMBackend(api_keys=...)` (keys never enter configs or results), the `Backend` protocol, `on_progress`, `arun` for its own event loop, and `previous=` / `RunResults.load_json` to resume.
68
+
69
+ ## Milestones
70
+
71
+ ### M0: Skeleton ✅
72
+ - Package, CI, license, README, plan
73
+
74
+ ### M1: Data in ✅
75
+ - Load `.xlsx` (multiple sheets), `.csv`, `.tsv`; UTF-8/BOM first, then encoding detection (tested with CP874 Thai, Shift-JIS, GBK)
76
+ - Unicode NFC normalisation; fixtures in Burmese, Thai, Chinese, Japanese, Korean
77
+ - Excel cell types converted to text predictably (`2.0` -> `2`, dates -> ISO); blank/duplicate headers fixed
78
+ - `ColumnMapping`: input column(s), context columns, expected column, row ID, multiple answers via delimiter; the expected column can never leak into the prompt
79
+ - Validation report: empty cells, empty/duplicate IDs, mojibake, invisible characters
80
+ - JSONL conversion + preview
81
+
82
+ ### M2: Prompt + runner ✅
83
+ - `PromptTemplate` (user + optional system prompt) checked against mapped columns
84
+ - Async runner over LiteLLM; tested live against **OpenRouter** and **Gemini**
85
+ - Rate limits per model: OpenRouter `:free` 20/min, Gemini Flash 10/min, Gemini Pro 5/min; overridable
86
+ - Retries with exponential backoff + jitter, honouring `Retry-After`; a rejected API key or unknown model stops that model immediately instead of failing every row
87
+ - Resume: rows that succeeded in an earlier run are reused (pulled forward from v1.1)
88
+ - Pre-run estimate: tokens (script-aware heuristic), cost (LiteLLM price table), wall time, warnings (OpenRouter daily caps, Gemini free-tier data use)
89
+ - Works in scripts and Jupyter
90
+
91
+ ### M3: Metrics ✅
92
+ - Metric interface (`compute(predictions, references) -> MetricResult`) with a registry so users can add their own
93
+ - `exact_match`, `accuracy` (optional label extraction from chatty answers), `f1` (macro/micro/weighted, per-class), `token_f1` (character tokens for Chinese, Japanese, Thai, Burmese)
94
+ - Configurable normalisation (NFKC, case, punctuation), recorded in the reproducibility config
95
+ - Multi-answer support; failed requests count as wrong unless `count_failed: false`
96
+ - Metrics are checked before any request is sent
97
+
98
+ ### M4: Export ✅
99
+ - Excel: Summary (scores, failures, cost, tokens), Outputs (per-row outputs and scores), Config sheets; formula injection blocked
100
+ - LaTeX: booktabs table, best score bolded, escaped names, percent or raw
101
+ - Reproducibility YAML: core/LiteLLM/Python versions, provider-reported model versions, dataset SHA-256, full config (dataset path reduced to file name); loads back with `RunConfig.from_yaml`
102
+ - Full results JSON for resuming and sharing
103
+
104
+ ### M5: CLI + first release (in progress)
105
+ - ✅ `paperlab-space init | validate | estimate | run [--resume] | metrics`
106
+ - ✅ `CITATION.cff`, release workflow (PyPI trusted publishing)
107
+ - ⬜ Configure the PyPI trusted publisher, then publish `0.1.0`
108
+ - ⬜ Docs site (mkdocs-material)
109
+
110
+ ### After 0.1 (matches the product roadmap)
111
+ - v1.1: separate answer-key file joined by row ID; BLEU, chrF, ROUGE (`sacrebleu`, `rouge-score`); Ollama and more providers documented and tested; Zawgyi detection for Burmese input
112
+ - v1.2: LLM-as-judge (with reference, and rubric-only with user rubric); significance tests and bootstrap confidence intervals
113
+ - v2: inter-annotator agreement metrics (Cohen's/Fleiss' kappa, Krippendorff's alpha)
114
+
115
+ ## Quality bar
116
+
117
+ - Every public function typed (`mypy --strict`) and documented
118
+ - No network access in unit tests; `uv run pytest -m live` for real-provider smoke tests
119
+ - Deterministic outputs given the same config + seed where providers allow it
120
+ - Semantic versioning; the reproducibility config records the exact core version