pyrdf2vec.walkers.weisfeiler_lehman module

class pyrdf2vec.walkers.weisfeiler_lehman.WLWalker(max_depth, max_walks=None, sampler=NOTHING, n_jobs=None, *, with_reverse=False, random_state=None, md5_bytes=8, wl_iterations=4)

Bases: pyrdf2vec.walkers.random.RandomWalker

Weisfeiler-Lehman walking strategy which relabels the nodes of the extracted random walks, providing additional information about the entity representations only when a maximum number of walks is not specified.

_inv_label_map

Stores the mapping of the inverse labels. Defaults to defaultdict.

_is_support_remote

True if the walking strategy can be used with a remote Knowledge Graph, False Otherwise. Defaults to False.

_label_map

Stores the mapping of the inverse labels. Defaults to defaultdict.

kg

The global KG used later on for the worker process. Defaults to None.

max_depth

The maximum depth of one walk.

max_walks

The maximum number of walks per entity. Defaults to None.

md5_bytes

The number of bytes to keep after hashing objects in MD5. Hasher allows to reduce the memory occupied by a long text. If md5_bytes is None, no hash is applied. Defaults to 8.

random_state

The random state to use to keep random determinism with the walking strategy. Defaults to None.

sampler

The sampling strategy. Defaults to UniformSampler.

wl_iterations

The Weisfeiler Lehman’s iteration. Defaults to 4.

extract(kg, entities, verbose=0)

Fits the provided sampling strategy and then calls the private _extract method that is implemented for each of the walking strategies.

Parameters
  • kg (KG) – The Knowledge Graph.

  • entities (List[str]) – The entities to be extracted from the Knowledge Graph.

  • verbose (int) – The verbosity level. 0: does not display anything; 1: display of the progress of extraction and training of walks; 2: debugging. Defaults to 0.

Return type

List[List[Tuple[str, ...]]]

Returns

The 2D matrix with its number of rows equal to the number of provided entities; number of column equal to the embedding size.