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

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:
  • wikidata_ids (Sequence[str]) – the Wikidata IDs

  • 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 WikidataImageCache.get_image_paths()

  • kwargs – additional keyword-based parameters passed to VisualRepresentation.__init__()

Raises:

ValueError – if the max_id does not match the number of Wikidata IDs

Methods Summary

from_dataset(dataset, **kwargs)

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, **kwargs) WikidataVisualRepresentation[source]

Prepare representations from a dataset.

Parameters:
Returns:

the representation

Raises:

TypeError – if the triples factory does not provide labels

Return type:

WikidataVisualRepresentation

classmethod from_triples_factory(triples_factory: TriplesFactory, for_entities: bool = True, **kwargs) WikidataVisualRepresentation[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 WikidataVisualRepresentation.__init__()

Returns:

a visual representation from the triples factory

Return type:

WikidataVisualRepresentation