Spaces:
Running
Running
yacine
commited on
Commit
•
160959f
1
Parent(s):
cca065e
local_datasets_and_Aggregate_tags
Browse files- README.md +4 -0
- tagging_app.py +42 -17
README.md
CHANGED
@@ -4,3 +4,7 @@ A Streamlit app to add structured tags to the datasets
|
|
4 |
```
|
5 |
streamlit run tagging_app.py
|
6 |
```
|
|
|
|
|
|
|
|
|
|
4 |
```
|
5 |
streamlit run tagging_app.py
|
6 |
```
|
7 |
+
|
8 |
+
The app initialization on the first run takes about 5 minutes, subsequent ones take about one minute.
|
9 |
+
|
10 |
+
Make sure to hit the `Done? Save to File!` button in the right column when you're done tagging a config!
|
tagging_app.py
CHANGED
@@ -9,7 +9,7 @@ from dataclasses import asdict
|
|
9 |
from glob import glob
|
10 |
from os.path import join as pjoin
|
11 |
|
12 |
-
st.
|
13 |
page_title="HF Dataset Tagging App",
|
14 |
page_icon="https://huggingface.co/front/assets/huggingface_logo.svg",
|
15 |
layout="wide",
|
@@ -18,8 +18,8 @@ st.beta_set_page_config(
|
|
18 |
|
19 |
task_set = json.load(open("task_set.json"))
|
20 |
license_set = json.load(open("license_set.json"))
|
21 |
-
|
22 |
-
|
23 |
|
24 |
multilinguality_set = {
|
25 |
"monolingual": "contains a single language",
|
@@ -46,15 +46,12 @@ creator_set = {
|
|
46 |
],
|
47 |
}
|
48 |
|
49 |
-
|
50 |
-
|
51 |
########################
|
52 |
## Helper functions
|
53 |
########################
|
54 |
|
55 |
@st.cache
|
56 |
def filter_features(feature_dict):
|
57 |
-
print(feature_dict)
|
58 |
if feature_dict.get("_type", None) == 'Value':
|
59 |
return {
|
60 |
"feature_type": feature_dict["_type"],
|
@@ -96,9 +93,10 @@ def find_languages(feature_dict):
|
|
96 |
else:
|
97 |
return []
|
98 |
|
|
|
|
|
99 |
@st.cache
|
100 |
def get_info_dicts(dataset_id):
|
101 |
-
keep_keys = ['description', 'features', 'homepage', 'license', 'splits']
|
102 |
module_path = datasets.load.prepare_module(dataset_id, dataset=True)
|
103 |
builder_cls = datasets.load.import_main_class(module_path[0], dataset=True)
|
104 |
build_confs = builder_cls.BUILDER_CONFIGS
|
@@ -112,9 +110,7 @@ def get_info_dicts(dataset_id):
|
|
112 |
|
113 |
@st.cache
|
114 |
def get_dataset_list():
|
115 |
-
|
116 |
-
all_dataset_ids = ["other"] + dataset_list
|
117 |
-
return all_dataset_ids
|
118 |
|
119 |
@st.cache()
|
120 |
def load_all_dataset_infos(dataset_list):
|
@@ -159,7 +155,7 @@ The tag sets are saved in JSON format, but you can print a YAML version in the r
|
|
159 |
|
160 |
all_dataset_ids = copy.deepcopy(get_dataset_list())
|
161 |
existing_tag_sets = load_existing_tags()
|
162 |
-
all_dataset_infos = load_all_dataset_infos(all_dataset_ids
|
163 |
|
164 |
st.sidebar.markdown(app_desc)
|
165 |
|
@@ -167,10 +163,10 @@ st.sidebar.markdown(app_desc)
|
|
167 |
only_missing = st.sidebar.checkbox("Show only un-annotated configs")
|
168 |
|
169 |
if only_missing:
|
170 |
-
dataset_choose_list = [did for did, c_dict in all_dataset_infos.items()
|
171 |
if not all([cid in existing_tag_sets.get(did, {}) for cid in c_dict])]
|
172 |
else:
|
173 |
-
dataset_choose_list = list(all_dataset_infos.keys())
|
174 |
|
175 |
dataset_id = st.sidebar.selectbox(
|
176 |
label="Choose dataset to tag",
|
@@ -178,7 +174,21 @@ dataset_id = st.sidebar.selectbox(
|
|
178 |
index=0,
|
179 |
)
|
180 |
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
if only_missing:
|
184 |
config_choose_list = [cid for cid in all_info_dicts
|
@@ -412,11 +422,26 @@ if c3.button("Done? Save to File!"):
|
|
412 |
_ = os.mkdir(pjoin('saved_tags', dataset_id, config_id))
|
413 |
json.dump(res, open(pjoin('saved_tags', dataset_id, config_id, 'tags.json'), 'w'))
|
414 |
|
415 |
-
with c3.beta_expander("Show JSON output"):
|
416 |
st.write(res)
|
417 |
|
418 |
-
with c3.beta_expander("Show YAML output"):
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
c3.markdown("--- ")
|
422 |
|
|
|
9 |
from glob import glob
|
10 |
from os.path import join as pjoin
|
11 |
|
12 |
+
st.set_page_config(
|
13 |
page_title="HF Dataset Tagging App",
|
14 |
page_icon="https://huggingface.co/front/assets/huggingface_logo.svg",
|
15 |
layout="wide",
|
|
|
18 |
|
19 |
task_set = json.load(open("task_set.json"))
|
20 |
license_set = json.load(open("license_set.json"))
|
21 |
+
language_set_restricted = json.load(open("language_set.json"))
|
22 |
+
language_set = json.load(open("language_set_full.json"))
|
23 |
|
24 |
multilinguality_set = {
|
25 |
"monolingual": "contains a single language",
|
|
|
46 |
],
|
47 |
}
|
48 |
|
|
|
|
|
49 |
########################
|
50 |
## Helper functions
|
51 |
########################
|
52 |
|
53 |
@st.cache
|
54 |
def filter_features(feature_dict):
|
|
|
55 |
if feature_dict.get("_type", None) == 'Value':
|
56 |
return {
|
57 |
"feature_type": feature_dict["_type"],
|
|
|
93 |
else:
|
94 |
return []
|
95 |
|
96 |
+
keep_keys = ['description', 'features', 'homepage', 'license', 'splits']
|
97 |
+
|
98 |
@st.cache
|
99 |
def get_info_dicts(dataset_id):
|
|
|
100 |
module_path = datasets.load.prepare_module(dataset_id, dataset=True)
|
101 |
builder_cls = datasets.load.import_main_class(module_path[0], dataset=True)
|
102 |
build_confs = builder_cls.BUILDER_CONFIGS
|
|
|
110 |
|
111 |
@st.cache
|
112 |
def get_dataset_list():
|
113 |
+
return datasets.list_datasets()
|
|
|
|
|
114 |
|
115 |
@st.cache()
|
116 |
def load_all_dataset_infos(dataset_list):
|
|
|
155 |
|
156 |
all_dataset_ids = copy.deepcopy(get_dataset_list())
|
157 |
existing_tag_sets = load_existing_tags()
|
158 |
+
all_dataset_infos = load_all_dataset_infos(all_dataset_ids)
|
159 |
|
160 |
st.sidebar.markdown(app_desc)
|
161 |
|
|
|
163 |
only_missing = st.sidebar.checkbox("Show only un-annotated configs")
|
164 |
|
165 |
if only_missing:
|
166 |
+
dataset_choose_list = ["local dataset"] + [did for did, c_dict in all_dataset_infos.items()
|
167 |
if not all([cid in existing_tag_sets.get(did, {}) for cid in c_dict])]
|
168 |
else:
|
169 |
+
dataset_choose_list = ["local dataset"] + list(all_dataset_infos.keys())
|
170 |
|
171 |
dataset_id = st.sidebar.selectbox(
|
172 |
label="Choose dataset to tag",
|
|
|
174 |
index=0,
|
175 |
)
|
176 |
|
177 |
+
if dataset_id == "local dataset":
|
178 |
+
path_to_info = st.sidebar.text_input("Please enter the path to the folder where the dataset_infos.json file was generated", "/path/to/dataset/")
|
179 |
+
if path_to_info != "/path/to/dataset/":
|
180 |
+
dataset_infos = json.load(open(pjoin(path_to_info, "dataset_infos.json")))
|
181 |
+
confs = dataset_infos.keys()
|
182 |
+
all_info_dicts = {}
|
183 |
+
for conf, info in dataset_infos.items():
|
184 |
+
conf_info_dict = dict([(k, info[k]) for k in keep_keys])
|
185 |
+
all_info_dicts[conf] = conf_info_dict
|
186 |
+
dataset_id = list(dataset_infos.values())[0]["builder_name"]
|
187 |
+
else:
|
188 |
+
dataset_id = dataset_choose_list[1]
|
189 |
+
all_info_dicts = all_dataset_infos[dataset_id]
|
190 |
+
else:
|
191 |
+
all_info_dicts = all_dataset_infos[dataset_id]
|
192 |
|
193 |
if only_missing:
|
194 |
config_choose_list = [cid for cid in all_info_dicts
|
|
|
422 |
_ = os.mkdir(pjoin('saved_tags', dataset_id, config_id))
|
423 |
json.dump(res, open(pjoin('saved_tags', dataset_id, config_id, 'tags.json'), 'w'))
|
424 |
|
425 |
+
with c3.beta_expander("Show JSON output for the current config"):
|
426 |
st.write(res)
|
427 |
|
428 |
+
with c3.beta_expander("Show YAML output aggregating the tags saved for all configs"):
|
429 |
+
task_saved_configs = dict([
|
430 |
+
(fname.split('/')[-2], json.load(open(fname)))
|
431 |
+
for fname in glob(f"saved_tags/{dataset_id}/*/tags.json")
|
432 |
+
])
|
433 |
+
aggregate_config = {}
|
434 |
+
for conf_name, saved_tags in task_saved_configs.items():
|
435 |
+
for tag_k, tag_ls in saved_tags.items():
|
436 |
+
aggregate_config[tag_k] = aggregate_config.get(tag_k, {})
|
437 |
+
aggregate_config[tag_k][conf_name] = tuple(sorted(tag_ls))
|
438 |
+
for tag_k in aggregate_config:
|
439 |
+
if len(set(aggregate_config[tag_k].values())) == 1:
|
440 |
+
aggregate_config[tag_k] = list(list(set(aggregate_config[tag_k].values()))[0])
|
441 |
+
else:
|
442 |
+
for conf_name in aggregate_config[tag_k]:
|
443 |
+
aggregate_config[tag_k][conf_name] = list(aggregate_config[tag_k][conf_name])
|
444 |
+
st.text(yaml.dump(aggregate_config))
|
445 |
|
446 |
c3.markdown("--- ")
|
447 |
|