{"id":8299,"date":"2022-06-14T15:14:08","date_gmt":"2022-06-14T14:14:08","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=8299"},"modified":"2022-08-17T11:02:16","modified_gmt":"2022-08-17T10:02:16","slug":"visualise-with-weight-and-biases","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2022\/06\/visualise-with-weight-and-biases\/","title":{"rendered":"Visualise with Weight and Biases"},"content":{"rendered":"\n<p>Understanding what\u2019s going on when you\u2019ve started training your shiny new ML model is hard enough. Will it work? Have I got the right parameters? Is it the data? Probably.&nbsp; Any tool that can help with that process is a Godsend. Weights and biases is a great tool to help you visualise and track your model throughout your production cycle. In this blog post, I\u2019m going to detail some basics on how you can initialise and use it to visualise your next project.<\/p>\n\n\n\n<p><strong>Installation<\/strong><\/p>\n\n\n\n<p>To use weights and biases (wandb), you need to make an account. For individuals it is free, however, for team-oriented features, you will have to pay. Wandb can then be installed using pip or conda.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ \tconda install -c conda-forge wandb\n\nor \n\n$   pip install wandb\n<\/pre>\n\n\n\n<p>To initialise your project, import the package, sign in, and then use the following command using your chosen project name and username (if you want):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import wandb\n\nwandb.login()\n\nwandb.init(project='project1')\n<\/pre>\n\n\n\n<p>In addition to your project, you can also initialise a config dictionary with starting parameter values:<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wandb.init(\n\tproject='project1',\n\tname='project1_exp1',\n\tconfig={\n\t\t'learning_rate':0.02,\n\t\t'architecture':'RNN',\n\t\t'epochs':5\n\t\t}\n\t)\n<\/pre>\n\n\n\n<p>Thankfully, wandb has made it super easy to track and visualise your experiments as you often only need one or two lines. To log any parameter simply chose how often you would like to take measurements (e.g. through an if statement in the training cycle based on the iteration count), then save the parameter&#8217;s value:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wandb.log({'loss': loss, 'accuracy':accuracy'})\n\n# Note: the parameter values should be defined and calculated as part of the training loop before logging.\n<\/pre>\n\n\n\n<p>Once complete you must mark the job as complete:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wandb.finish()\n<\/pre>\n\n\n\n<p>The results can then be viewed under the project section of your wandb page. This is only the simplest use-case of weights and biases. Additional features include system hardware tracking ( e.g. GPU utilisation), data visualisation and hyperparameter tuning and data visualisation. For more information I found this article very helpful when starting: <a href=\"https:\/\/theaisummer.com\/weights-and-biases-tutorial\/\">https:\/\/theaisummer.com\/weights-and-biases-tutorial\/<\/a><\/p>\n\n\n\n<p>Weights and Biases: <a href=\"https:\/\/wandb.ai\/site\">https:\/\/wandb.ai\/site<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding what\u2019s going on when you\u2019ve started training your shiny new ML model is hard enough. Will it work? Have I got the right parameters? Is it the data? Probably.&nbsp; Any tool that can help with that process is a Godsend. Weights and biases is a great tool to help you visualise and track your [&hellip;]<\/p>\n","protected":false},"author":75,"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,296,14,227],"tags":[172,152],"ppma_author":[553],"class_list":["post-8299","post","type-post","status-publish","format-standard","hentry","category-code","category-hints-and-tips","category-howto","category-python-code","tag-machine-learning","tag-python"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":553,"user_id":75,"is_guest":0,"slug":"maranga","display_name":"Maranga Mokaya","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1fdf4dab73e0e7c801c72c921e529f4827e4af020e7f9124bde0a4adc1cb861b?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\/8299","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\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=8299"}],"version-history":[{"count":2,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/8299\/revisions"}],"predecessor-version":[{"id":8321,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/8299\/revisions\/8321"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=8299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=8299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=8299"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=8299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}