-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add datasets: - lmsys - openorca - oasst2 Other: - Reduce spacy spam - Add OpenAI JSON format as a dataset format so we can cluster role=human lmsys.
- Loading branch information
Showing
11 changed files
with
201 additions
and
40 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
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,58 @@ | ||
"""ShareGPT format.""" | ||
|
||
from typing import ClassVar | ||
|
||
from ..dataset_format import DatasetFormat, DatasetFormatInputSelector | ||
from ..schema import PATH_WILDCARD, VALUE_KEY, Item, PathTuple, Schema, schema | ||
|
||
|
||
def _openai_selector(item: Item, conv_role: str) -> str: | ||
"""Selector for OpenAI JSON Formatted conversations.""" | ||
# TODO(nsthorat): Make this return an array, and not pre-join with newlines. | ||
values = [conv['content'] for conv in item['conversation'] if conv['role'] == conv_role] | ||
# Get the __value__ key version of text if it's enriched. | ||
values = [value if isinstance(value, str) else value.get(VALUE_KEY) for value in values] | ||
return '\n'.join(values) | ||
|
||
|
||
_USER_SELECTOR = DatasetFormatInputSelector( | ||
name='user', | ||
selector=lambda item: _openai_selector(item, 'user'), | ||
) | ||
|
||
_ASSISTANT_SELECTOR = DatasetFormatInputSelector( | ||
name='assistant', | ||
selector=lambda item: _openai_selector(item, 'assistant'), | ||
) | ||
|
||
|
||
class OpenAIJSON(DatasetFormat): | ||
"""OpenAI JSON format. | ||
Taken from: https://platform.openai.com/docs/api-reference/chat | ||
Note that here "messages" is "conversation" for support with common datasets. | ||
""" | ||
|
||
name: ClassVar[str] = 'openai_json' | ||
data_schema: Schema = schema( | ||
{ | ||
'conversation': [ | ||
{ | ||
'role': 'string', | ||
'content': 'string', | ||
} | ||
], | ||
}, | ||
) | ||
|
||
title_slots: list[tuple[PathTuple, PathTuple]] = [ | ||
(('conversation', PATH_WILDCARD, 'content'), ('conversation', PATH_WILDCARD, 'role')) | ||
] | ||
|
||
user: ClassVar[DatasetFormatInputSelector] = _USER_SELECTOR | ||
assistant: ClassVar[DatasetFormatInputSelector] = _ASSISTANT_SELECTOR | ||
|
||
input_selectors: ClassVar[dict[str, DatasetFormatInputSelector]] = { | ||
selector.name: selector for selector in [_USER_SELECTOR, _ASSISTANT_SELECTOR] | ||
} |
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,28 @@ | ||
"""Tests for the openai_json format.""" | ||
|
||
|
||
from ..data.dataset_test_utils import TestDataMaker | ||
from .openai_json import OpenAIJSON | ||
|
||
|
||
def test_infer_open_chat(make_test_data: TestDataMaker) -> None: | ||
dataset = make_test_data( | ||
[ | ||
{ | ||
'conversation': [ | ||
{'role': 'user', 'content': 'Hello'}, | ||
{'role': 'assistant', 'content': 'Hi'}, | ||
{'role': 'user', 'content': 'How are you today?'}, | ||
{'role': 'assistant', 'content': "I'm fine."}, | ||
], | ||
}, | ||
{ | ||
'conversation': [ | ||
{'role': 'user', 'content': 'Who are you?'}, | ||
{'role': 'assistant', 'content': "I'm OpenChat."}, | ||
], | ||
}, | ||
] | ||
) | ||
|
||
assert dataset.manifest().dataset_format == OpenAIJSON() |
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
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
Oops, something went wrong.