dicee.config ============ .. py:module:: dicee.config .. autoapi-nested-parse:: Configuration module for DICE embeddings. Provides the Namespace class with default configuration values for training knowledge graph embedding models. Classes ------- .. autoapisummary:: dicee.config.Namespace Module Contents --------------- .. py:class:: Namespace(**kwargs) Bases: :py:obj:`argparse.Namespace` Extended Namespace with default KGE training configuration. Provides sensible defaults for all training parameters while allowing easy customization through command-line arguments or direct assignment. .. py:attribute:: dataset_dir :type: Optional[str] :value: None The path of a folder containing train.txt, and/or valid.txt and/or test.txt .. py:attribute:: save_embeddings_as_csv :type: bool :value: False Embeddings of entities and relations are stored into CSV files to facilitate easy usage. .. py:attribute:: storage_path :type: str :value: 'Experiments' A directory named with time of execution under --storage_path that contains related data about embeddings. .. py:attribute:: path_to_store_single_run :type: Optional[str] :value: None A single directory created that contains related data about embeddings. .. py:attribute:: path_single_kg :value: None Path of a file corresponding to the input knowledge graph .. py:attribute:: sparql_endpoint :value: None An endpoint of a triple store. .. py:attribute:: ultra_checkpoint :type: Optional[str] :value: None .. py:attribute:: ultra_dim :type: int :value: 64 .. py:attribute:: ultra_num_layers :type: int :value: 6 .. py:attribute:: ultra_query_batch_size :type: int :value: 8 .. py:attribute:: trix_checkpoint :type: Optional[str] :value: None .. py:attribute:: trix_dim :type: int :value: 32 .. py:attribute:: trix_query_batch_size :type: int :value: 8 .. py:attribute:: flock_checkpoint :type: Optional[str] :value: None .. py:attribute:: flock_dim :type: int :value: 64 .. py:attribute:: flock_walk_num :type: int :value: 128 .. py:attribute:: flock_walk_len :type: int :value: 128 .. py:attribute:: flock_refinements :type: int :value: 6 .. py:attribute:: flock_num_layers :type: int :value: 1 .. py:attribute:: flock_attention_heads :type: int :value: 4 .. py:attribute:: flock_test_samples :type: int :value: 1 .. py:attribute:: flock_query_batch_size :type: int :value: 1 .. py:attribute:: flock_seed :type: Optional[int] :value: None .. py:attribute:: flock_prefetch_walks :type: bool :value: True .. py:attribute:: flock_compact_state :type: bool :value: True .. py:attribute:: flock_compile_sampler :type: bool :value: True .. py:attribute:: flock_pack_walks :type: bool :value: True .. py:attribute:: graph_inference_backend :type: str :value: 'auto' .. py:attribute:: graph_relation_cache_mb :type: int :value: 64 .. py:attribute:: graph_projection_cache_mb :type: int :value: 64 .. py:attribute:: graph_inference_compile :type: bool :value: False .. py:attribute:: grouped_negative_sampling :type: bool :value: False Sample a fixed-size group of negatives per positive (positive in column 0) via GroupedNegativeSamplingDataset instead of the flat NegSample layout. Requires scoring_technique='NegSample', entity prediction, no byte_pair_encoding. .. py:attribute:: strict_negative_sampling :type: bool :value: False With grouped/adversarial sampling, exclude every known-true triple from the negative candidate pool instead of sampling entities uniformly at random. .. py:attribute:: adversarial_temperature :type: Optional[float] :value: None Softmax temperature for self-adversarial weighting of negatives by their own score (dicee.models.sampled_loss.grouped_adversarial_bce); implies grouped sampling. 0 weights negatives uniformly; higher values weight high-scoring (harder) negatives more. None disables adversarial weighting. .. py:attribute:: model :type: str :value: 'Keci' KGE model .. py:attribute:: optim :type: str :value: 'Adam' Optimizer .. py:attribute:: embedding_dim :type: int :value: 64 Size of continuous vector representation of an entity/relation .. py:attribute:: num_epochs :type: int :value: 150 Number of pass over the training data .. py:attribute:: batch_size :type: int :value: 1024 Mini-batch size if it is None, an automatic batch finder technique applied .. py:attribute:: lr :type: float :value: 0.1 Learning rate .. py:attribute:: add_noise_rate :type: Optional[float] :value: None The ratio of added random triples into training dataset .. py:attribute:: gpus :value: None Number GPUs to be used during training .. py:attribute:: callbacks 10}} :type: Callbacks, e.g., {"PPE" :type: { "last_percent_to_consider" .. py:attribute:: backend :type: str :value: 'pandas' Backend to read, process, and index input knowledge graph. pandas, polars and rdflib available .. py:attribute:: separator :type: str :value: '\\s+' separator for extracting head, relation and tail from a triple .. py:attribute:: trainer :type: str :value: 'torchCPUTrainer' 'torchCPUTrainer' (CPU/single GPU), 'PL' (PyTorch Lightning multi-GPU), 'torchDDP' (native DDP), 'TP' (Tensor Parallelism - implements 'Multiple Run Ensemble Learning with Low-Dimensional Knowledge Graph Embeddings') :type: Trainer for knowledge graph embedding model. Options .. py:attribute:: scoring_technique :type: str :value: 'KvsAll' Scoring technique for knowledge graph embedding models .. py:attribute:: neg_ratio :type: int :value: 0 Negative ratio for a true triple in NegSample training_technique .. py:attribute:: weight_decay :type: float :value: 0.0 Weight decay for all trainable params .. py:attribute:: normalization :type: str :value: 'None' LayerNorm, BatchNorm1d, or None .. py:attribute:: init_param :type: Optional[str] :value: None xavier_normal or None .. py:attribute:: gradient_accumulation_steps :type: int :value: 0 Not tested e .. py:attribute:: num_folds_for_cv :type: int :value: 0 Number of folds for CV .. py:attribute:: eval_model :type: str :value: 'train_val_test' ["None", "train", "train_val", "train_val_test", "test"] :type: Evaluate trained model choices .. py:attribute:: eval_tie_policy :type: str :value: 'sort' sort (legacy), optimistic, random, or pessimistic. :type: Prediction ties .. py:attribute:: eval_tie_seed :type: Optional[int] :value: None Independent random tie seed; None uses random_seed. .. py:attribute:: save_model_at_every_epoch :type: Optional[int] :value: None Not tested .. py:attribute:: label_smoothing_rate :type: float :value: 0.0 Smooths dataset targets toward a uniform distribution at construction time (dicee/dataset_classes/_label_based.py, _negative_sampling.py), independent of loss_fn. Also passed as smoothness_ratio to loss_fn="LS"/"CombinedLSandLR"/ "AggregatedLSandLR" (see dicee/losses/custom_losses.py). .. py:attribute:: num_core :type: int :value: 0 Number of CPUs to be used in the mini-batch loading process .. py:attribute:: random_seed :type: int :value: 0 Random Seed .. py:attribute:: log_level :type: str :value: 'INFO' DEBUG, INFO, WARNING, ERROR, or CRITICAL. Dataset info, timing, and checkpoint messages are logged at INFO; set to WARNING or higher to silence them. :type: Logging verbosity .. py:attribute:: sample_triples_ratio :type: Optional[float] :value: None Read some triples that are uniformly at random sampled. Ratio being between 0 and 1 .. py:attribute:: read_only_few :type: Optional[int] :value: None Read only first few triples .. py:attribute:: pykeen_model_kwargs Additional keyword arguments for pykeen models .. py:attribute:: pl_trainer_kwargs Additional keyword arguments for the PyTorch Lightning Trainer .. py:attribute:: kernel_size :type: int :value: 3 Size of a square kernel in a convolution operation .. py:attribute:: num_of_output_channels :type: int :value: 32 Number of slices in the generated feature map by convolution. .. py:attribute:: margin :type: float :value: 4.0 Margin used by margin-based scoring functions (e.g. TransE, TransH, RotatE), and by torch.nn.MarginRankingLoss when scoring_technique='NegSampleMargin' .. py:attribute:: p :type: int :value: 0 P parameter of Clifford Embeddings .. py:attribute:: q :type: int :value: 1 Q parameter of Clifford Embeddings .. py:attribute:: input_dropout_rate :type: float :value: 0.0 Dropout rate on embeddings of input triples .. py:attribute:: hidden_dropout_rate :type: float :value: 0.0 Dropout rate on hidden representations of input triples .. py:attribute:: feature_map_dropout_rate :type: float :value: 0.0 Dropout rate on a feature map generated by a convolution operation .. py:attribute:: byte_pair_encoding :type: bool :value: False Byte pair encoding :type: WIP .. py:attribute:: adaptive_swa :type: bool :value: False Adaptive stochastic weight averaging .. py:attribute:: swa :type: bool :value: False Stochastic weight averaging .. py:attribute:: swag :type: bool :value: False Stochastic weight averaging - Gaussian .. py:attribute:: ema :type: bool :value: False Exponential Moving Average .. py:attribute:: twa :type: bool :value: False Trainable weight averaging .. py:attribute:: block_size :type: Optional[int] :value: None block size of LLM .. py:attribute:: continual_learning :type: Optional[str] :value: None Path of a pretrained model size of LLM .. py:attribute:: auto_batch_finding :type: bool :value: False A flag for using auto batch finding .. py:attribute:: eval_every_n_epochs :type: int :value: 0 Evaluate model every n epochs. If 0, no evaluation is applied. .. py:attribute:: save_every_n_epochs :type: bool :value: False Save model every n epochs. If True, save model at every epoch. .. py:attribute:: eval_at_epochs :type: Optional[list] :value: None List of epoch numbers at which to evaluate the model (e.g., 1 5 10). .. py:attribute:: n_epochs_eval_model :type: str :value: 'val_test' Evaluating link prediction performance on data splits while performing periodic evaluation. .. py:attribute:: adaptive_lr "cca"}' :type: Adaptive learning rate parameters, e.g., '{"scheduler_name" .. py:attribute:: swa_start_epoch :type: Optional[int] :value: None Epoch at which to start applying stochastic weight averaging. .. py:attribute:: swa_c_epochs :type: int :value: 1 Number of epochs to average over for SWA, SWAG, EMA, TWA. .. py:attribute:: loss_fn :type: Optional[str] :value: None Overrides the default entity/relation-prediction loss with one of the classes in dicee/losses/custom_losses.py: "LS", "LRLoss", "BCELoss", "WeightedBCELoss", "CombinedLSandLR", "AdaptiveLabelSmoothingLoss", "AdaptiveLabelRelaxationLoss", "ConfidenceBasedAdaptiveLabelRelaxationLoss", "CombinedAdaptiveLSandAdaptiveLR", "AggregatedLSandLR", "ACLS". None (default) keeps the framework's own BCEWithLogitsLoss/CrossEntropyLoss/MarginRankingLoss selection. See the docstring of each class for what it actually does and known caveats. .. py:attribute:: label_relaxation_alpha :type: float :value: 0.1 alpha for loss_fn="LRLoss"/"CombinedLSandLR"/"AggregatedLSandLR" (dicee.losses.custom_losses.LabelRelaxationLoss). .. py:attribute:: amwa :type: bool :value: False Adaptive Momentum Weight Averaging .. py:attribute:: amwa_start_epoch :type: int :value: 0 Epoch at which to start applying AMWA. .. py:attribute:: amwa_c_epochs :type: int :value: 1 Number of epochs between AMWA updates. .. py:attribute:: amwa_monitor :type: str :value: 'MRR' Validation metric used by AMWA to compare BaseNet and StableNet. .. py:attribute:: amwa_maximize :type: bool :value: True Whether larger values of amwa_monitor are better. .. py:attribute:: amwa_beta :type: Optional[float] :value: None Fixed beta for AMWA. If None, use adaptive beta_n. .. py:attribute:: amwa_beta_window :type: int :value: 10 Number of recent delta values used to estimate beta_n. .. py:attribute:: amwa_beta_init :type: float :value: 1.0 Initial beta used before enough delta history exists. .. py:attribute:: amwa_beta_floor :type: float :value: 1e-08 Numerical floor for beta_n. .. py:method:: __iter__()