Skip to content

Commit

Permalink
Already Said That Eval (openai#1490)
Browse files Browse the repository at this point in the history
@JunShern will review this

# Thank you for contributing an eval! ♥️

🚨 Please make sure your PR follows these guidelines, **failure to follow
the guidelines below will result in the PR being closed automatically**.
Note that even if the criteria are met, that does not guarantee the PR
will be merged nor GPT-4 access be granted. 🚨

**PLEASE READ THIS**:

In order for a PR to be merged, it must fail on GPT-4. We are aware that
right now, users do not have access, so you will not be able to tell if
the eval fails or not. Please run your eval with GPT-3.5-Turbo, but keep
in mind as we run the eval, if GPT-4 gets higher than 90% on the eval,
we will likely reject it since GPT-4 is already capable of completing
the task.

We plan to roll out a way for users submitting evals to see the eval
performance on GPT-4 soon. Stay tuned! Until then, you will not be able
to see the eval performance on GPT-4. **Starting April 10, the minimum
eval count is 15 samples, we hope this makes it easier to create and
contribute evals.**

Also, please note that we're using **Git LFS** for storing the JSON
files, so please make sure that you move the JSON file to Git LFS before
submitting a PR. Details on how to use Git LFS are available
[here](https://git-lfs.com).

## Eval details 📑

### Eval name

Alaready Said That

### Eval description

This eval measures how robust models are to distractors when performing
sequential tasks. We construct a toy task where the model needs to
determine whether it has already seen a given word, and inject
distractor questions into the interaction, keeping track of model
performance throughout.

### What makes this a useful eval?

[Insert why this eval is worth including and any additional context]

## Criteria for a good eval ✅

Below are some of the criteria we look for in a good eval. In general,
we are seeking cases where the model does not do a good job despite
being capable of generating a good response (note that there are some
things large language models cannot do, so those would not make good
evals).

Your eval should be:

- [x] Thematically consistent: The eval should be thematically
consistent. We'd like to see a number of prompts all demonstrating some
particular failure mode. For example, we can create an eval on cases
where the model fails to reason about the physical world.
- [x] Contains failures where a human can do the task, but either GPT-4
or GPT-3.5-Turbo could not.
- [x] Includes good signal around what is the right behavior. This means
either a correct answer for `Basic` evals or the `Fact` Model-graded
eval, or an exhaustive rubric for evaluating answers for the `Criteria`
Model-graded eval.
- [x] **Include at least 15 high-quality examples.**

If there is anything else that makes your eval worth including, please
document it below.

### Unique eval value

> Insert what makes your eval high quality that was not mentioned above.
(Not required)

## Eval structure 🏗️

Your eval should

- [x] Check that your data is in `evals/registry/data/{name}`
- [x] Check that your YAML is registered at
`evals/registry/evals/{name}.yaml`
- [x] Ensure you have the right to use the data you submit via this eval

(For now, we will only be approving evals that use one of the existing
eval classes. You may still write custom eval classes for your own
cases, and we may consider merging them in the future.)

## Final checklist 👀

### Submission agreement

By contributing to Evals, you are agreeing to make your evaluation logic
and data under the same MIT license as this repository. You must have
adequate rights to upload any data used in an Eval. OpenAI reserves the
right to use this data in future service improvements to our product.
Contributions to OpenAI Evals will be subject to our usual Usage
Policies (<https://platform.openai.com/docs/usage-policies>).

- [x] I agree that my submission will be made available under an MIT
license and complies with OpenAI's usage policies.

### Email address validation

If your submission is accepted, we will be granting GPT-4 access to a
limited number of contributors. Access will be given to the email
address associated with the commits on the merged pull request.

- [x] I acknowledge that GPT-4 access will only be granted, if
applicable, to the email address used for my merged pull request.

### Limited availability acknowledgment

We know that you might be excited to contribute to OpenAI's mission,
help improve our models, and gain access to GPT-4. However, due to the
requirements mentioned above and the high volume of submissions, we will
not be able to accept all submissions and thus not grant everyone who
opens a PR GPT-4 access. We know this is disappointing, but we hope to
set the right expectation before you open this PR.

- [x] I understand that opening a PR, even if it meets the requirements
above, does not guarantee the PR will be merged nor GPT-4 access be
granted.

### Submit eval

- [x] I have filled out all required fields of this form
- [x] I have used **Git LFS** for the Eval JSON data
- [x] (Ignore if not submitting code) I have run `pip install
pre-commit; pre-commit install` and have verified that `mypy`, `black`,
`isort`, `autoflake` and `ruff` are running when I commit and push

Failure to fill out all required fields will result in the PR being
closed.

### Eval JSON data

Since we are using Git LFS, we are asking eval submitters to add in as
many Eval Samples (at least 5) from their contribution here:

<details>
  <summary>View evals in JSON</summary>

  ### Eval
  ```jsonl
  INSERT_EVAL_HERE
  ```
</details>
  • Loading branch information
thesofakillers committed Mar 19, 2024
1 parent bd1736e commit baa12d0
Show file tree
Hide file tree
Showing 17 changed files with 1,569 additions and 3 deletions.
9 changes: 8 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,12 @@ NOTE: This license applies to all parts of this repository except for the datase
- **License**: Creative Commons Attribution 4.0 International: https://creativecommons.org/licenses/by/4.0/
- **Source**: https://allenai.org/data/socialiqa

#### Already Said That

Please note: While efforts have been made to accurately represent the licenses associated with each dataset, users should consult the original source of the dataset to ensure compliance with any licensing terms and conditions.
- **Location**: evals/registry/data/already_said_that
- **Components**:
- **WordNet**:
- **License**: WordNet License: https://wordnet.princeton.edu/license-and-commercial-use
- **Source**: https://wordnet.princeton.edu/

Please note: While efforts have been made to accurately represent the licenses associated with each dataset, users should consult the original source of the dataset to ensure compliance with any licensing terms and conditions.
185 changes: 185 additions & 0 deletions evals/elsuite/already_said_that/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Already Said That

This eval measures how robust models are to distractors when performing
sequential tasks. We construct a toy task where the model needs to determine
whether it has already seen a given word, and inject distractor questions into
the interaction, keeping track of model performance throughout.

## Usage

Run with:

```bash
oaieval <solver> already_said_that
```

We have found that `generation/direct/gpt-4-0125-preview` works well on this
eval. For more examples of tested solvers, see
[`./scripts/run_experiments.sh`](./scripts/run_experiments.sh).

## Dataset

The dataset consists of 500 samples, where each sample contains 100 unique words
randomly sampled from the [WordNet corpus](https://wordnet.princeton.edu/) via
the `nltk` library.

We also rely on four sets of distractor questions, sourced directly from the
datasets of pre-existing evals. Specifically we make use of the datasets of the
following evals from our evals registry:

- [`which-is-heavier`](../../registry/evals/which-is-heavier.yaml)
- [`first-letters`](../../registry/evals/first-letters.yaml)
- [`ambigous-sentences`](../../registry/evals/ambiguous-sentences.yaml)
- [`reverse-sort-words-eng`](../../registry/evals/reverse-sort-words-eng.yaml)

## Evaluation Process

The evaluation process is as follows for a given sample from our dataset:

1. The `TASK_DESCRIPTION` prompt is shown to the solver.
2. For 100 turns, we either show a word to the solver or a distractor question,
with probability 2/3 and 1/3 respectively.
3. If a word is shown, we prefix it with `MAIN TASK -`, to indicate that we are
asking the solver to perform the main task of determining whether it has seen
the word before.
4. When showing a word, we randomly show previously seen words with a
probability of 1/2 and new words with a probability of 1/2.
5. If we show a distractor question, we directly show the question to the
solver.
6. The solver should respond with its answer wrapped in the format
`[answer: <answer>]`.
7. The solver's response is parsed and compared to the correct answer.
8. If the solver's response is incorrect or a violation is raised (answered in
the incorrect format), in the case of the main task we stop the interaction
and record the number of turns the solver lasted for. Otherwise we continue
to the next turn.

## Prompts

We refer readers to [`./prompts.py`](./prompts.py) for the `TASK_DESCRIPTION`
used in the eval.

We refer readers to [`./distractors.py`](./distractors.py) for any cosmetic
changes we make to the distractor questions.

## Metrics

Below are the metrics returned by the eval:

<!-- prettier-ignore-start -->
| **Metric** | **Notes** |
|------------------------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `avg_num_turns` | The average number of turns shown before the model fails across the samples. Higher is better. Best possible is 100. |
| `stddev_num_turns` | The standard deviation on the above. |
| `median_num_turns` | The median number of turns shown before the model fails across the samples. Higher is better. Best possible is 100. |
| `max_num_turns` | The maximum number of turns shown before the model fails across the samples. |
| `min_num_turns` | The minimum number of turns shown before the model fails across the samples. |
| `false_positive_rate` | How often the model answers “yes” when it should have answered “no” (i.e. a new word is shown, and the model claims to have seen it already). |
| `false_negative_rate` | How often the model answers “no” when it should have answered “yes” (i.e. a word is shown again, and the model claims to not have seen it). |
| `avg_distractor_accuracy` | For a given sample interaction, we measure whether each model response to a given distractor question is accurate. We then compute the accuracy on the distractor questions shown over the interaction. We then average this accuracy across all samples. |
| `violation_rate` | how often the model responds in an invalid format, i.e. not using the `[answer: <answer>]` format. |
| `avg_num_distractors` | The average number of distractors shown before the model fails across the samples. Higher is better. Best possible is around 33. |
| `stddev_num_distractors` | The standard deviation on the above. |
| `median_num_distractors` | The median number of distractors shown before the model fails across the samples. Higher is better. Best possible is around 33. |
| `max_num_distractors` | The maximum number of distractors shown before the model fails across the samples. |
| `min_num_distractors` | The minimum number of distractors shown before the model fails across the samples. |
<!-- prettier-ignore-end -->

## Variants

We consider each of the four distractor datasets mentioned in
[Dataset](#dataset) as a variant of the eval.

```bash
oaieval <solver> already_said_that.<distractor>
```

We also have a `distractorless` variant where we only show words to the solver.
We use this as a baseline to determine how robust the solver is to distractors.

```bash
oaieval <solver> already_said_that.distractorless
```

## Custom Solvers

We implement 2 custom solvers for this eval in [./solvers.py](./solvers.py):

1. `RandomBaselineSolver`: A solver that randomly answers `yes` or `no` for any
input. We view this baseline as equivalent to randomly guessing.
2. `AlreadySaidThatHuman`: A helper solver class that wraps the `HumanCliSolver`
class such that users do not have to wrap their answer in the
`[answer: <answer>]` format and can instead just directly type the answer.

## Token Usage Estimates

Below are approximate token usage estimates for a given run (one run = all
samples) of the eval, for each of the distractor variants.

For Direct gpt-4-0125-preview:

| Distractor variant | Input | Output | Total |
| --------------------- | ---------- | ------- | ---------- |
| which-is-heavier | 17,960,000 | 80,000 | 18,040,000 |
| ambiguous-sentences | 27,750,000 | 110,000 | 27,860,000 |
| first-letters | 19,850,000 | 80,000 | 19,940,000 |
| reverse-sort-words-en | 10,700,000 | 120,000 | 10,820,000 |
| distractorless | 27,550,000 | 120,000 | 27,680,000 |

For Direct gpt-3.5-turbo-0125:

| Distractor variant | Input | Output | Total |
| --------------------- | --------- | ------ | --------- |
| which-is-heavier | 1,200,000 | 10,000 | 1,210,000 |
| ambiguous-sentences | 1,540,000 | 20,000 | 1,550,000 |
| first-letters | 2,120,000 | 20,000 | 2,140,000 |
| reverse-sort-words-en | 910,000 | 20,000 | 940,000 |
| distractorless | 1,250,000 | 20,000 | 1,270,000 |

For Direct gpt-4-base:

| Distractor variant | Input | Output | Total |
| --------------------- | ---------- | --------- | ---------- |
| which-is-heavier | 16,950,000 | 3,670,000 | 20,620,000 |
| ambiguous-sentences | 23,100,000 | 4,390,000 | 27,490,000 |
| first-letters | 25,310,000 | 4,870,000 | 30,180,000 |
| reverse-sort-words-en | 14,380,000 | 2,760,000 | 17,140,000 |
| distractorless | 24,460,000 | 5,000,000 | 29,460,000 |

For CoT gpt-4-0125-preview:

| Distractor variant | Input | Output | Total |
| --------------------- | ----------- | --------- | ----------- |
| which-is-heavier | 263,600,000 | 1,900,000 | 265,500,000 |
| ambiguous-sentences | 383,500,000 | 2,700,000 | 386,200,000 |
| first-letters | 251,700,000 | 1,700,000 | 253,400,000 |
| reverse-sort-words-en | 236,700,000 | 2,100,000 | 238,800,000 |
| distractorless | 395,500,000 | 2,400,000 | 398,000,000 |

For CoT gpt-3.5-turbo-0125:

| Distractor variant | Input | Output | Total |
| --------------------- | ---------- | ------- | ---------- |
| which-is-heavier | 10,100,000 | 190,000 | 10,280,000 |
| ambiguous-sentences | 7,510,000 | 140,000 | 7,650,000 |
| first-letters | 16,450,000 | 220,000 | 16,670,000 |
| reverse-sort-words-en | 4,690,000 | 150,000 | 4,840,000 |
| distractorless | 30,230,000 | 310,000 | 30,540,000 |

## Future modifications

- Extending the range of distractors considered, either by incorporating more
evals or designing new distractor variants.
- Experiment with multiple distractor sources in a single eval run, to see if
the variety of distractors affects the model's robustness.

## Version History

- v0: Initial version released

## Contribution Statement

Eval design, implementation, and results evaluation were primarily conducted by
Giulio Starace, under the guidance of (alphabetically by last-name) Steven
Adler, Andrei Alexandru, James Aung, and Chan Jun Shern who provided research
input, report revisions, and project management support.
133 changes: 133 additions & 0 deletions evals/elsuite/already_said_that/distractors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import os
from dataclasses import dataclass
from pathlib import Path

import evals


@dataclass
class DistractorSample:
question: str
ideal: str


VARIANTS = {
"which-is-heavier",
"ambiguous-sentences",
"first-letters",
"reverse-sort-words-eng",
"distractorless",
}


def proc_which_is_heavier(samples) -> list[DistractorSample]:
distractor_samples = []
for sample in samples:
# get rid of ' Answer Yes or No'
question = sample["input"][1]["content"][:-17]
ideal = sample["ideal"].lower()
distractor_samples.append(DistractorSample(question, ideal))
return distractor_samples


def proc_distractors_first_letters(samples) -> list[DistractorSample]:
distractor_samples = []
for sample in samples:
question = sample["input"][1]["content"]
ideal = sample["ideal"].lower()
distractor_samples.append(DistractorSample(question, ideal))
return distractor_samples


def proc_distractors_ambiguous_sentences(samples) -> list[DistractorSample]:
distractor_samples = []
for sample in samples:
sample_content = sample["input"][1]["content"]
question = f"{sample_content}"
ideal = sample["ideal"].lower()
distractor_samples.append(DistractorSample(question, ideal))
return distractor_samples


def proc_distractors_reverse_sort_words_eng(samples) -> list[DistractorSample]:
distractor_samples = []
for sample in samples:
# cut " (respond as concisely as possible and only include the comma-separated words in your response):"
instruction = sample["input"][0]["content"][:-96]
sample_content = sample["input"][1]["content"]
question = f"{instruction}: {sample_content}"
ideal = sample["ideal"].lower()
distractor_samples.append(DistractorSample(question, ideal))
return distractor_samples


variant_to_processor = {
"which-is-heavier": proc_which_is_heavier,
"first-letters": proc_distractors_first_letters,
"ambiguous-sentences": proc_distractors_ambiguous_sentences,
"reverse-sort-words-eng": proc_distractors_reverse_sort_words_eng,
}


def get_basic_distractor_example() -> DistractorSample:
"""
An arbitrary distractor example used in the task description for the
distractorless variant
"""
return DistractorSample(question="What is the capital of Italy?", ideal="rome")


def get_distractors(variant: str) -> list[DistractorSample]:
"""
Gets and optionally processes the corpus of distractor questions for variant
"""
assert variant in VARIANTS, f"Invalid variant {variant}, expected one of {VARIANTS}"
if variant == "distractorless":
# single element will be pop()ed for the task description, leaving an empty list
return [get_basic_distractor_example()]

samples = get_samples(variant)

process_variant_fn = variant_to_processor[variant]
processed_samples = process_variant_fn(samples)

return processed_samples


def get_samples(eval_name) -> list[dict]:
"""
Gets the samples from the samples_jsonl associated with
a given eval.
Adapted from evals.eval.Eval.get_samples
"""
registry = evals.registry.Registry()
eval_spec = registry.get_eval(eval_name)
samples_path = eval_spec.args["samples_jsonl"]
registry_path = eval_spec.registry_path
samples_full_path = get_full_path(samples_path, registry_path)
return evals.data.get_jsonl(samples_full_path.as_posix())


def get_full_path(data_path, registry_path) -> Path:
if os.path.isfile(data_path):
return Path(data_path)

return registry_path / "data" / data_path


def get_distractor_word(question: str) -> str:
"""
Takes the last word of the question (stripped of punctuation and lower-cased)
To be shown in the task description example
"""
words = question.split()
last_word = words[-1]
last_word = last_word.strip(".,!?")
return last_word.lower()


if __name__ == "__main__":
# just for testing
distractors = get_distractors("rectangles")
print(distractors[0])
Loading

0 comments on commit baa12d0

Please sign in to comment.