{"id":6544,"date":"2021-01-19T16:34:32","date_gmt":"2021-01-19T16:34:32","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=6544"},"modified":"2021-01-19T16:34:38","modified_gmt":"2021-01-19T16:34:38","slug":"tracking-machine-learning-projects-with-weights-biases","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2021\/01\/tracking-machine-learning-projects-with-weights-biases\/","title":{"rendered":"Tracking machine learning projects with Weights &amp; Biases"},"content":{"rendered":"\n<p>Optimising machine learning models requires extensive comparison of architectures and hyperparameter combinations. There are many frameworks that make logging and visualising performance metrics across model runs easier. I recently started using Weights &amp; Biases. In the following, I give a brief overview over some basic code snippets for your machine learning python code to get started with this tool.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>For account setup see <a href=\"https:\/\/docs.wandb.ai\/quickstart\">here<\/a>. The basic account is free.<\/p>\n\n\n\n<p>First, initialise the run alongside all parameters you want to keep track off before you start the model training:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wandb.init(\n    project='demo_project',\n    name='demo_run',\n    config={\n        'learning_rate': 0.001,\n        'dropout': 0.2,\n        'layers': 6,\n        'train epochs': 3\n    }\n)<\/pre>\n\n\n\n<p> This will set up a project &#8216;demo_project&#8217; in your Weights &amp; Biases account and log the following code as the run &#8216;demo_run&#8217;, associating the hyperparameters logged in config with the run metrics.<\/p>\n\n\n\n<p>We can then log any metrics to this run as demonstrated here:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for epoch in range(1, 5):\n    for step in range(1, 100):\n        \n        ####\n        # Model training goes here\n        ####\n\n        # simulating loss and accuracy of train step\n        dummy_loss = mult * (1\/(step + 5 * epoch) + random.random()\/(step + 5 * epoch))\n        dummy_accuracy =  1 - mult * (1\/math.sqrt((step + 5 * epoch) + random.random()))\n        \n        # log to Weights &amp; Biases\n        wandb.log({'Train loss': dummy_loss})\n        wandb.log({'Train accuracy': dummy_accuracy})\n\n    ####\n    # Model testing per epoch goes here\n    ####\n    \n    dummy_test_loss = mult * (1 \/ (epoch * 10) + random.random() \/ (epoch * 10))\n    dummy_test_accuracy = 1 - mult * (1\/math.sqrt(epoch * 10 + random.random()))\n    wandb.log({'Test loss': dummy_test_loss})\n    wandb.log({'Test accuracy': dummy_test_accuracy})<\/pre>\n\n\n\n<p>This can the be used for easy visualisation of training and testing progress:<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_test_loss.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"600\" height=\"300\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_test_loss.png?resize=600%2C300&#038;ssl=1\" alt=\"\" data-id=\"6558\" data-full-url=\"https:\/\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_test_loss.png\" data-link=\"https:\/\/www.blopig.com\/blog\/?attachment_id=6558\" class=\"wp-image-6558\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_test_loss.png?w=600&amp;ssl=1 600w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_test_loss.png?resize=300%2C150&amp;ssl=1 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_train_loss.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"600\" height=\"300\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_train_loss.png?resize=600%2C300&#038;ssl=1\" alt=\"\" data-id=\"6559\" data-full-url=\"https:\/\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_train_loss.png\" data-link=\"https:\/\/www.blopig.com\/blog\/?attachment_id=6559\" class=\"wp-image-6559\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_train_loss.png?w=600&amp;ssl=1 600w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_train_loss.png?resize=300%2C150&amp;ssl=1 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>And even to generate quick visualisations of hyperparameter sweeps:<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_sweep.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"600\" height=\"300\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_sweep.png?resize=600%2C300&#038;ssl=1\" alt=\"\" data-id=\"6560\" data-full-url=\"https:\/\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_sweep.png\" data-link=\"https:\/\/www.blopig.com\/blog\/?attachment_id=6560\" class=\"wp-image-6560\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_sweep.png?w=600&amp;ssl=1 600w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/01\/demo_sweep.png?resize=300%2C150&amp;ssl=1 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>Weights &amp; Biases has a number of additional <a href=\"https:\/\/docs.wandb.ai\/\">features<\/a>, including automated running of hyperparameter optimisation and integration into standard machine learning frameworks, which I will go into in a later post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Optimising machine learning models requires extensive comparison of architectures and hyperparameter combinations. There are many frameworks that make logging and visualising performance metrics across model runs easier. I recently started using Weights &amp; Biases. In the following, I give a brief overview over some basic code snippets for your machine learning python code to get [&hellip;]<\/p>\n","protected":false},"author":54,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,189,227],"tags":[],"ppma_author":[536],"class_list":["post-6544","post","type-post","status-publish","format-standard","hentry","category-code","category-machine-learning","category-python-code"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":536,"user_id":54,"is_guest":0,"slug":"constantin","display_name":"Constantin Schneider","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/a5a52b2568c59d46723b7a77f296dbd5cb9d683382a754d869cad2aa2d6d5c6b?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/6544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/54"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=6544"}],"version-history":[{"count":5,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/6544\/revisions"}],"predecessor-version":[{"id":6563,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/6544\/revisions\/6563"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=6544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=6544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=6544"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=6544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}