Skip to content

Recipes

recipe

Classes:

  • RecipeRegistry

    Registry recipe for managing all pre-defined recipe in the form of Callable object.

Functions:

  • build_tgb_link_pred

    Build ready-to-use HookManager with default hooks for TGB linkproppred task.

RecipeRegistry

Registry recipe for managing all pre-defined recipe in the form of Callable object.

This class allows you to register your custom recipes perform frequently-used pre-experiment setup used. One common frequently-used pre-experiment setup is set up HookManager for TGB linkpropred, which is provided by TGM team. Users are welcome to define their own recipe. User-defined recipe need to be registered with RecipeRegistry to be able to build. Please see tutorial for further information

Raises: UndefinedRecipe: If build is call on recipe that is not defined or registered.

build_tgb_link_pred(
    dataset_name: str, train_dg: DGraph
) -> HookManager

Build ready-to-use HookManager with default hooks for TGB linkproppred task.

Parameters:

  • dataset_name (str) –

    The name of the TGB dataset (e.g. 'tgbl-wiki')

  • train_dg (DGraph) –

    The training graph, used to setup the NegativeEdgeSamplerHook for training

Returns:

  • HookManager

    HookManager with registered keys: ['train', 'val', 'test']

Source code in tgm/hooks/recipe.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@RecipeRegistry.register(RECIPE_TGB_LINK_PRED)
def build_tgb_link_pred(dataset_name: str, train_dg: DGraph) -> HookManager:
    """Build ready-to-use HookManager with default hooks for TGB linkproppred task.

    Args:
        dataset_name (str): The name of the TGB dataset (e.g. 'tgbl-wiki')
        train_dg (DGraph): The training graph, used to setup the `NegativeEdgeSamplerHook` for training

    Returns:
        HookManager with registered keys: ['train', 'val', 'test']
    """
    dst = train_dg.edge_dst
    hm = HookManager(keys=['train', 'val', 'test'])
    hm.register(
        'train',
        RandomNegativeEdgeSamplerHook(low=int(dst.min()), high=int(dst.max())),
    )
    hm.register('val', TGBNegativeEdgeSamplerHook(dataset_name, split_mode='val'))
    hm.register('test', TGBNegativeEdgeSamplerHook(dataset_name, split_mode='test'))

    logger.info(
        "Built %s HookManager recipe for dataset '%s'. Hooks registered: %s",
        RECIPE_TGB_LINK_PRED,
        dataset_name,
        list(hm.keys),
    )
    logger.debug('HookManager: %s', hook_manager)

    return hm