使用MLflow
MLflow 是一个用于跟踪机器学习结果的图形化工具。PyKEEN 将 MLflow 集成到管道和 HPO 管道中。
要使用它,您首先需要使用pip install mlflow安装MLflow,并在后台运行mlflow ui。更多信息可以在MLflow快速入门中找到。默认情况下,它将在http://localhost:5000运行。
管道示例
此示例展示了如何将MLflow与pykeen.pipeline.pipeline()函数一起使用。
在result_tracker_kwargs中,至少需要tracking_uri和experiment_name。
from pykeen.pipeline import pipeline
pipeline_result = pipeline(
model='RotatE',
dataset='Kinships',
result_tracker='mlflow',
result_tracker_kwargs=dict(
tracking_uri='http://localhost:5000',
experiment_name='Tutorial Training of RotatE on Kinships',
),
)
如果您导航到http://localhost:5000的MLflow UI,您会看到实验出现在左侧栏中。
如果您点击实验,您将看到以下内容:
HPO 示例
此示例展示了如何将MLflow与pykeen.hpo.hpo_pipeline()函数一起使用。
from pykeen.hpo import hpo_pipeline
pipeline_result = hpo_pipeline(
model='RotatE',
dataset='Kinships',
result_tracker='mlflow',
result_tracker_kwargs=dict(
tracking_uri='http://localhost:5000',
experiment_name='Tutorial HPO Training of RotatE on Kinships',
),
)
对于这个例子,可以通过MLflow进行相同的导航。
重用实验
在MLflow UI中,您会看到实验被分配了一个ID。这意味着您可以使用experiment_id关键字参数来重新使用相同的ID,将不同的子实验分组在一起,而不是使用experiment_name。
from pykeen.pipeline import pipeline
experiment_id = 4 # if doesn't already exist, will throw an error!
pipeline_result = pipeline(
model='RotatE',
dataset='Kinships',
result_tracker='mlflow'
result_tracker_kwargs=dict(
tracking_uri='http://localhost:5000',
experiment_id=4,
),
)