A lightweight Python package for taking notes on your machine learning experiments
Project description
hypernotes
hypernotes is a lightweight Python package for taking notes on your machine learning experiments. It provides a simple way to store hyperparameters, their corresponding evaluation metrics, as well as additional information and retrieve them again later for analyzing. It is written in pure Python and requires no additional dependencies.
Installation
pip install hypernotes
Only Python 3.6+ is supported
Basic Usage
hypernotes implements a Note and a Store class. A Note is a small wrapper around Python dictionaries. This means that you can do everything with it, that you could do with a normal dictionary, but in addition, it stores:
- the path to your Python executable,
- information about the current state of your Git repository (if there is one) such as the last commit, current branch, etc.,
- start (upon initialization) and end datetime (call note.end() or add to store)
and it provides
- a useful default dictionary structure (print a note instance and you will see what's inside)
- access to the most commonly used dictionary keys as attributes for better auto-completion support and readability (see below, for example
note.metrics
)
The notes are then saved with a Store instance, which uses a json file. Due to this, you should only add json serializable objects + datetime.datetime instances to a Note.
A note is uniquely identifiable by its identifier
attribute, which is the start datetime in ISO format.
Add a note
from hypernotes import Note, Store
note = Note("Some descriptive text about your experiment")
# Add name of used algorithm
note.model = "randomforest"
# Add hyperparameters about model training, preprocessing, etc.
note.parameters["num_estimators"] = 100
note.parameters["impute_missings"] = True
# Add the names of the features and of the target variable
note.features["identifier"] = ["id"]
note.features["binary"] = ["bool1"]
note.features["categorical"] = ["cat1", "cat2"]
note.features["numerical"] = ["num1"]
note.target = "target"
# Some additional information
note.info["important_stuff"] = "something noteworthy"
# ... Rest of your code ...
# train_recall, train_precision test_recall, test_precision = train_and_evaluate_model(
# parameters=note.params,
# feature_names=note.features,
# target_name=note.target)
# ...
# Add your calculated evaluation metrics
note.metrics["train"] = {"recall": train_recall, "precision": train_precision}
note.metrics["test"] = {"recall": test_recall, "precision": test_precision}
store = Store("hyperstore.json")
store.add(note)
Load notes
A Store instance provides the load
method, which can be used to retrieve the whole store. By default it returns a sorted list (most recent note first).
notes = store.load()
most_recent_note = notes[0]
print(most_recent_note.identifier)
If you have pandas installed, you can use the return_dataframe
argument to return a pandas dataframe.
notes_df = store.load(return_dataframe=True)
notes_df.head()
Update notes
If you want to update notes, you can do this either directly in the json file containing the notes, or load the notes as described above, change the relevant ones, and pass them to the update
method.
notes = store.load()
updated_notes = []
for note in notes[:2]:
note.info["something_new"] = "..."
updated_notes.append(note)
store.update(updated_notes)
Remove notes
If you want to remove notes, you can do this either directly in the json file containing the notes, or load the notes as described above, and pass the ones which you want to remove to the remove
method.
notes = store.load()
notes_to_remove = notes[:2]
store.remove(notes_to_remove)
View content of a store
Directly in your browser (no additional dependencies)
To get a quick glance into a store, you can use the following command. It will start an http server and automatically open the relevant page in your web browser. The page contains an interactive table which shows the most relevant information of all notes in the store such as metrics and parameters.
$ python -m hypernotes hyperstore.json
This only requires a modern web browser as well as an internet connection to load a view javascript libraries and css files.
pandas and QGrid
Another useful option might be to load the store as a pandas dataframe (see Load notes) and then use Qgrid in a Jupyter notebook.
Bonus: Store additional objects in separate experiment folders
If you want to store larger artifacts of your experiment, such as a trained model, you could create a separate folder and use the identifier of a note as part of the name.
experiment_folder = f"experiment_{note.identifier}"
You can then store any additional objects into this folder and it will be very easy to lather on link them again to the hyperparameters and metrics stored using hypernotes.
Other tools
Check out tools such as MLflow, Sacred, or DVC if you need better multi-user capabilities, more advanced reproducibility features, dataset versioning, ...
Development
Feel free to open a GitHub issue or even better submit a pull request if you find a bug or miss a feature.
Any requirements for developing the package can be installed with
pip install -r requirements_dev.txt
Code is required to be formatted with Black.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hypernotes-0.3.0.tar.gz
.
File metadata
- Download URL: hypernotes-0.3.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01bc74edcfc95cf8e3f892a61427986bc3effcaf6e77d9c660fa66ffb54dd7f5 |
|
MD5 | 0839a44776a7024fe51335fb7e05b53b |
|
BLAKE2b-256 | 483226d62797cbb1e30ab0718dff0050337d09c321ec91f28c4e7b412c6da559 |
Provenance
File details
Details for the file hypernotes-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: hypernotes-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bafaa8e91ba62a145e21c36c802e6933e65d57dff9c86f7b0a7e523d58b52ee |
|
MD5 | 17ff40eef6b3ce789b56c63b8123d166 |
|
BLAKE2b-256 | e67e8fada3e83a9b7d206c1773ffe3af5f9a1c8b532b908522b4a6cfed3e965d |