-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into prompts-eval
- Loading branch information
Showing
152 changed files
with
17,886 additions
and
5,368 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import nbformat\n", | ||
"from pathlib import Path\n", | ||
"from nb_helpers.utils import find_nbs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"152" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"nbs_paths = find_nbs(\"../../\")\n", | ||
"len(nbs_paths)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"Path('/Users/tcapelle/work/examples/colabs/boosting/Credit_Scorecards_with_XGBoost_and_W&B.ipynb')" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"nb_path = nbs_paths[3]\n", | ||
"nb_path\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"wandb.login()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nb = nbformat.read(nb_path, 4)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"18" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"login_idx = idx_login_cell(nb, delete_line=False)\n", | ||
"login_idx" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"login_code = \"wandb.login()\" # or !wandb login\n", | ||
"\n", | ||
"def insert_login_cell(nb, idx, code=login_code, replace=True):\n", | ||
" n_cells = len(nb[\"cells\"])\n", | ||
" login_cell = nbformat.v4.new_code_cell(source=code)\n", | ||
" nb[\"cells\"].insert(idx+1, login_cell)\n", | ||
" return nb" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nb = insert_login_cell(nb, login_idx)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'cell_type': 'code',\n", | ||
" 'execution_count': None,\n", | ||
" 'metadata': {},\n", | ||
" 'outputs': [],\n", | ||
" 'source': '!wandb login'}" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"nb[\"cells\"][login_idx] " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'id': 'ff6708eb',\n", | ||
" 'cell_type': 'code',\n", | ||
" 'metadata': {},\n", | ||
" 'execution_count': None,\n", | ||
" 'source': '!wandb login',\n", | ||
" 'outputs': []}" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"nb[\"cells\"][login_idx+1] " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'attachments': {},\n", | ||
" 'cell_type': 'markdown',\n", | ||
" 'metadata': {},\n", | ||
" 'source': '## Vehicle Loan Dataset\\n\\nWe will be using a simplified version of the [Vehicle Loan Default Prediction dataset](https://www.kaggle.com/sneharshinde/ltfs-av-data) from L&T which has been stored in W&B Artifacts. '}" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"nb[\"cells\"][login_idx+2] " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def remove_properties(nb, props=[\"id\", \"idx_\", \"path_\"]):\n", | ||
" for cell in nb[\"cells\"]:\n", | ||
" for prop in props:\n", | ||
" cell.pop(prop, None)\n", | ||
" return nb\n", | ||
"\n", | ||
"def remove_empty_cells(nb):\n", | ||
" nb[\"cells\"] = [cell for cell in nb[\"cells\"] if cell[\"source\"] != \"\"]\n", | ||
" return nb" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nb = remove_properties(nb)\n", | ||
"nb = remove_empty_cells(nb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for nb_path in nbs_paths:\n", | ||
" nb = nbformat.read(nb_path, 4)\n", | ||
" login_idx = idx_login_cell(nb)\n", | ||
" if login_idx is not None:\n", | ||
" nb = insert_login_cell(nb, login_idx)\n", | ||
" # delete path_ attribute\n", | ||
" nb.pop(\"path_\", None)\n", | ||
" nb = remove_properties(nb)\n", | ||
" nb = remove_empty_cells(nb)\n", | ||
" nbformat.validate(nb)\n", | ||
" nbformat.write(nb, nb_path)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "nbdev2", | ||
"language": "python", | ||
"name": "python3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.