expectedparrot / edsl

Design, conduct and analyze results of AI-powered surveys and experiments. Simulate social science and market research with large numbers of AI agents and LLMs.
https://docs.expectedparrot.com
MIT License
167 stars 18 forks source link

Results object should have a shuffle method & random sample method #437

Closed rbyh closed 3 months ago

johnjosephhorton commented 4 months ago

All models w/o None were runnable

>>> results.select('text', 'answer.*', 'model.model').print(format = "rich")
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ scenario      ┃ answer   ┃ model                                          ┃
┃ .text         ┃ .testing ┃ .model                                         ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ I feel happy! │ Positive │ mistralai/Mistral-7B-Instruct-v0.2             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo-0301                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ mistralai/Mixtral-8x7B-Instruct-v0.1           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ mistralai/Mistral-7B-Instruct-v0.2             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ mistralai/Mistral-7B-Instruct-v0.1             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ mistralai/Mistral-7B-Instruct-v0.1             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo-0301                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo-0125                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo-0125                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo-0613                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ mistralai/Mixtral-8x7B-Instruct-v0.1           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo                                  │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo                                  │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo-1106                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ claude-3-haiku-20240307                        │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ meta-llama/Meta-Llama-3-70B-Instruct           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo-16k                              │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo-16k                              │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ meta-llama/Meta-Llama-3-70B-Instruct           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-3.5-turbo-16k-0613                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ claude-3-haiku-20240307                        │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo-0613                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo-1106                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-3.5-turbo-16k-0613                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-turbo-preview                            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ bigcode/starcoder2-15b                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ codellama/CodeLlama-34b-Instruct-hf            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ bigcode/starcoder2-15b                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ codellama/CodeLlama-70b-Instruct-hf            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ codellama/CodeLlama-70b-Instruct-hf            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ codellama/CodeLlama-34b-Instruct-hf            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ Phind/Phind-CodeLlama-34B-v2                   │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ Phind/Phind-CodeLlama-34B-v2                   │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gemini-pro                                     │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-1106-vision-preview                      │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4                                          │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-1106-preview                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-vision-preview                           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gemini-pro                                     │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ claude-3-sonnet-20240229                       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-vision-preview                           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-0125-preview                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-turbo-preview                            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-1106-preview                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ claude-3-sonnet-20240229                       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-0125-preview                             │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4                                          │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-turbo                                    │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-0613                                     │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-turbo-2024-04-09                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-0613                                     │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ gpt-4-turbo                                    │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-turbo-2024-04-09                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ gpt-4-1106-vision-preview                      │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ google/gemma-1.1-7b-it                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Neutral  │ deepinfra/airoboros-70b                        │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ meta-llama/Llama-2-70b-chat-hf                 │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ meta-llama/Llama-2-70b-chat-hf                 │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ meta-llama/Llama-2-7b-chat-hf                  │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ Gryphe/MythoMax-L2-13b                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Negative │ mistralai/Mixtral-8x22B-v0.1                   │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ microsoft/WizardLM-2-8x22B                     │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ mistralai/Mixtral-8x22B-Instruct-v0.1          │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ microsoft/WizardLM-2-7B                        │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ mistralai/Mixtral-8x22B-v0.1                   │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ claude-3-opus-20240229                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ microsoft/WizardLM-2-8x22B                     │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ claude-3-opus-20240229                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ meta-llama/Llama-2-13b-chat-hf                 │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Positive │ Gryphe/MythoMax-L2-13b-turbo                   │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ google/gemma-1.1-7b-it                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ cognitivecomputations/dolphin-2.6-mixtral-8x7b │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ Austism/chronos-hermes-13b-v2                  │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ meta-llama/Meta-Llama-3-8B-Instruct            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ 01-ai/Yi-34B-Chat                              │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ databricks/dbrx-instruct                       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ databricks/dbrx-instruct                       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ Negative │ cognitivecomputations/dolphin-2.6-mixtral-8x7b │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ gpt-3.5-turbo-instruct                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ gpt-3.5-turbo-instruct-0914                    │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ gpt-3.5-turbo-instruct                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ gpt-3.5-turbo-instruct-0914                    │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Positive │ meta-llama/Meta-Llama-3-8B-Instruct            │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ google/codegemma-7b-it                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ google/codegemma-7b-it                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ Negative │ Austism/chronos-hermes-13b-v2                  │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ 01-ai/Yi-34B-Chat                              │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ openchat/openchat_3.5                          │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ mistralai/Mixtral-8x22B-Instruct-v0.1          │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ Gryphe/MythoMax-L2-13b                         │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ bigcode/starcoder2-15b-instruct-v0.1           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ bigcode/starcoder2-15b-instruct-v0.1           │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ microsoft/WizardLM-2-7B                        │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ meta-llama/Llama-2-7b-chat-hf                  │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ llava-hf/llava-1.5-7b-hf                       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ Gryphe/MythoMax-L2-13b-turbo                   │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ meta-llama/Llama-2-13b-chat-hf                 │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ lizpreciatior/lzlv_70b_fp16_hf                 │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ llava-hf/llava-1.5-7b-hf                       │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ lizpreciatior/lzlv_70b_fp16_hf                 │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel sad.   │ None     │ deepinfra/airoboros-70b                        │
├───────────────┼──────────┼────────────────────────────────────────────────┤
│ I feel happy! │ None     │ openchat/openchat_3.5                          │
└───────────────┴──────────┴────────────────────────────────────────────────┘
>>> 
rbyh commented 4 months ago

Unexpected behavior for results.shuffle():

image
rbyh commented 4 months ago

Unexpected behavior for results.sample(n):

image
rbyh commented 4 months ago

Shuffle method changes results unexpectedly:

image
rbyh commented 4 months ago
results.shuffle()

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File [~/edsl/.venv/lib/python3.11/site-packages/IPython/core/formatters.py:344](http://localhost:8888/lab/tree/~/edsl/.venv/lib/python3.11/site-packages/IPython/core/formatters.py#line=343), in BaseFormatter.__call__(self, obj)
    342     method = get_real_method(obj, self.print_method)
    343     if method is not None:
--> 344         return method()
    345     return None
    346 else:

File [~/edsl/edsl/results/Dataset.py:44](http://localhost:8888/lab/tree/~/edsl/edsl/results/Dataset.py#line=43), in Dataset._repr_html_(self)
     41 """Return an HTML representation of the dataset."""
     42 from edsl.utilities.utilities import data_to_html
---> 44 return data_to_html(self.data)

File [~/edsl/edsl/utilities/utilities.py:23](http://localhost:8888/lab/tree/~/edsl/edsl/utilities/utilities.py#line=22), in data_to_html(data, replace_new_lines)
     22 def data_to_html(data, replace_new_lines=False):
---> 23     json_str = json.dumps(data, indent=4)
     24     formatted_json = highlight(
     25         json_str,
     26         JsonLexer(),
     27         HtmlFormatter(style="default", full=False, noclasses=False),
     28     )
     29     if replace_new_lines:

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/__init__.py:238](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/__init__.py#line=237), in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    232 if cls is None:
    233     cls = JSONEncoder
    234 return cls(
    235     skipkeys=skipkeys, ensure_ascii=ensure_ascii,
    236     check_circular=check_circular, allow_nan=allow_nan, indent=indent,
    237     separators=separators, default=default, sort_keys=sort_keys,
--> 238     **kw).encode(obj)

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:202](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=201), in JSONEncoder.encode(self, o)
    200 chunks = self.iterencode(o, _one_shot=True)
    201 if not isinstance(chunks, (list, tuple)):
--> 202     chunks = list(chunks)
    203 return ''.join(chunks)

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:430](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=429), in _make_iterencode.<locals>._iterencode(o, _current_indent_level)
    428     yield _floatstr(o)
    429 elif isinstance(o, (list, tuple)):
--> 430     yield from _iterencode_list(o, _current_indent_level)
    431 elif isinstance(o, dict):
    432     yield from _iterencode_dict(o, _current_indent_level)

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:326](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=325), in _make_iterencode.<locals>._iterencode_list(lst, _current_indent_level)
    324         else:
    325             chunks = _iterencode(value, _current_indent_level)
--> 326         yield from chunks
    327 if newline_indent is not None:
    328     _current_indent_level -= 1

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:406](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=405), in _make_iterencode.<locals>._iterencode_dict(dct, _current_indent_level)
    404         else:
    405             chunks = _iterencode(value, _current_indent_level)
--> 406         yield from chunks
    407 if newline_indent is not None:
    408     _current_indent_level -= 1

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:326](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=325), in _make_iterencode.<locals>._iterencode_list(lst, _current_indent_level)
    324         else:
    325             chunks = _iterencode(value, _current_indent_level)
--> 326         yield from chunks
    327 if newline_indent is not None:
    328     _current_indent_level -= 1

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:439](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=438), in _make_iterencode.<locals>._iterencode(o, _current_indent_level)
    437         raise ValueError("Circular reference detected")
    438     markers[markerid] = o
--> 439 o = _default(o)
    440 yield from _iterencode(o, _current_indent_level)
    441 if markers is not None:

File [~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:180](http://localhost:8888/lab/tree/~/.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py#line=179), in JSONEncoder.default(self, o)
    161 def default(self, o):
    162     """Implement this method in a subclass such that it returns
    163     a serializable object for ``o``, or calls the base implementation
    164     (to raise a ``TypeError``).
   (...)
    178 
    179     """
--> 180     raise TypeError(f'Object of type {o.__class__.__name__} '
    181                     f'is not JSON serializable')

TypeError: Object of type Prompt is not JSON serializable
johnjosephhorton commented 3 months ago

Latest commits should fix this.