TriplesNumericLiteralsFactory
- class TriplesNumericLiteralsFactory(*, numeric_literals: ndarray, literals_to_id: Mapping[str, int], **kwargs)[source]
Bases:
TriplesFactory
Create multi-modal instances given the path to triples.
Initialize the multi-modal triples factory.
- Parameters:
numeric_literals (ndarray) – shape: (num_entities, num_literals) the numeric literals as a dense matrix.
literals_to_id (Mapping[str, int]) – a mapping from literal names to their IDs, i.e., the columns in the numeric_literals matrix.
kwargs – additional keyword-based parameters passed to
TriplesFactory.__init__()
.
Attributes Summary
Return the shape of the literals.
Methods Summary
clone_and_exchange_triples
(mapped_triples[, ...])Create a new triples factory sharing everything except the triples.
from_labeled_triples
(triples, *[, ...])Create a new triples factory from label-based triples.
from_path
(path, *[, path_to_numeric_triples])Create a new triples factory from triples stored in a file.
Return the numeric literals as a tensor.
Iterate over extra_repr components.
to_path_binary
(path)Save triples factory to path in (PyTorch's .pt) binary format.
Attributes Documentation
- literal_shape
Return the shape of the literals.
Methods Documentation
- clone_and_exchange_triples(mapped_triples: Tensor, extra_metadata: dict[str, Any] | None = None, keep_metadata: bool = True, create_inverse_triples: bool | None = None) TriplesNumericLiteralsFactory [source]
Create a new triples factory sharing everything except the triples.
Note
We use shallow copies.
- Parameters:
mapped_triples (Tensor) – The new mapped triples.
extra_metadata (dict[str, Any] | None) – Extra metadata to include in the new triples factory. If
keep_metadata
is true, the dictionaries will be unioned with precedence taken on keys fromextra_metadata
.keep_metadata (bool) – Pass the current factory’s metadata to the new triples factory
create_inverse_triples (bool | None) – Change inverse triple creation flag. If None, use flag from this factory.
- Returns:
The new factory.
- Return type:
- classmethod from_labeled_triples(triples: ndarray, *, numeric_triples: ndarray = None, **kwargs) TriplesNumericLiteralsFactory [source]
Create a new triples factory from label-based triples.
- Parameters:
triples (ndarray) – shape: (n, 3), dtype: str The label-based triples.
create_inverse_triples – Whether to create inverse triples.
entity_to_id – The mapping from entity labels to ID. If None, create a new one from the triples.
relation_to_id – The mapping from relations labels to ID. If None, create a new one from the triples.
compact_id – Whether to compact IDs such that the IDs are consecutive.
filter_out_candidate_inverse_relations – Whether to remove triples with relations with the inverse suffix.
metadata – Arbitrary key/value pairs to store as metadata
numeric_triples (ndarray)
- Returns:
A new triples factory.
- Return type:
- classmethod from_path(path: str | Path | TextIO, *, path_to_numeric_triples: None | str | Path | TextIO = None, **kwargs) TriplesNumericLiteralsFactory [source]
Create a new triples factory from triples stored in a file.
- Parameters:
path (str | Path | TextIO) – The path where the label-based triples are stored.
create_inverse_triples – Whether to create inverse triples.
entity_to_id – The mapping from entity labels to ID. If None, create a new one from the triples.
relation_to_id – The mapping from relations labels to ID. If None, create a new one from the triples.
compact_id – Whether to compact IDs such that the IDs are consecutive.
metadata – Arbitrary key/value pairs to store as metadata with the triples factory. Do not include
path
as a key because it is automatically taken from thepath
kwarg to this function.load_triples_kwargs – Optional keyword arguments to pass to
load_triples()
. Could include thedelimiter
or acolumn_remapping
.kwargs – additional keyword-based parameters, which are ignored.
- Returns:
A new triples factory.
- Return type:
- get_numeric_literals_tensor() Tensor [source]
Return the numeric literals as a tensor.
- Return type: