ConvE

class ConvE(triples_factory: ~pykeen.triples.triples_factory.CoreTriplesFactory, input_channels: int | None = None, output_channels: int = 32, embedding_height: int | None = None, embedding_width: int | None = None, kernel_height: int = 3, kernel_width: int = 3, input_dropout: float = 0.2, output_dropout: float = 0.3, feature_map_dropout: float = 0.2, embedding_dim: int = 200, apply_batch_normalization: bool = True, entity_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_normal_>, relation_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_normal_>, **kwargs)[源代码]

基础类:ERModel

ConvE 的实现来自 [dettmers2018]

ConvE 使用一个 \(d\) 维嵌入和一个标量尾部偏差来表示实体。 关系由一个 \(d\) 维向量表示。 所有三个组件都可以存储为 Embedding

在这些表示的基础上,该模型使用ConvEInteraction来计算分数。

Example::
"""Example of using ConvE outside of the pipeline."""

# Step 1: Get triples
from pykeen.datasets import get_dataset

dataset = get_dataset(dataset="nations", dataset_kwargs=dict(create_inverse_triples=True))

# Step 2: Configure the model
from pykeen.models import ConvE

model = ConvE(
    triples_factory=dataset.training,
    embedding_dim=200,
    input_channels=1,
    output_channels=32,
    embedding_height=10,
    embedding_width=20,
    kernel_height=3,
    kernel_width=3,
    input_dropout=0.2,
    feature_map_dropout=0.2,
    output_dropout=0.3,
)

# Step 3: Configure the loop
from torch.optim import Adam

optimizer = Adam(params=model.get_grad_params())
from pykeen.training import LCWATrainingLoop

training_loop = LCWATrainingLoop(model=model, optimizer=optimizer)

# Step 4: Train
losses = training_loop.train(triples_factory=dataset.training, num_epochs=5, batch_size=256)

# Step 5: Evaluate the model
from pykeen.evaluation import RankBasedEvaluator

evaluator = RankBasedEvaluator()
metric_result = evaluator.evaluate(
    model=model,
    mapped_triples=dataset.testing.mapped_triples,
    additional_filter_triples=dataset.training.mapped_triples,
    batch_size=8192,
)

初始化模型。

属性摘要

hpo_default

优化模型超参数的默认策略

loss_default_kwargs

默认损失函数类的默认参数

属性文档

Parameters:
hpo_default: ClassVar[Mapping[str, Any]] = {'feature_map_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'input_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'output_channels': {'high': 6, 'low': 4, 'scale': 'power_two', 'type': <class 'int'>}, 'output_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}}

优化模型超参数的默认策略

loss_default_kwargs: ClassVar[Mapping[str, Any]] = {}

默认损失函数类的默认参数