persianeval 0.1.1__py3-none-any.whl
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.
- persianeval/__init__.py +42 -0
- persianeval/cli.py +154 -0
- persianeval/data/README.md +85 -0
- persianeval/data/v1/SHA256SUMS +8 -0
- persianeval/data/v1/bias_detection.jsonl +200 -0
- persianeval/data/v1/code_with_persian_comments.jsonl +200 -0
- persianeval/data/v1/cultural_knowledge.jsonl +200 -0
- persianeval/data/v1/rag_faithfulness.jsonl +200 -0
- persianeval/data/v1/reading_comprehension.jsonl +200 -0
- persianeval/data/v1/reasoning.jsonl +200 -0
- persianeval/data/v1/spelling.jsonl +200 -0
- persianeval/data/v1/translation_fa_en.jsonl +200 -0
- persianeval/harness/__init__.py +48 -0
- persianeval/harness/providers.py +493 -0
- persianeval/harness/results.py +135 -0
- persianeval/harness/runner.py +284 -0
- persianeval/harness/scorers.py +308 -0
- persianeval/leaderboard/__init__.py +1 -0
- persianeval/leaderboard/generate.py +213 -0
- persianeval/leaderboard/templates/index.html.j2 +162 -0
- persianeval/py.typed +0 -0
- persianeval/tasks/__init__.py +109 -0
- persianeval/tasks/base.py +237 -0
- persianeval/tasks/bias_detection.py +50 -0
- persianeval/tasks/code_with_persian_comments.py +46 -0
- persianeval/tasks/cultural_knowledge.py +30 -0
- persianeval/tasks/rag_faithfulness.py +35 -0
- persianeval/tasks/reading_comprehension.py +28 -0
- persianeval/tasks/reasoning.py +50 -0
- persianeval/tasks/spelling.py +34 -0
- persianeval/tasks/translation_fa_en.py +42 -0
- persianeval-0.1.1.dist-info/METADATA +246 -0
- persianeval-0.1.1.dist-info/RECORD +36 -0
- persianeval-0.1.1.dist-info/WHEEL +4 -0
- persianeval-0.1.1.dist-info/entry_points.txt +2 -0
- persianeval-0.1.1.dist-info/licenses/LICENSE +201 -0
persianeval/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""PersianEval: the first serious open-source benchmark for Persian (Farsi) LLMs.
|
|
2
|
+
|
|
3
|
+
PersianEval ships 8 frozen evaluation tasks, an async provider-agnostic
|
|
4
|
+
harness (OpenAI, Anthropic, Ollama, vLLM), reproducible scoring
|
|
5
|
+
(exact / fuzzy / LLM-as-judge) and a static leaderboard generator.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from importlib import metadata
|
|
11
|
+
from typing import Final
|
|
12
|
+
|
|
13
|
+
from persianeval.harness.results import ItemResult, RunResult
|
|
14
|
+
from persianeval.tasks import (
|
|
15
|
+
AbstractTask,
|
|
16
|
+
Sample,
|
|
17
|
+
ScoringKind,
|
|
18
|
+
ScoringSpec,
|
|
19
|
+
all_task_classes,
|
|
20
|
+
get_task,
|
|
21
|
+
list_task_names,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
try: # pragma: no cover - depends on installation state
|
|
25
|
+
_detected_version = metadata.version("persianeval")
|
|
26
|
+
except metadata.PackageNotFoundError: # pragma: no cover - editable/source checkout
|
|
27
|
+
_detected_version = "0.0.0.dev0"
|
|
28
|
+
|
|
29
|
+
__version__: Final[str] = _detected_version
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"AbstractTask",
|
|
33
|
+
"ItemResult",
|
|
34
|
+
"RunResult",
|
|
35
|
+
"Sample",
|
|
36
|
+
"ScoringKind",
|
|
37
|
+
"ScoringSpec",
|
|
38
|
+
"__version__",
|
|
39
|
+
"all_task_classes",
|
|
40
|
+
"get_task",
|
|
41
|
+
"list_task_names",
|
|
42
|
+
]
|
persianeval/cli.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""Typer-based command line interface for PersianEval.
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
persianeval tasks
|
|
5
|
+
persianeval run --task reasoning --provider openai --model gpt-4o --rpm 60
|
|
6
|
+
persianeval run --task spelling --provider ollama --model qwen2.5:7b-instruct
|
|
7
|
+
persianeval leaderboard --results-dir results --out leaderboard
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import logging
|
|
14
|
+
from importlib import metadata
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Annotated, Final
|
|
17
|
+
|
|
18
|
+
import typer
|
|
19
|
+
|
|
20
|
+
from persianeval.harness.providers import ProviderError, create_provider
|
|
21
|
+
from persianeval.harness.results import save_json, save_parquet
|
|
22
|
+
from persianeval.harness.runner import run_task
|
|
23
|
+
from persianeval.leaderboard.generate import generate_site
|
|
24
|
+
from persianeval.tasks import get_task
|
|
25
|
+
|
|
26
|
+
app: Final[typer.Typer] = typer.Typer(
|
|
27
|
+
name="persianeval",
|
|
28
|
+
help="Open-source benchmark for Persian (Farsi) LLMs.",
|
|
29
|
+
no_args_is_help=True,
|
|
30
|
+
add_completion=False,
|
|
31
|
+
pretty_exceptions_show_locals=False,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
_LOGGING_FORMAT: Final[str] = "%(asctime)s %(levelname)s %(name)s: %(message)s"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _version_callback(value: bool) -> None:
|
|
38
|
+
if value:
|
|
39
|
+
typer.echo(f"persianeval {metadata.version('persianeval')}")
|
|
40
|
+
raise typer.Exit
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@app.command()
|
|
44
|
+
def tasks() -> None:
|
|
45
|
+
"""List all registered evaluation tasks."""
|
|
46
|
+
from persianeval.tasks import all_task_classes
|
|
47
|
+
|
|
48
|
+
typer.echo(f"{'TASK':<28} {'MIN SAMPLES':>11} TITLE")
|
|
49
|
+
for task_class in all_task_classes().values():
|
|
50
|
+
instance = task_class()
|
|
51
|
+
typer.echo(
|
|
52
|
+
f"{instance.name:<28} {instance.min_samples:>11} {instance.title_en} — {instance.title_fa}"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@app.command()
|
|
57
|
+
def run(
|
|
58
|
+
task: Annotated[str, typer.Option(help="Task name (see `persianeval tasks`).")],
|
|
59
|
+
model: Annotated[str, typer.Option(help="Model identifier, e.g. gpt-4o or qwen2.5:7b-instruct.")],
|
|
60
|
+
provider: Annotated[str, typer.Option(help="openai | anthropic | ollama | vllm | dummy")] = "openai",
|
|
61
|
+
base_url: Annotated[str | None, typer.Option(help="Endpoint override (vLLM/self-hosted).")] = None,
|
|
62
|
+
org: Annotated[str, typer.Option(help="Organization metadata for the leaderboard.")] = "",
|
|
63
|
+
license_id: Annotated[str, typer.Option("--license", help="Model license metadata.")] = "",
|
|
64
|
+
limit: Annotated[int | None, typer.Option(help="Seeded random subset size.")] = None,
|
|
65
|
+
max_requests: Annotated[
|
|
66
|
+
int | None, typer.Option("--max-requests", help="Hard cap on evaluated items (API budget).")
|
|
67
|
+
] = None,
|
|
68
|
+
max_requests_per_minute: Annotated[
|
|
69
|
+
int | None,
|
|
70
|
+
typer.Option("--max-requests-per-minute", help="Per-provider rate limit (RPM)."),
|
|
71
|
+
] = None,
|
|
72
|
+
max_tokens: Annotated[int, typer.Option(help="Completion budget per item.")] = 1024,
|
|
73
|
+
concurrency: Annotated[int, typer.Option(help="Maximum in-flight API requests.")] = 4,
|
|
74
|
+
seed: Annotated[int, typer.Option(help="RNG seed for subset selection.")] = 42,
|
|
75
|
+
temperature: Annotated[float, typer.Option(help="Sampling temperature (default 0.0).")] = 0.0,
|
|
76
|
+
out_dir: Annotated[Path, typer.Option("--out", help="Directory for result files.")] = Path("results"),
|
|
77
|
+
cache_dir: Annotated[Path, typer.Option(help="Response cache directory.")] = Path(".persianeval_cache"),
|
|
78
|
+
no_cache: Annotated[bool, typer.Option(help="Disable the response cache.")] = False,
|
|
79
|
+
) -> None:
|
|
80
|
+
"""Evaluate a task against a model and write JSON + Parquet results."""
|
|
81
|
+
logging.basicConfig(level=logging.INFO, format=_LOGGING_FORMAT)
|
|
82
|
+
try:
|
|
83
|
+
task_obj = get_task(task)
|
|
84
|
+
provider_obj = create_provider(provider, model, base_url=base_url, rpm=max_requests_per_minute)
|
|
85
|
+
except (KeyError, ProviderError, ValueError) as exc:
|
|
86
|
+
typer.secho(f"error: {exc}", fg=typer.colors.RED, err=True)
|
|
87
|
+
raise typer.Exit(code=2) from exc
|
|
88
|
+
|
|
89
|
+
typer.echo(
|
|
90
|
+
f"task={task_obj.name} provider={provider_obj.provider_name} model={model} "
|
|
91
|
+
f"seed={seed} temperature={temperature} concurrency={concurrency}"
|
|
92
|
+
)
|
|
93
|
+
try:
|
|
94
|
+
result = asyncio.run(
|
|
95
|
+
run_task(
|
|
96
|
+
task_obj,
|
|
97
|
+
provider_obj,
|
|
98
|
+
limit=limit,
|
|
99
|
+
max_requests=max_requests,
|
|
100
|
+
seed=seed,
|
|
101
|
+
temperature=temperature,
|
|
102
|
+
max_tokens=max_tokens,
|
|
103
|
+
concurrency=concurrency,
|
|
104
|
+
cache_root=None if no_cache else cache_dir,
|
|
105
|
+
org=org,
|
|
106
|
+
license_id=license_id,
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
finally:
|
|
110
|
+
asyncio.run(provider_obj.aclose())
|
|
111
|
+
|
|
112
|
+
slug = f"{result.task}__{model}".replace("/", "-")
|
|
113
|
+
json_path = save_json(result, out_dir / f"{slug}.json")
|
|
114
|
+
parquet_path = save_parquet(result, out_dir / f"{slug}.parquet")
|
|
115
|
+
|
|
116
|
+
accuracy = result.metrics.get("accuracy", 0.0)
|
|
117
|
+
mean_score = result.metrics.get("mean_score", 0.0)
|
|
118
|
+
typer.echo("-" * 56)
|
|
119
|
+
typer.echo(f"accuracy : {accuracy:.2%} mean score: {mean_score:.3f}")
|
|
120
|
+
typer.echo(f"items : {result.n_items} ({result.n_cached} served from cache)")
|
|
121
|
+
typer.echo(f"results : {json_path}")
|
|
122
|
+
typer.echo(f"results : {parquet_path}")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@app.command()
|
|
126
|
+
def leaderboard(
|
|
127
|
+
results_dir: Annotated[
|
|
128
|
+
Path, typer.Option(exists=True, file_okay=False, help="Directory containing *.json run results.")
|
|
129
|
+
],
|
|
130
|
+
out: Annotated[Path, typer.Option(help="Output directory for the static site.")] = Path("leaderboard"),
|
|
131
|
+
title: Annotated[str, typer.Option(help="Site title.")] = "PersianEval Leaderboard",
|
|
132
|
+
) -> None:
|
|
133
|
+
"""Build the static leaderboard site from run results."""
|
|
134
|
+
index_path = generate_site(results_dir, out, title=title)
|
|
135
|
+
typer.echo(f"leaderboard written to {index_path}")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@app.callback()
|
|
139
|
+
def _root_callback(
|
|
140
|
+
version: Annotated[
|
|
141
|
+
bool | None,
|
|
142
|
+
typer.Option("--version", callback=_version_callback, is_eager=True, help="Show version and exit."),
|
|
143
|
+
] = None,
|
|
144
|
+
) -> None:
|
|
145
|
+
"""PersianEval command line interface."""
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def main() -> None:
|
|
149
|
+
"""Console-script entry point (see ``[project.scripts]`` in pyproject.toml)."""
|
|
150
|
+
app()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if __name__ == "__main__": # pragma: no cover
|
|
154
|
+
app()
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# PersianEval v1 Data — Provenance, Licenses & Methodology
|
|
2
|
+
|
|
3
|
+
<div dir="rtl">
|
|
4
|
+
|
|
5
|
+
## فارسی
|
|
6
|
+
|
|
7
|
+
این پوشه شامل مجموعهدادههای فریزشدهٔ نسخهٔ v1 است. هر فایل JSONL با اسکیمای صریح
|
|
8
|
+
`{"id", "prompt", "expected", "metadata"}` و فایل `SHA256SUMS` برای اطمینان از تغییرنکردن
|
|
9
|
+
دادهها ارائه میشود. هیچ نمونهای پس از انتشار نسخه تغییر نمیکند؛ نسخههای بعدی در پوشههای
|
|
10
|
+
جدا (v2 و ...) منتشر میشوند.
|
|
11
|
+
|
|
12
|
+
| فایل | تعداد نمونه | روش گردآوری | هدف نسخهٔ 0.2 |
|
|
13
|
+
|---|---|---|---|
|
|
14
|
+
| `reasoning.jsonl` | ۲۰۰ | تولید برنامهنویسیشده با پاسخهای محاسبهشده (۷ خانوادهٔ مسئله) | ۳۰۰ |
|
|
15
|
+
| `spelling.jsonl` | ۲۰۰ | تولید سیستماتیک از بانک واژه/جمله با خرابی عمدی همگردانی | ۲۵۰ |
|
|
16
|
+
| `cultural_knowledge.jsonl` | ۲۰۰ | نگارش دستی (سطح کتابهای درسی، حقایق بااطمینان) | ۳۰۰ |
|
|
17
|
+
| `reading_comprehension.jsonl` | ۲۰۰ | ۵۰ متن دستنویس × ۴ پرسش | ۳۰۰ (۷۵ متن) |
|
|
18
|
+
| `translation_fa_en.jsonl` | ۲۰۰ | جفتجملههای دستنویس در ۴ سبک | ۳۰۰ (زیرمجموعهٔ FLORES-200) |
|
|
19
|
+
| `rag_faithfulness.jsonl` | ۲۰۰ | ۵۰ متن سنتزی × ۲ پرسش × پاسخ وفادار/غیروفادار | ۳۰۰ |
|
|
20
|
+
| `bias_detection.jsonl` | ۲۰۰ | ۱۴ قالب روی ۹ گروه ایرانی + ۲۴ آیتم جنسیتی + ۵۰ کنترل | ۳۰۰ |
|
|
21
|
+
| `code_with_persian_comments.jsonl` | ۲۰۰ | ۱۵ خانوادهٔ تابع با واریانتهای متفاوت و تستهای محاسبهشده | ۳۰۰ |
|
|
22
|
+
|
|
23
|
+
### روششناسی در یک نگاه
|
|
24
|
+
|
|
25
|
+
- **پاسخ صحیح با ساخت تضمینشده:** در تسکهای تولیدشده بهصورت برنامهنویسی (reasoning،
|
|
26
|
+
spelling، rag، code)، پاسخ مرجع با کد محاسبه میشود، نه با حدس انسانی.
|
|
27
|
+
- **متنهای سنتزی برای RAG:** متنهای `rag_faithfulness` آگاهانه سنتزیاند (نهادها و اعداد
|
|
28
|
+
فرضی) چون معیار سنجش «وفاداری به متنِ ارائهشده» است نه دانش جهانی؛ این کار از اختلاف نظر
|
|
29
|
+
واقعیتی هم جلوگیری میکند.
|
|
30
|
+
- **حقایق با اطمینان بالا برای دانش فرهنگی:** پرسشهای `cultural_knowledge` به حقایق
|
|
31
|
+
سطح کتابهای درسی محدود شدهاند.
|
|
32
|
+
- **داوری شفاف:** پرامپت داورِ هر تسک LLM-judge در سورس همان کلاس تسک و در
|
|
33
|
+
`docs/methodology.md` عمومی است.
|
|
34
|
+
|
|
35
|
+
### لایسنس
|
|
36
|
+
|
|
37
|
+
کل مجموعهداده (مثل کد) تحت **Apache-2.0** منتشر میشود و بازاستفادهٔ تجاری و پژوهشی آزاد است.
|
|
38
|
+
هیچ بخشی از داده از دیتاستهای محدودیتدار کپی نشده است؛ برای v0.2 که زیرمجموعهای از
|
|
39
|
+
FLORES-200 (لایسنس CC-BY-SA) اضافه میشود، فایل لایسنس جداگانه در همین پوشه قرار میگیرد.
|
|
40
|
+
|
|
41
|
+
### بازتولید
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python scripts/generate_data/run_all.py # همهٔ فایلها + SHA256SUMS را بازتولید میکند
|
|
45
|
+
sha256sum -c src/persianeval/data/v1/SHA256SUMS --directory src/persianeval/data/v1
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
<div dir="ltr">
|
|
53
|
+
|
|
54
|
+
## English
|
|
55
|
+
|
|
56
|
+
This directory holds the frozen v1 datasets. Every JSONL file follows the explicit schema
|
|
57
|
+
`{"id", "prompt", "expected", "metadata"}` and is covered by `SHA256SUMS` so any
|
|
58
|
+
accidental mutation is caught in CI. Samples never change after a release; future dataset
|
|
59
|
+
revisions ship in new directories (v2, ...).
|
|
60
|
+
|
|
61
|
+
See the Persian table above for per-task counts, collection method and the v0.2 target.
|
|
62
|
+
Highlights:
|
|
63
|
+
|
|
64
|
+
- **Correct-by-construction answers** for programmatically generated tasks (reasoning,
|
|
65
|
+
spelling, rag, code): reference answers are computed by code, not guessed.
|
|
66
|
+
- **Synthetic passages** for RAG faithfulness — deliberately fictional entities/numbers,
|
|
67
|
+
because the skill under test is grounding in the *provided* text, not world knowledge.
|
|
68
|
+
- **High-confidence textbook facts only** for cultural knowledge.
|
|
69
|
+
- **Judge prompts are public** — they live in each task class source and in
|
|
70
|
+
`docs/methodology.md`.
|
|
71
|
+
|
|
72
|
+
### License
|
|
73
|
+
|
|
74
|
+
The datasets ship under the same **Apache-2.0** license as the code. No data was copied
|
|
75
|
+
from restricted datasets; the planned FLORES-200 subset (CC-BY-SA) for v0.2 will carry its
|
|
76
|
+
own license note in this directory.
|
|
77
|
+
|
|
78
|
+
### Reproducibility
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python scripts/generate_data/run_all.py # regenerates every file + SHA256SUMS
|
|
82
|
+
sha256sum -c src/persianeval/data/v1/SHA256SUMS --directory src/persianeval/data/v1
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
1ec4894ff2b520522fbbd902fe5fbff90a0bddb6549d01ef0468e63114c46096 bias_detection.jsonl
|
|
2
|
+
8dd4ef284c985df4fc94364ef95b0890772a0bca4359d42d8043d5d205e1bc67 code_with_persian_comments.jsonl
|
|
3
|
+
827f55949bdeb8183aae2ba20f4dfd32e33a2a44efdbcd81934bd37c7b12b31b cultural_knowledge.jsonl
|
|
4
|
+
bf33b86a3d72fec845ec0c0929fb01851efb9bee3bdda9df859e1b1c823c07c9 rag_faithfulness.jsonl
|
|
5
|
+
4bdd570f4f87f4703553191f54e174de228aad55f24bcfd5a6377f55d1c2d230 reading_comprehension.jsonl
|
|
6
|
+
4ec420efda9e543a0bb6189d10d07b533a7fa51c7ad80ca2ff9b9db876256f4c reasoning.jsonl
|
|
7
|
+
4d94a03467099fb2bca20451c1a2810198e5d7e6753599b447c957f14cfdea51 spelling.jsonl
|
|
8
|
+
56ec29265407dd40501d53e8183e1b6c5ce9691a0d74c5326ecd26abcbd7ecf1 translation_fa_en.jsonl
|