|
| 1 | +# Development |
| 2 | + |
| 3 | +This guide provides a checklist for contributing new cleanvision examples. |
| 4 | + |
| 5 | +- Ensure that the notebook contains cell outputs and that they look as expected in Jupyter notebook and **on GitHub**. |
| 6 | + Note this is different than our tutorials in the main cleanvision repository (where notebook cells should not be |
| 7 | + executed)! Unlike the tutorials, we want examples notebooks to also look good in GitHub's viewer (which has limited |
| 8 | + rendering functionality, so avoid things like `<div>` that GitHub's viewer does not render properly). |
| 9 | + |
| 10 | +- Ensure that the jupyter notebook cells are executed in order. Additionally clear any cell blocks that are too large ( |
| 11 | + eg. model training code that specifies accuracy for each epoch), it is ok if these do not have an execution number |
| 12 | + after being cleared. |
| 13 | + |
| 14 | +- The first cell of the notebook should be a markdown block containing the text: |
| 15 | + ``` |
| 16 | + [](https://colab.research.google.com/github/cleanlab/cleanvision-examples/blob/main/{ relative path to notebook }.ipynb) |
| 17 | + ``` |
| 18 | +
|
| 19 | + Replace the `{ relative path to notebook }` portion with the path to the notebook relative to the root folder. |
| 20 | +
|
| 21 | + > eg. the [caltech256.ipynb](caltech256.ipynb) notebook will have a relative path of `caltech256.ipynb` and will have |
| 22 | + the badge: |
| 23 | + > |
| 24 | + > ``` |
| 25 | + > [](https://colab.research.google.com/github/cleanlab/cleanvision-examples/blob/main/caltech256.ipynb) |
| 26 | + > ``` |
| 27 | +
|
| 28 | + This will create a badge that will link to a Google Colab version of the notebook. |
| 29 | +
|
| 30 | + Note that the Colab badge links to the notebook in the main branch, so at the time of making the PR, the link will be |
| 31 | + invalid. Please remember to check that the Colab link works after the PR has been approved and merged to `main`. |
| 32 | +
|
| 33 | + The Colab badge must also be in its own notebook cell, not with other content. |
| 34 | +
|
| 35 | +- Ensure that your notebook is using the correct kernel. In jupyter notebook, you can check the notebook's metadata by |
| 36 | + navigating to `Edit` > `Edit Notebook Metadata` and check if the follow fields match this: |
| 37 | +
|
| 38 | +```json |
| 39 | +"kernelspec": { |
| 40 | +"name": "python3", |
| 41 | +"display_name": "Python 3 (ipykernel)", |
| 42 | +"language": "python" |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +- Add the notebook to the [README](README.md), ideally grouping the newly added example with any other related examples. |
| 47 | + |
| 48 | +- After a new notebook has been added and pushed to `main` branch, AVOID changing the notebook and folder names, as this |
| 49 | + may break existing links referencing the example notebook throughout cleanvision documentation, blog posts, and more. |
| 50 | + |
| 51 | +- If the example requires some packages other than the ones in [requirements-dev.txt](requirements-dev.txt), Please |
| 52 | + create a separate `requirements.txt` specific to that example with extra packages required. Put these requirements and |
| 53 | + any related jupyter notebooks in a directory instead of the root folder. |
| 54 | + |
| 55 | +## Set up the environment for running notebooks |
| 56 | + |
| 57 | +While this is not required, we recommend that you do development and testing in a virtual environment. There are a |
| 58 | +number of tools to do this, including [virtualenv](https://virtualenv.pypa.io/), [pipenv](https://pipenv.pypa.io/), |
| 59 | +and [venv](https://docs.python.org/3/library/venv.html). You |
| 60 | +can [compare](https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe) |
| 61 | +the tools and choose what is right for you. Here, we'll explain how to get set up with venv, which is built in to Python |
| 62 | + |
| 63 | +```shell |
| 64 | +python3 -m venv cleanvision-examples |
| 65 | +source cleanvision-examples/bin/activate |
| 66 | +pip install --upgrade pip |
| 67 | +pip install -r requirements-dev.txt |
| 68 | +python -m ipykernel install --user --name=cleanvision-examples |
| 69 | +``` |
| 70 | + |
| 71 | +Choose the `cleanvision-examples` kernel in the jupyter notebook when running. |
| 72 | + |
| 73 | +You only need to create the virtual environment once, but you will need to |
| 74 | +activate it every time you start a new shell. Once the virtual environment is |
| 75 | +activated, the `pip install` commands below will install dependencies into the |
| 76 | +virtual environment rather than your system Python installation. |
0 commit comments