TestDataLoader¶
- class pybind11_ke.data.TestDataLoader(in_path: str = './', ent_file: str = 'entity2id.txt', rel_file: str = 'relation2id.txt', train_file: str = 'train2id.txt', valid_file: str = 'valid2id.txt', test_file: str = 'test2id.txt', sampling_mode: str = 'link_test', type_constrain: bool = True)[源代码]¶
主要从底层 C++ 模块获得数据用于 KGE 模型的评估。
例子:
from pybind11_ke.config import Tester from pybind11_ke.data import TestDataLoader # dataloader for test test_dataloader = TestDataLoader('../../benchmarks/FB15K/') # test the model tester = Tester(model = transe, data_loader = test_dataloader, use_gpu = True, device = 'cuda:1')
- __init__(in_path: str = './', ent_file: str = 'entity2id.txt', rel_file: str = 'relation2id.txt', train_file: str = 'train2id.txt', valid_file: str = 'valid2id.txt', test_file: str = 'test2id.txt', sampling_mode: str = 'link_test', type_constrain: bool = True)[源代码]¶
创建 TestDataLoader 对象。
- 参数:
in_path (str) – 数据集目录
ent_file (str) – entity2id.txt
rel_file (str) – relation2id.txt
train_file (str) – train2id.txt
valid_file (str) – valid2id.txt
test_file (str) – test2id.txt
sampling_mode (str) – 数据采样模式,
link_test和link_valid分别表示为链接预测进行测试集和验证集的负采样type_constrain (bool) – 是否用 type_constrain.txt 进行负采样
- __iter__() TestDataSampler[源代码]¶
迭代器函数
iterator.__iter__(), 根据sampling_mode决定是评估验证集还是测试集。
- __weakref__¶
list of weak references to the object (if defined)
- sampling() dict[str, Union[numpy.ndarray, str]][源代码]¶
为链接预测进行采样数据,为给定的正三元组,用所有实体依次替换头尾实体得到 2 *
ent_tol个三元组。