WikidataVisualRepresentation
- class WikidataVisualRepresentation(wikidata_ids: Sequence[str], max_id: int | None = None, image_kwargs: Mapping[str, Any] | None = None, **kwargs)[source]
Bases:
BackfillRepresentation
Visual representations obtained from Wikidata and encoded with a vision encoder.
If no image could be found for a certain Wikidata ID, a plain (trainable) embedding will be used instead.
Example usage
"""Example of using visual representations from Wikidata.""" from pykeen.datasets import get_dataset from pykeen.models import ERModel from pykeen.nn import WikidataVisualRepresentation from pykeen.pipeline import pipeline dataset = get_dataset(dataset="codexsmall") entity_representations = WikidataVisualRepresentation.from_dataset(dataset=dataset) result = pipeline( dataset=dataset, model=ERModel, model_kwargs=dict( interaction="distmult", entity_representations=entity_representations, relation_representation_kwargs=dict( shape=entity_representations.shape, ), ), )
Initialize the representation.
- Parameters:
max_id (int | None) – The total number of IDs. If provided, must match the length of
wikidata_ids
.image_kwargs (Mapping[str, Any] | None) – Keyword-based parameters passed to
pykeen.nn.vision.cache.WikidataImageCache.get_image_paths()
.kwargs – Additional keyword-based parameters passed to
pykeen.nn.vision.representation.VisualRepresentation
.
- Raises:
ValueError – If the max_id does not match the number of Wikidata IDs.
Methods Summary
from_dataset
(dataset[, for_entities])Prepare representations from a dataset.
from_triples_factory
(triples_factory[, ...])Prepare a visual representations for Wikidata entities from a triples factory.
Methods Documentation
- classmethod from_dataset(dataset: Dataset, for_entities: bool = True, **kwargs) Self [source]
Prepare representations from a dataset.
- Parameters:
dataset (Dataset) – The dataset; needs to have Wikidata IDs as entity names.
for_entities (bool) – Whether to create the initializer for entities (or relations).
kwargs – Additional keyword-based arguments passed to
pykeen.nn.vision.representation.WikidataVisualRepresentation
.
- Returns:
A visual representation from the training factory in the dataset.
- Raises:
TypeError – If the triples factory does not provide labels.
- Return type:
- classmethod from_triples_factory(triples_factory: TriplesFactory, for_entities: bool = True, **kwargs) Self [source]
Prepare a visual representations for Wikidata entities from a triples factory.
- Parameters:
triples_factory (TriplesFactory) – The triples factory.
for_entities (bool) – Whether to create the initializer for entities (or relations).
kwargs – Additional keyword-based arguments passed to
pykeen.nn.vision.representation.WikidataVisualRepresentation
.
- Returns:
A visual representation from the triples factory.
- Return type: