{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "30a1ff83e388495ab06f4b8177746d4b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Saving the dataset (0/1 shards): 0%| | 0/6260 [00:00{str(row['tag_description'])}\"\n", " elif mode == 'tn_td':\n", " input_str = f\"{str(row['tag_name'])}{str(row['tag_description'])}\"\n", " elif mode == 'tn_td_min_max':\n", " input_str = f\"{str(row['tag_name'])}{str(row['tag_description'])}{row['min']}{row['max']}\"\n", " elif mode == 'td_min_max':\n", " input_str = f\"{str(row['tag_description'])}{row['min']}{row['max']}\"\n", " elif mode == 'td_unit':\n", " input_str = f\"{str(row['tag_description'])}{str(row['unit'])}\"\n", " elif mode == 'tn_td_unit':\n", " input_str = f\"{str(row['tag_name'])}{str(row['tag_description'])}{str(row['unit'])}\"\n", " elif mode == 'td_min_max_unit':\n", " input_str = f\"{str(row['tag_description'])}{row['min']}{row['max']}{str(row['unit'])}\"\n", " else:\n", " raise ValueError(\"Invalid mode specified\")\n", " \n", " output_list.append({\n", " 'translation': {\n", " 'ships_idx': row['ships_idx'],\n", " 'input': input_str,\n", " 'thing_property': f\"{str(row['thing'])}{str(row['property'])}\",\n", " 'answer': f\"{str(row['thing'])} {str(row['property'])}\",\n", " }\n", " })\n", " except Exception as e:\n", " print(f\"Error processing row at index {idx}: {e}\")\n", " return output_list\n", "\n", "combined_dict = {\"mode\": mode, \"fold_group\": group_number}\n", "with open(\"mode.json\", \"w\") as json_file:\n", " json.dump(combined_dict, json_file)\n", "\n", "combined_data = DatasetDict({\n", " 'train': Dataset.from_list(process_df(train_data, mode=mode)),\n", " 'test': Dataset.from_list(process_df(test_data, mode=mode)),\n", " 'validation': Dataset.from_list(process_df(valid_data, mode=mode)),\n", "})\n", "combined_data.save_to_disk(f\"combined_data/{mode}/{group_number}\")\n", "print(\"Dataset saved to 'combined_data'\")\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }