> For AI agents: guidance on navigating Viam documentation is available at https://docs.viam.com/llms.txt.

# Phase 4: Review and build a dataset

Review your recorded episodes, tag the keepers, and collect them into a sequence dataset for training.
> Source: https://docs.viam.com/tutorials/xarm-act-stacking/review-and-build-a-dataset/


Of the 50 or so episodes you recorded, you now decide which ones the policy learns from. Watch each one in the capture-control webapp, tag it as a keeper or a discard, then collect the keepers into a sequence dataset named `xarm-stacking-v1`.

## Why review {#why-review}

A few bad episodes cost more than they add, because a dropped block, a long pause, or a camera dropout all become training data. ACT (Action Chunking with Transformers) learns hesitation as readily as skill, so a policy trained on a pause will pause. A smaller clean set beats a larger mixed one.

## Review in the webapp {#review-in-the-webapp}

Open the capture-control webapp. Below the camera views are two buttons, **Review session** and **Episodes**:

![The capture-control webapp's status line, DONE, 6 of 50 episodes, above the Review session (6 episodes) and Episodes buttons, both outlined.](/tutorials/xarm-act-stacking/webapp-review-buttons.png)

- **Review session** lists the episodes from the session you just ended, as they sync.
- **Episodes** opens the same player for this machine's past episodes. Filter by task, session, and review status.

Each episode plays its camera frames in real time. Press **K** to tag the episode `review:keep` or **D** to tag it `review:discard`, and the app jumps to the next episode you haven't reviewed.

Nothing is deleted. An episode with neither tag counts as not reviewed.

A sequence can appear before all its frames have synced. **K** and **D** unlock once the frames have caught up, or after 15 seconds with no new frames, when the app marks the episode partial. Discard partial episodes.

| Key       | Action                                                  |
| --------- | ------------------------------------------------------- |
| **K / D** | Keep or discard, then go to the next unreviewed episode |
| **← / →** | Previous or next episode                                |
| **Space** | Play or pause                                           |
| **, / .** | Step one frame                                          |
| **Esc**   | Close review                                            |

![The capture-control webapp's review player: the wrist-cam and scene-cam frames above a playback bar, the Episodes list with task, session, source, and outcome filters, and the Keep and Discard buttons.](/tutorials/xarm-act-stacking/webapp-review.png)

## What to discard {#what-to-discard}

Discard an episode if any of these happened:

- The stack failed, or a block was knocked over.
- The arm paused for a long time.
- The gripper re-grasped the block.
- The arm left the camera frame.
- The episode is partial.

When in doubt, discard it. You can always record more.

## Create the sequence dataset {#create-the-sequence-dataset}

Collect every sequence tagged `review:keep` into a new sequence dataset named `xarm-stacking-v1`. Dataset names must be unique in your organization.




### Viam app

<ol>
<li>On the **DATA** tab, click **DATASETS**.</li>
<li>Click **Create dataset**.</li>
<li>In the **Dataset Name** field, enter `xarm-stacking-v1`.</li>
<li>Set **Data type** to **Sequence Data**, and click **Create dataset** again.</li>
<li>Open the dataset and click **Add Data**.</li>
<li>In the **All sequences** dialog, select the sequences tagged both `review:keep` and `task:stack the red block on the green block`, and click **Add**. Check both tags: a shared machine can hold kept sequences from other tasks, and Phase 7’s policy rollouts carry the same task tag. Leave out any sequence tagged `source:policy`.</li>
</ol>

    
    
    

    
    

    
        
        
        
        
        
        
        
<picture>
    <source
        srcset="/tutorials/xarm-act-stacking/sequences-review-keep_hu_4bd7b666bd8694c5.webp 480w, /tutorials/xarm-act-stacking/sequences-review-keep_hu_ec6cba109f308262.webp 768w, /tutorials/xarm-act-stacking/sequences-review-keep_hu_a0dffebae8ac553b.webp 1200w"
        sizes="(min-width: 60rem) 80vw, (min-width: 40rem) 90vw, 100vw"
    />
    <img
        sizes="(min-width: 60rem) 80vw, (min-width: 40rem) 90vw, 100vw"
        srcset="/tutorials/xarm-act-stacking/sequences-review-keep_hu_971786061b6c68fb.png 480w, /tutorials/xarm-act-stacking/sequences-review-keep_hu_5b309cd03ba09146.png 768w, /tutorials/xarm-act-stacking/sequences-review-keep_hu_e37f6bcaa5b86085.png 1024w"
        src="/tutorials/xarm-act-stacking/sequences-review-keep.png"
        width="2638"
        height="1540"
        alt="The SEQUENCES tab filtered by the review:keep tag, showing kept episodes with their task, session, fps, and review tags."
        loading="lazy"
        style="width:1000px"
    >
</picture>

The dataset’s sidebar shows how many sequences it holds.

### CLI and Python

This path uses the Python SDK, so a script picks the sequences instead of you copying their IDs. It lists every sequence in your organization, keeps this machine’s demonstrations tagged `review:keep` for this task, skips policy rollouts, creates the dataset, and adds them. Save this as `create_dataset.py`:

```python
import asyncio
import os
import sys

from viam.app.viam_client import ViamClient
from viam.proto.app.dataset import DatasetType
from viam.rpc.dial import DialOptions

TASK_TAG = "task:stack the red block on the green block"

async def main():
    client = await ViamClient.create_from_dial_options(
        DialOptions.with_api_key(
            os.environ["VIAM_API_KEY"], os.environ["VIAM_API_KEY_ID"]
        )
    )
    data = client.data_client

    sequence_ids = []
    page_token = None
    while True:
        sequences, page_token = await data.list_sequences(
            organization_id=os.environ["VIAM_ORG_ID"], page_token=page_token
        )
        for s in sequences:
            if s.part_id != os.environ["VIAM_PART_ID"]:
                continue
            tags = set(s.sequence_tags)
            if {"review:keep", TASK_TAG} <= tags and "source:policy" not in tags:
                sequence_ids.append(s.id)
        if not page_token:
            break

    if not sequence_ids:
        print("No sequences are tagged review:keep. Review some episodes first.")
        client.close()
        sys.exit(1)

    dataset_id = await data.create_dataset(
        name="xarm-stacking-v1",
        organization_id=os.environ["VIAM_ORG_ID"],
        type=DatasetType.DATASET_TYPE_SEQUENCE_DATA,
    )
    await data.add_sequences_to_dataset(
        dataset_id=dataset_id, sequence_ids=sequence_ids
    )
    print(f"{dataset_id}: {len(sequence_ids)} sequences")
    client.close()

asyncio.run(main())
```
To find your organization ID, your machine’s ID, and the ID of its main part, run:

```sh
viam organizations list
viam machines list --organization=<org-id> --all
viam machines part list --machine=<machine-id>
```
The script needs an organization API key. A key for a machine part isn’t enough. Create one:

```sh
viam organizations api-key create --org-id=<org-id> --name=xarm-stacking
```
Then export the IDs and the key for the script to read:

```sh
export VIAM_ORG_ID=<org-id>
export VIAM_PART_ID=<part-id>
export VIAM_API_KEY_ID=<api-key-id>
export VIAM_API_KEY=<api-key>
```
The script needs the Python SDK. Install it with `pip install "viam-sdk>=0.83.1"`, then run it:

```sh
python create_dataset.py
```
Note the dataset ID it prints. You use it in the next section.



For more on sequence datasets, see [Create a dataset](/train/create-a-dataset/).

> **Checkpoint:**
> 
> The dataset `xarm-stacking-v1` exists, and its sequence count matches your keep count. Aim for at least 40 sequences.

## Sanity-check the export (optional) {#sanity-check-the-export-optional}

Export the dataset to a local folder and confirm that it holds one sequence per kept episode. Use the dataset ID from the dataset page or the script:

```sh {class="command-line" data-prompt="$"}
viam dataset export \
  --dataset-id=<dataset-id> \
  --destination=./xarm-stacking-v1 \
  --only-parquet
```

`--only-parquet` skips the images, so the export is small. It writes `<dataset-id>.zip` to the destination. `sequences.parquet` has one row per sequence. To count the rows, install `pandas` and `pyarrow` (`pip install pandas pyarrow`), then run:

```sh {class="command-line" data-prompt="$"}
python -c "import io, zipfile, pandas as pd; z = zipfile.ZipFile('xarm-stacking-v1/<dataset-id>.zip'); print(len(pd.read_parquet(io.BytesIO(z.read('sequences.parquet')))))"
```

The number should equal your keep count. For every column in the export, see [Sequence datasets](/train/dataset-formats/#sequence-datasets).

<nav class="workshop-nav" aria-label="Workshop phase navigation"><p class="workshop-progress">Phase 4 of 7</p><div class="workshop-nav-links"><a class="workshop-nav-prev" href="/tutorials/xarm-act-stacking/record-demonstrations/">&larr; Previous</a><a class="workshop-nav-next" href="/tutorials/xarm-act-stacking/train-a-policy/">Next &rarr;</a></div>
</nav>


