-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,413 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
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,123 @@ | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
|
||
from data_juicer.format import load_formatter | ||
|
||
if st.__version__ >= '1.23.0': | ||
data_editor = st.data_editor | ||
else: | ||
data_editor = st.data_editor.experimental_data_editor | ||
|
||
|
||
@st.cache_data | ||
def convert_csv(df): | ||
# IMPORTANT: Cache the conversion to prevent computation on every rerun | ||
return df.to_csv(encoding='utf_8_sig').encode('utf-8') | ||
|
||
|
||
@st.cache_data | ||
def convert_jsonl(df): | ||
# IMPORTANT: Cache the conversion to prevent computation on every rerun | ||
return df.to_json(orient='records', lines=True, | ||
force_ascii=False).encode('utf-8') | ||
|
||
|
||
class Visualize: | ||
|
||
@staticmethod | ||
def setup(): | ||
st.set_page_config( | ||
page_title='Data-Juicer', | ||
page_icon=':smile', | ||
layout='wide', | ||
# initial_sidebar_state="expanded", | ||
) | ||
|
||
readme_link = 'https://github.com/alibaba/data-juicer' | ||
st.markdown( | ||
'<div align = "center"> <font size = "70"> Data-Juicer \ | ||
</font> </div>', | ||
unsafe_allow_html=True, | ||
) | ||
st.markdown( | ||
f'<div align = "center"> A Data-Centric Text Processing System for \ | ||
Large Language Models, \ | ||
see more details in our <a href={readme_link}>page</a></div>', | ||
unsafe_allow_html=True, | ||
) | ||
|
||
@staticmethod | ||
def mix_dataset(): | ||
|
||
data_files = list(Path('./data').glob('*jsonl')) | ||
|
||
data_files_dict = {file.stem: str(file) for file in data_files} | ||
col1, col2 = st.columns(2) | ||
all_selected = [] | ||
with col1: | ||
col3, col4 = st.columns(2) | ||
with col3: | ||
st.subheader('Select datasets') | ||
options = sorted(list(data_files_dict.keys())) | ||
selected_ds = st.multiselect(label='datasets', | ||
options=options, | ||
label_visibility='hidden') | ||
for ds in selected_ds: | ||
all_selected.append({'dataset': ds, 'weight': 1.0}) | ||
with col4: | ||
st.subheader('Select sampling method') | ||
options = ['Random'] | ||
st.selectbox(label='method', | ||
options=options, | ||
label_visibility='hidden') | ||
|
||
st.subheader('Set weight (0.0-1.0)') | ||
datasets = data_editor(all_selected, use_container_width=True) | ||
ds_names = [ds['dataset'] for ds in datasets] | ||
ds_files = [data_files_dict[ds['dataset']] for ds in datasets] | ||
weights = [ds['weight'] for ds in datasets] | ||
with col2: | ||
st.subheader('Show selected dataset details') | ||
display_select = st.checkbox('Display') | ||
if display_select: | ||
if len(datasets) > 0: | ||
tabs = st.tabs(ds_names) | ||
for tab, ds_file in zip(tabs, ds_files): | ||
with tab: | ||
st.write(pd.read_json(ds_file, lines=True)) | ||
|
||
start_btn = st.button('Start to mix datasets', use_container_width=True) | ||
if start_btn: | ||
if len(datasets) > 0: | ||
data_path = ' '.join([ | ||
' '.join([str(weight), ds_file]) | ||
for ds_file, weight in zip(ds_files, weights) | ||
]) | ||
formatter = load_formatter(data_path) | ||
df = pd.DataFrame(formatter.load_dataset()) | ||
|
||
st.session_state.dataset = df | ||
else: | ||
st.warning('Please select one dataset at least') | ||
|
||
dataset = st.session_state.get('dataset', pd.DataFrame()) | ||
st.subheader('Mixed dataset') | ||
st.dataframe(dataset, use_container_width=True) | ||
st.download_button(label='Download mixed dataset as JSONL', | ||
data=convert_jsonl(dataset), | ||
file_name='mixed_dataset.jsonl') | ||
|
||
@staticmethod | ||
def visualize(): | ||
Visualize.setup() | ||
Visualize.mix_dataset() | ||
|
||
|
||
def main(): | ||
Visualize.visualize() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.