Skip to content

Commit

Permalink
Tutorials: fix headers and remove emojis (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
J2-D2-3PO authored Jan 10, 2025
1 parent 5d441ef commit dcbbd42
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 150 deletions.
2 changes: 1 addition & 1 deletion content/tutorials/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See the following tutorials for step by step information on how to use popular M

- [PyTorch](/tutorials/pytorch)
- [PyTorch Lightning](/tutorials/lightning)
- [HuggingFace 🤗 Transformers](/tutorials/huggingface)
- [HuggingFace Transformers](/tutorials/huggingface)
- Tensorflow
- [Track experiments](/tutorials/tensorflow)
- [Tune hyperparameters](/tutorials/tensorflow_sweeps)
Expand Down
31 changes: 16 additions & 15 deletions content/tutorials/artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Follow along with a [video tutorial](http://tiny.cc/wb-artifacts-video).

## About artifacts

An artifact, like a Greek [amphora 🏺](https://en.wikipedia.org/wiki/Amphora),
An artifact, like a Greek [amphora](https://en.wikipedia.org/wiki/Amphora),
is a produced object -- the output of a process.
In ML, the most important artifacts are _datasets_ and _models_.

Expand All @@ -30,7 +30,9 @@ where a training run takes in a dataset and produces a model.
Since one run can use another run's output as an input, `Artifact`s and `Run`s together form a directed graph (a bipartite [DAG](https://en.wikipedia.org/wiki/Directed_acyclic_graph), with nodes for `Artifact`s and `Run`s
and arrows that connect a `Run` to the `Artifact`s it consumes or produces.

# 0️⃣ Install and Import
## Use artifacts to track models and datatsets

### Install and Import

Artifacts are part of our Python library, starting with version `0.9.2`.

Expand All @@ -49,7 +51,7 @@ import os
import wandb
```

# 1️⃣ Log a Dataset
### Log a Dataset

First, let's define some Artifacts.

Expand Down Expand Up @@ -160,7 +162,7 @@ def load_and_log():
load_and_log()
```

### 🚀 `wandb.init`
#### `wandb.init`


When we make the `Run` that's going to produce the `Artifact`s,
Expand All @@ -180,7 +182,7 @@ This keeps the graph of your Artifacts nice and tidy.

> **Rule of 👍**: the `job_type` should be descriptive and correspond to a single step of your pipeline. Here, we separate out `load`ing data from `preprocess`ing data.
### 🏺 `wandb.Artifact`
#### `wandb.Artifact`


To log something as an `Artifact`, we have to first make an `Artifact` object.
Expand All @@ -202,7 +204,7 @@ The `metadata` just needs to be serializable to JSON.

> **Rule of 👍**: the `metadata` should be as descriptive as possible.
### 🐣 `artifact.new_file` and ✍️ `run.log_artifact`
#### `artifact.new_file` and `run.log_artifact`

Once we've made an `Artifact` object, we need to add files to it.

Expand All @@ -227,7 +229,7 @@ including any `Artifact`s that got logged.

We'll see some examples that make better use of the other components of the Run page below.

# 2️⃣ Use a Logged Dataset Artifact
### Use a Logged Dataset Artifact

`Artifact`s in W&B, unlike artifacts in museums,
are designed to be _used_, not just stored.
Expand Down Expand Up @@ -325,7 +327,7 @@ steps = {"normalize": True,
preprocess_and_log(steps)
```

### ✔️ `run.use_artifact`
#### `run.use_artifact`

These steps are simpler. The consumer just needs to know the `name` of the `Artifact`, plus a bit more.

Expand All @@ -342,8 +344,7 @@ so the `Artifact` we want is `mnist-raw:latest`.
Use custom `alias`es like `latest` or `best` when you want an `Artifact`
that satisifies some property

### 📥 `artifact.download`

#### `artifact.download`

Now, you may be worrying about the `download` call.
If we download another copy, won't that double the burden on memory?
Expand All @@ -363,10 +364,10 @@ Check out its contents with `!tree artifacts`:
!tree artifacts
```

### 🌐 The Artifacts page on [wandb.ai](https://wandb.ai)
#### The Artifacts page

Now that we've logged and used an `Artifact`,
let's check out the Artifacts tab on the Run page.
let's check out the Artifacts tab on the Run page.

Navigate to the Run page URL from the `wandb` output
and select the "Artifacts" tab from the left sidebar
Expand All @@ -384,7 +385,7 @@ with the `type`s of `Artifact`s
and the `job_type`s of `Run` as the two types of nodes,
with arrows to represent consumption and production.

# 3️⃣ Log a Model
### Log a Model

That's enough to see how the API for `Artifact`s works,
but let's follow this example through to the end of the pipeline
Expand Down Expand Up @@ -478,7 +479,7 @@ model_config = {"hidden_layer_sizes": [32, 64],
build_model_and_log(model_config)
```

### `artifact.add_file`
#### `artifact.add_file`


Instead of simultaneously writing a `new_file` and adding it to the `Artifact`,
Expand All @@ -489,7 +490,7 @@ and then `add` them to the `Artifact` in another.

> **Rule of 👍**: use `new_file` when you can, to prevent duplication.
# 4️⃣ Use a Logged Model Artifact
#### Use a Logged Model Artifact

Just like we could call `use_artifact` on a `dataset`,
we can call it on our `initialized_model`
Expand Down
2 changes: 1 addition & 1 deletion content/tutorials/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The following image shows what a dashboard can look like:

Now that we know how to integrate W&B into a psuedo machine learning training loop, let's track a machine learning experiment using a basic PyTorch neural network. The following code will also upload model checkpoints to W&B that you can then share with other teams in your organization.

## Track a machine learning experiment using Pytorch
## Track a machine learning experiment using Pytorch

The following code cell defines and trains a simple MNIST classifier. During training, you will see W&B prints out URLs. Click on the project page link to see your results stream in live to a W&B project.

Expand Down
4 changes: 2 additions & 2 deletions content/tutorials/integration-tutorials/huggingface.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Optionally, we can set environment variables to customize W&B logging. See [docu
%env WANDB_WATCH=all
```

# 👟 Train the model
## Train the model
Next, call the downloaded training script [run_glue.py](https://huggingface.co/transformers/examples.html#glue) and see training automatically get tracked to the Weights & Biases dashboard. This script fine-tunes BERT on the Microsoft Research Paraphrase Corpus— pairs of sentences with human annotations indicating whether they are semantically equivalent.


Expand Down Expand Up @@ -109,7 +109,7 @@ Here's an example comparing [BERT vs DistilBERT](https://app.wandb.ai/jack-morri

{{< img src="/images/tutorials/huggingface-comparearchitectures.gif" alt="" >}}

### Track key information effortlessly by default
## Track key information effortlessly by default
Weights & Biases saves a new run for each experiment. Here's the information that gets saved by default:
- **Hyperparameters**: Settings for your model are saved in Config
- **Model Metrics**: Time series data of metrics streaming in are saved in Log
Expand Down
72 changes: 37 additions & 35 deletions content/tutorials/integration-tutorials/keras.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use Weights & Biases for machine learning experiment tracking, dataset versionin
This Colab notebook introduces the `WandbMetricsLogger` callback. Use this callback for [Experiment Tracking](/guides/track). It will log your training and validation metrics along with system metrics to Weights and Biases.


## 🌴 Setup and Installation
## Setup and Installation

First, let us install the latest version of Weights and Biases. We will then authenticate this colab instance to use W&B.

Expand Down Expand Up @@ -43,31 +43,31 @@ If this is your first time using W&B or you are not logged in, the link that app
wandb.login()
```

## 🌳 Hyperparameters
## Hyperparameters

Use of proper config system is a recommended best practice for reproducible machine learning. We can track the hyperparameters for every experiment using W&B. In this colab we will be using simple Python `dict` as our config system.


```python
configs = dict(
num_classes = 10,
shuffle_buffer = 1024,
batch_size = 64,
image_size = 28,
image_channels = 1,
earlystopping_patience = 3,
learning_rate = 1e-3,
epochs = 10
num_classes=10,
shuffle_buffer=1024,
batch_size=64,
image_size=28,
image_channels=1,
earlystopping_patience=3,
learning_rate=1e-3,
epochs=10,
)
```

## 🍁 Dataset
## Dataset

In this colab, we will be using [CIFAR100](https://www.tensorflow.org/datasets/catalog/cifar100) dataset from TensorFlow Dataset catalog. We aim to build a simple image classification pipeline using TensorFlow/Keras.


```python
train_ds, valid_ds = tfds.load('fashion_mnist', split=['train', 'test'])
train_ds, valid_ds = tfds.load("fashion_mnist", split=["train", "test"])
```


Expand All @@ -90,14 +90,10 @@ def parse_data(example):
def get_dataloader(ds, configs, dataloader_type="train"):
dataloader = ds.map(parse_data, num_parallel_calls=AUTOTUNE)

if dataloader_type=="train":
if dataloader_type == "train":
dataloader = dataloader.shuffle(configs["shuffle_buffer"])

dataloader = (
dataloader
.batch(configs["batch_size"])
.prefetch(AUTOTUNE)
)

dataloader = dataloader.batch(configs["batch_size"]).prefetch(AUTOTUNE)

return dataloader
```
Expand All @@ -108,17 +104,21 @@ trainloader = get_dataloader(train_ds, configs)
validloader = get_dataloader(valid_ds, configs, dataloader_type="valid")
```

# 🎄 Model
## Model


```python
def get_model(configs):
backbone = tf.keras.applications.mobilenet_v2.MobileNetV2(weights='imagenet', include_top=False)
backbone = tf.keras.applications.mobilenet_v2.MobileNetV2(
weights="imagenet", include_top=False
)
backbone.trainable = False

inputs = layers.Input(shape=(configs["image_size"], configs["image_size"], configs["image_channels"]))
inputs = layers.Input(
shape=(configs["image_size"], configs["image_size"], configs["image_channels"])
)
resize = layers.Resizing(32, 32)(inputs)
neck = layers.Conv2D(3, (3,3), padding="same")(resize)
neck = layers.Conv2D(3, (3, 3), padding="same")(resize)
preprocess_input = tf.keras.applications.mobilenet.preprocess_input(neck)
x = backbone(preprocess_input)
x = layers.GlobalAveragePooling2D()(x)
Expand All @@ -134,33 +134,35 @@ model = get_model(configs)
model.summary()
```

## 🌿 Compile Model
## Compile Model


```python
model.compile(
optimizer = "adam",
loss = "categorical_crossentropy",
metrics = ["accuracy", tf.keras.metrics.TopKCategoricalAccuracy(k=5, name='top@5_accuracy')]
optimizer="adam",
loss="categorical_crossentropy",
metrics=[
"accuracy",
tf.keras.metrics.TopKCategoricalAccuracy(k=5, name="top@5_accuracy"),
],
)
```

## 🌻 Train
## Train


```python
# Initialize a W&B run
run = wandb.init(
project = "intro-keras",
config = configs
)
run = wandb.init(project="intro-keras", config=configs)

# Train your model
model.fit(
trainloader,
epochs = configs["epochs"],
validation_data = validloader,
callbacks = [WandbMetricsLogger(log_freq=10)] # Notice the use of WandbMetricsLogger here
epochs=configs["epochs"],
validation_data=validloader,
callbacks=[
WandbMetricsLogger(log_freq=10)
], # Notice the use of WandbMetricsLogger here
)

# Close the W&B run
Expand Down
12 changes: 6 additions & 6 deletions content/tutorials/integration-tutorials/keras_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Use Weights & Biases for machine learning experiment tracking, dataset versionin

This Colab notebook introduces the `WandbModelCheckpoint` callback. Use this callback to log your model checkpoints to Weight and Biases [Artifacts](/guides/artifacts).

## 🌴 Setup and Installation
## Setup and Installation

First, let us install the latest version of Weights and Biases. We will then authenticate this colab instance to use W&B.

Expand Down Expand Up @@ -43,7 +43,7 @@ If this is your first time using W&B or you are not logged in, the link that app
wandb.login()
```

## 🌳 Hyperparameters
## Hyperparameters

Use of proper config system is a recommended best practice for reproducible machine learning. We can track the hyperparameters for every experiment using W&B. In this colab we will be using simple Python `dict` as our config system.

Expand All @@ -61,7 +61,7 @@ configs = dict(
)
```

## 🍁 Dataset
## Dataset

In this colab, we will be using [CIFAR100](https://www.tensorflow.org/datasets/catalog/cifar100) dataset from TensorFlow Dataset catalog. We aim to build a simple image classification pipeline using TensorFlow/Keras.

Expand Down Expand Up @@ -108,7 +108,7 @@ trainloader = get_dataloader(train_ds, configs)
validloader = get_dataloader(valid_ds, configs, dataloader_type="valid")
```

## 🎄 Model
## Model


```python
Expand All @@ -134,7 +134,7 @@ model = get_model(configs)
model.summary()
```

## 🌿 Compile Model
## Compile Model


```python
Expand All @@ -145,7 +145,7 @@ model.compile(
)
```

## 🌻 Train
## Train


```python
Expand Down
Loading

0 comments on commit dcbbd42

Please sign in to comment.