:py:mod:`helper_classes` ======================== .. py:module:: helper_classes Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: helper_classes.DatasetTriple helper_classes.HeadAndRelationBatchLoader helper_classes.Reproduce Attributes ~~~~~~~~~~ .. autoapisummary:: helper_classes.seed .. py:data:: seed :value: 1 .. py:class:: DatasetTriple(data) Bases: :py:obj:`torch.utils.data.Dataset` An abstract class representing a :class:`Dataset`. All datasets that represent a map from keys to data samples should subclass it. All subclasses should overwrite :meth:`__getitem__`, supporting fetching a data sample for a given key. Subclasses could also optionally overwrite :meth:`__len__`, which is expected to return the size of the dataset by many :class:`~torch.utils.data.Sampler` implementations and the default options of :class:`~torch.utils.data.DataLoader`. .. note:: :class:`~torch.utils.data.DataLoader` by default constructs a index sampler that yields integral indices. To make it work with a map-style dataset with non-integral indices/keys, a custom sampler must be provided. .. py:method:: __len__() .. py:method:: __getitem__(idx) .. py:class:: HeadAndRelationBatchLoader(er_vocab, num_e) Bases: :py:obj:`torch.utils.data.Dataset` An abstract class representing a :class:`Dataset`. All datasets that represent a map from keys to data samples should subclass it. All subclasses should overwrite :meth:`__getitem__`, supporting fetching a data sample for a given key. Subclasses could also optionally overwrite :meth:`__len__`, which is expected to return the size of the dataset by many :class:`~torch.utils.data.Sampler` implementations and the default options of :class:`~torch.utils.data.DataLoader`. .. note:: :class:`~torch.utils.data.DataLoader` by default constructs a index sampler that yields integral indices. To make it work with a map-style dataset with non-integral indices/keys, a custom sampler must be provided. .. py:method:: __len__() .. py:method:: __getitem__(idx) .. py:class:: Reproduce .. py:method:: get_er_vocab(data) :staticmethod: .. py:method:: get_head_tail_vocab(data) :staticmethod: .. py:method:: get_data_idxs(data) .. py:method:: get_batch_1_to_N(er_vocab, er_vocab_pairs, idx) .. py:method:: evaluate_link_prediction(model, data, per_rel_flag_=True) .. py:method:: reproduce(model_path, data_path, model_name, per_rel_flag_=False, tail_pred_constraint=False, out_of_vocab_flag=False) .. py:method:: get_embeddings(model_path, data_path, model_name, per_rel_flag_=False, tail_pred_constraint=False, out_of_vocab_flag=False) .. py:method:: load_model(model_path, model_name) .. py:method:: reproduce_ensemble(model, data_path, per_rel_flag_=False, tail_pred_constraint=False, out_of_vocab_flag=False) per_rel_flag_ reports link prediction results per relations. flag_of_removal -> removes triples from testing split containing entities that did not occur during training at testing time. lp_based_on_head_and_tail_entity_rankings-> computes rank of missing entities based on head and tail entity.