Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example(dataset): ds z bench #2070

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions example/datasets/LLM/z_bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: The `z-bench` Dataset
---

## The z-bench Dataset Description

- [Homepage](https://github.com/zhenbench/z-bench)

## The `z-bench` dataset Structure

### Data Fields

- `data` of type dict:
- `prompt`: `str`
- `task_type`: `str`
- `ref_answer`: `str`
- `gpt3d5`: `str`
- `gpt4`: `str`

## Build `z-bench` sample Dataset locally

```shell
python3 dataset.py common
```

## Example

Output the `10`th record of the `z-bench` dataset.

```shell
python3 example.py common
```
44 changes: 44 additions & 0 deletions example/datasets/LLM/z_bench/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import csv
import sys
from io import StringIO

import requests

from starwhale import Link, Image, dataset, MIMEType # noqa: F401
from starwhale.utils.retry import http_retry

PATH_ROOT = "https://raw.githubusercontent.com/zhenbench/z-bench/main"


@http_retry
def request_link_text(index_link):
return requests.get(index_link, timeout=10).text


def build_ds(ds_name: str) -> None:
ds = dataset(f"z_bench_{ds_name}", create="auto")
csv_reader = csv.reader(
StringIO(request_link_text(f"{PATH_ROOT}/{ds_name}.samples.csv")), delimiter=","
)
line_count = 0
for row in csv_reader:
if line_count == 0:
print(f'Column names are {", ".join(row)}')
line_count += 1
else:
ds.append(
{
"prompt": row[0],
"task_type": row[1],
"ref_answer": row[2],
"gpt3d5": row[3],
"gpt4": row[4],
}
)

ds.commit()
ds.close()


if __name__ == "__main__":
build_ds(sys.argv[1])
8 changes: 8 additions & 0 deletions example/datasets/LLM/z_bench/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys

from starwhale import dataset

ds_name = sys.argv[1]
ds = dataset(f"z_bench_{ds_name}/version/latest")
row = ds[10]
print(row.data)