-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added creative writing category to category.py and config (#3584)
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## Download dataset | ||
We have pre-generated several category classifier benchmarks and ground truths. You can download them (with [`git-lfs`](https://git-lfs.com) installed) to the directory `classify/` by running | ||
```console | ||
> git clone https://huggingface.co/datasets/lmarena-ai/categories-benchmark-eval | ||
// cd into classify/ and then copy the label_bench directory to the current directory | ||
> cp -r categories-benchmark-eval/label_bench . | ||
``` | ||
Your label_bench directory should follow the structure: | ||
```markdown | ||
├── label_bench/ | ||
│ ├── creative_writing_bench/ | ||
│ │ ├── data/ | ||
│ │ │ └── llama-v3p1-70b-instruct.json | ||
│ │ └── test.json | ||
│ ├── ... | ||
│ ├── your_bench_name/ | ||
│ │ ├── data/ | ||
│ │ │ ├── your_classifier_data_1.json | ||
│ │ │ ├── your_classifier_data_2.json | ||
│ │ │ └── ... | ||
│ │ └── test.json (your ground truth) | ||
└── ... | ||
``` | ||
|
||
## How to evaluate your category classifier? | ||
|
||
To test your new classifier for a new category, you would have to make sure you created the category child class in `category.py`. Then, to generate classification labels, make the necessary edits in `config.yaml` and run | ||
```console | ||
python label.py --config config.yaml --testing | ||
``` | ||
|
||
Then, add your new category bench to `tag_names` in `display_score.py`. After making sure that you also have a correctly formatted ground truth json file, you can report the performance of your classifier by running | ||
```console | ||
python display_score.py --bench <your_bench> | ||
``` | ||
|
||
If you want to check out conflicts between your classifier and ground truth, use | ||
```console | ||
python display_score.py --bench <your_bench> --display-conflict | ||
``` | ||
|
||
Example output: | ||
```console | ||
> python display_score.py --bench if_bench --display-conflict | ||
Model: gpt-4o-mini-2024-07-18 | ||
Accuracy: 0.967 | ||
Precision: 0.684 | ||
Recall: 0.918 | ||
|
||
###### CONFLICT ###### | ||
|
||
Ground Truth = True; Pred = False | ||
\#################### | ||
... | ||
|
||
Ground Truth = False; Pred = True | ||
\#################### | ||
... | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pandas as pd | ||
import argparse | ||
import os | ||
from glob import glob | ||
from sklearn.metrics import recall_score, precision_score | ||
|
||
tag_names = { | ||
"if_bench": ("if_v0.1", "if"), | ||
"math_bench": ("math_v0.1", "math"), | ||
"hard_bench": ("criteria_v0.1", "hard"), | ||
"creative_writing_bench": ("creative_writing_v0.1", "creative_writing"), | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--bench", type=str, default="if_bench") | ||
parser.add_argument("--display-conflict", action="store_true") | ||
args = parser.parse_args() | ||
assert args.bench in tag_names, "Not valid bench argument, add bench if needed." | ||
|
||
test = pd.read_json(os.path.join("label_bench", args.bench, "test.json")) | ||
|
||
for file in glob(os.path.join("label_bench", args.bench, "data", "*.json")): | ||
output = pd.read_json(file) | ||
|
||
tag_map = ( | ||
output[["question_id", "category_tag"]] | ||
.set_index("question_id") | ||
.to_dict("index") | ||
) | ||
|
||
tag_1, tag_2 = tag_names[args.bench] | ||
test["pred"] = test.question_id.map( | ||
lambda id: tag_map[id]["category_tag"][tag_1][tag_2] | ||
) | ||
|
||
accuracy = (test.label == test.pred).mean() | ||
recall = recall_score(y_pred=test.pred, y_true=test.label) | ||
precision = precision_score(y_pred=test.pred, y_true=test.label) | ||
|
||
print(f"Model: {output.model[0]}") | ||
print(f"Accuracy: {round(accuracy, 3)}") | ||
print(f"Precision: {round(precision, 3)}") | ||
print(f"Recall: {round(recall, 3)}") | ||
|
||
if args.display_conflict: | ||
print() | ||
print("###### CONFLICT ######") | ||
print() | ||
conflict = test[test.label & ~test.pred] | ||
print("Ground Truth = True; Pred = False") | ||
prompts = ( | ||
conflict.conversation_a.map(lambda x: x[0]["content"]) | ||
.sample(n=5) | ||
.tolist() | ||
) | ||
for prompt in prompts: | ||
print("####################") | ||
print(prompt) | ||
print() | ||
print() | ||
|
||
conflict = test[~test.label & test.pred] | ||
print("Ground Truth = False; Pred = True") | ||
prompts = ( | ||
conflict.conversation_a.map(lambda x: x[0]["content"]) | ||
.sample(n=5) | ||
.tolist() | ||
) | ||
for prompt in prompts: | ||
print("####################") | ||
print(prompt) | ||
print() | ||
print() | ||
print() |