-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from future-xy/add-datasets
feat: generate prompts from datasets
- Loading branch information
Showing
16 changed files
with
499 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"sort_strategy": "random", | ||
"dataset_1": { | ||
"file_name": "", | ||
"prompt_field": "", | ||
"select_ratio": 1, | ||
"split": "train" | ||
}, | ||
"dataset_2": { | ||
"file_name": "", | ||
"prompt_field": "", | ||
"select_ratio": 1 | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"sort_strategy": "original", | ||
"dataset_1": { | ||
"file_name": "hf://datasets/fka/awesome-chatgpt-prompts/prompts.csv", | ||
"prompt_field": "prompt", | ||
"select_ratio": 2, | ||
"split": "train" | ||
}, | ||
"dataset_2": { | ||
"file_name": "MAsad789565/Coding_GPT4_Data", | ||
"prompt_field": "user", | ||
"select_ratio": 8, | ||
"split": "train" | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"sort_strategy": "random", | ||
"dataset_1": { | ||
"file_name": "Conversational_dataset.jsonl", | ||
"prompt_field": "messages", | ||
"select_ratio": 6 | ||
}, | ||
"dataset_2": { | ||
"file_name": "~/.cache/tracestorm/GPT4_coding_sample.csv", | ||
"prompt_field": "user", | ||
"select_ratio": 4 | ||
} | ||
} |
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 @@ | ||
import os | ||
|
||
import pandas as pd | ||
|
||
from tracestorm.constants import DEFAULT_DATASET_FOLDER | ||
|
||
|
||
def prepare_test_datasets(): | ||
df1 = pd.read_json( | ||
"hf://datasets/MAsad789565/Coding_GPT4_Data/Data/GPT_4_Coding.json" | ||
) | ||
df2 = pd.read_json( | ||
"hf://datasets/olathepavilion/Conversational-datasets-json/Validation.jsonl", | ||
lines=True, | ||
) | ||
|
||
# save the pre-processed dataset to the default folder for test | ||
os.makedirs(DEFAULT_DATASET_FOLDER, exist_ok=True) | ||
path1 = os.path.join(DEFAULT_DATASET_FOLDER, "GPT4_coding_sample.csv") | ||
path2 = os.path.join(DEFAULT_DATASET_FOLDER, "Conversational_dataset.jsonl") | ||
|
||
# test with different file formats | ||
df1.to_csv(path1, index=False) | ||
df2.to_json(path2, orient="records", lines=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
prepare_test_datasets() |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
click>=8.1.8 | ||
datasets>=3.3.2 | ||
matplotlib>=3.9 | ||
numpy>=1.26.4 | ||
openai>=1.58.0 | ||
pandas>=2.2.3 | ||
requests>=2.31.0 | ||
seaborn>=0.13.2 |
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,63 @@ | ||
import os | ||
import unittest | ||
|
||
import pandas as pd | ||
|
||
from tracestorm.constants import DEFAULT_DATASET_FOLDER | ||
from tracestorm.data_loader import Dataset, load_datasets | ||
|
||
|
||
class TestDataLoader(unittest.TestCase): | ||
def test_remote_files(self): | ||
""" | ||
Test loading datasets from hugging face. | ||
There are 2 datasets, testing for: | ||
1. loading with datasets.load_dataset | ||
2. loading csv format with pandas | ||
""" | ||
datasets, sort = load_datasets("examples/datasets_config_hf.json") | ||
assert isinstance(datasets, list) | ||
assert isinstance(datasets[0], Dataset) and isinstance( | ||
datasets[1], Dataset | ||
) | ||
assert sort == "original" | ||
assert len(datasets) == 2 | ||
assert datasets[0].select_ratio == 2 and datasets[1].select_ratio == 8 | ||
assert datasets[0].length > 0 and datasets[1].length > 0 | ||
|
||
def test_local_files(self): | ||
"""Test loading from local files""" | ||
|
||
os.makedirs(DEFAULT_DATASET_FOLDER, exist_ok=True) | ||
# testing datasets | ||
df1 = pd.read_json( | ||
"hf://datasets/MAsad789565/Coding_GPT4_Data/Data/GPT_4_Coding.json" | ||
) | ||
df2 = pd.read_json( | ||
"hf://datasets/olathepavilion/Conversational-datasets-json/Validation.jsonl", | ||
lines=True, | ||
) | ||
|
||
# test with different file formats | ||
path1 = os.path.join(DEFAULT_DATASET_FOLDER, "GPT4_coding_sample.csv") | ||
path2 = os.path.join( | ||
DEFAULT_DATASET_FOLDER, "Conversational_dataset.jsonl" | ||
) | ||
|
||
# save the pre-processed dataset to the default folder for test | ||
df1.to_csv(path1, index=False) | ||
df2.to_json(path2, orient="records", lines=True) | ||
|
||
datasets, sort = load_datasets("examples/datasets_config_local.json") | ||
assert isinstance(datasets, list) | ||
assert isinstance(datasets[0], Dataset) and isinstance( | ||
datasets[1], Dataset | ||
) | ||
assert sort == "random" | ||
assert len(datasets) == 2 | ||
assert datasets[0].select_ratio == 6 and datasets[1].select_ratio == 4 | ||
assert datasets[0].length > 0 and datasets[1].length > 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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.