Versioning large data files and directories for data science is great, but not enough. How is data filtered, transformed, or used to train ML models? DVC introduces a mechanism to capture data pipelines — series of data processes that produce a final result.
DVC pipelines and their data can also be easily versioned (using Git). This allows you to better organize your project, and reproduce your workflow and results later exactly as they were built originally!
dvc run to create stages. These represent processes (source code tracked
with Git) that form the steps of a pipeline. Stages also connect code to its
data input and output. Let's transform a Python script into a
$ dvc run -n prepare \ -p prepare.seed,prepare.split \ -d src/prepare.py -d data/data.xml \ -o data/prepared \ python src/prepare.py data/data.xml
dvc.yaml file is generated. It includes information about the command we ran
python src/prepare.py), its dependencies, and
There's no need to use
dvc add for DVC to track stage outputs (
in this case);
dvc run already took care of this. You only need to run
dvc push if you want to save them to
(usually along with
git commit to version the stage file itself).
dvc run multiple times, and specifying outputs of a
stage as dependencies of another one, we can describe a sequence of
commands that gets to a desired result. This is what we call a data pipeline
or dependency graph.
Let's create a second stage chained to the outputs of
prepare, to perform
$ dvc run -n featurize \ -p featurize.max_features,featurize.ngrams \ -d src/featurization.py -d data/prepared \ -o data/features \ python src/featurization.py data/prepared data/features
dvc.yaml file is updated automatically and should include two stages now.
The whole point of creating this
dvc.yaml pipeline file is an ability to
reproduce the pipeline:
$ dvc repro
dvc.lockfiles describe what data to use and which commands will generate the pipeline results (such as an ML model). Storing these files in Git makes it easy to version and share.
Having built our pipeline, we need a good way to understand its structure. Seeing a graph of connected stage files would help. DVC lets you do just that, without leaving the terminal!
$ dvc dag +---------+ | prepare | +---------+ * * * +-----------+ | featurize | +-----------+ ** ** ** * * ** +-------+ * | train | ** +-------+ * ** ** ** ** * * +----------+ | evaluate | +----------+
dvc dagto explore other ways this command can visualize a pipeline.