Skip to content

Refactor Navigation and KGE Pipeline: Consistent Entity Naming, Enhanced Evaluation, and Robust Config Management#34

Open
HernandezEduin wants to merge 40 commits into
HalcyonSolutions:masterfrom
HernandezEduin:master
Open

Refactor Navigation and KGE Pipeline: Consistent Entity Naming, Enhanced Evaluation, and Robust Config Management#34
HernandezEduin wants to merge 40 commits into
HalcyonSolutions:masterfrom
HernandezEduin:master

Conversation

@HernandezEduin

Copy link
Copy Markdown
Contributor

Summary of Recent Changes

This pull request brings major refactors, feature enhancements, configuration changes, and bug fixes, particularly around navigation (supervised), KGE, and configuration management.

Highlights

  • Consistent Data Schema and Naming

    • Standardized the codebase to use source_ent/Source-Entity throughout, replacing query_ent/Query-Entity and the use of query_rel (relation) where possible. This impacts all data loading, supervision, and environment interfaces.
    • Function signatures, docstrings, and data processing logic updated for consistency and clarity across supervised and RL navigation.
  • Supervised Path Learning

    • Cleanup and removal of unnecessary variables and lines.
    • Added saving and loading functions for supervised navigation.
    • Config updates and added support for optional validation and model checkpointing.
    • Training, testing, and validation can now be performed independently.
    • Rollouts and noise injection added to training process.
    • Improved tqdm and metrics printing for easier monitoring.
    • Updated configs and sweeps for best performance (KinshipHinton, etc.).
    • Configurations added for reproducibility.
    • Fixed typo in filename: nav_superviced_training.pynav_supervised_training.py.
  • Knowledge Graph Embedding (KGE)

    • Moved KGE loading logic from training scripts to utility modules.
    • Log metrics and model saving functions refactored into utilities.
    • Embedded calculations and cleaning functions moved to appropriate utility files.
    • Best model loading for evaluation after training.
    • Added option for full graph training (navigability focus).
    • Improved config dump formatting for clarity.
  • Configuration Management

    • Major reorganization: RL navigation and KGE configs/sweeps moved to dedicated directories.
    • Timestamps corrected to consistent format.
    • Store action now used for certain CLI arguments.
    • Improved data splitting: now recognizes both dev and test splits if present, with fallback to random splits.
  • Reinforcement Learning and Environment

    • Added rollouts to supervised navigation and noise to agent position.
    • Added option for extrinsic reward calculation using FAISS or epsilon threshold.
    • Refactored rollout logic: now returns richer tensors, loss calculation done separately.
    • Environment now recycles answer ID tensors for efficiency.
    • Added and clarified metric variable names for disambiguation.
    • Improved initial state/embedding logic and batch handling for environment resets and RL episodes.
  • Metrics and Evaluation

    • Enhanced evaluation routines: now computes Hits@1, Hits@3, Hits@5, Hits@10, Hits@20, and Mean Reciprocal Rank (MRR) with improved rank calculation.
    • Logging and output updated to match new metrics.
    • Improved nearest-neighbor search and reshaping for batch evaluation.
  • General Refactoring

    • Refactored and consolidated code from exogenous/sun_models.py into utils modules for convenience, saving, cleaning, and metrics.
    • Removed obsolete triplet-saving and debugging code.
    • Improved variable naming, documentation, bugfixes for index/batch handling, and code maintainability throughout.

This PR introduces significant backend improvements, enhances reproducibility, and streamlines configuration and training workflows. It lays groundwork for future development and improves maintainability for navigation and embedding tasks.

Major affected files
  • README.md
  • mlm_training.py
  • nav_supervised_training.py
  • nav_training.py
  • multihopkg/data_utils.py
  • multihopkg/rl/graph_search/pn.py
  • multihopkg/utils_debug/dump_evals.py
  • multihopkg/vector_search.py

For the full commit list and details, see the commit history in the source repository.

Removing query_relation (as it is unused), saving of the triplets from
QA (as the benchmark already works), and renaming Query-Entity to
Source-Entity for a clearer understanding of the variable.
Modified all the necessary files to that are affected by the renaming of
Source-Entity and the removal of Query-Relation

Additional Correction for Single Hop Supervised
Forcing found cache to be the cached_metadata_path if the file exists.
The function `shift_through_cache_data` returns None regardless of the
situation, causing a forced recompute for each new instance.
Modified vector search to be able to take 3D tensors where the 2nd Dim
is the rollouts.
Modified code to be able to evaluate the performance in a similar
fashion to literature: ranks the rollouts according to their scores
(distance to closest entity in this case)

Correction
- Correcting the dimension in test_nav due to num_rollouts
- Using Path Log Prob to do the ranking of the Rollouts
- Adding back Mean Rank (MR) to have a better idea of the performance
Added an additional argument which controls the number of rollouts
during the EVALUATION phase. This is necessary for the benchmark metric
comparison. Keep at 100.
- Adding Comments of varible expected shape
- Changing Metric Variable Name from Distance to Ans Distance for
disambiguation with the distance provided by FAISS
- Replaced extracting answer_tensor and instead using the one already
calculated by the environment.
- Additionally returning tensors of shape (batch size, num_rollouts,
steps) from Rollout instead of (batch_size, steps)
- Calculating Reinforce Loss in a Separate Function
Added an optional variable in ITLGraphEnvironment for choosing whether
to use FAISS to calculate the closest entity and reward the agent if it
is the answer vs using episilon distance threshold with the answer
embedding. FAISS should provide a correct approach, but it slows down
the computation.
- Added Rollouts to the training during Supervised
- Added Noise to the current position of the Agent
- Modified the Query Rel for the Adapter to be the average relations emb
of the supervised path
The configurations (best) and sweeps for the supervised path learning
are added and moved to ./configs/supervised_path_learning/ for
disambiguation.
Moving KGE training related configs and sweeps into
./configs/embedding_training.
Moving RL Navigation Configs and Sweeps to ./configs/navigation/
Adding indent to make it more presentable
Adding a parameter to allow trainining on the full graph (assumming KGE
completion is no longer the task, instead of it the task is
navigability).
Before the beginning of training, a pretrained model can be loaded if
`--checkpoint_path` is a valid path and contains the dir with the model.
Addionally, validation is now optional in the training.
Moving the functions from exogenous/sun_models to utils/convenience for
a better location:
- calculate_entity_range
- calculate_entity_centroid
- get_entity_embeddings_from_indices
Modifying affected files accordingly:
- mlm_training.py
- nav_supervised_training.py
- nav_training.py
- multihopkg/rl/graph_search/pn.py
Moving and renaming the following functions:
- save_configs -> save_train_configs
- save_model -> save_kge_model
- update_best_model -> update_best_kge_model
from exogenous/sun_model.py to utils/saving.py

Updated the following affected files:
- kge_train.py
- nav_supervised_training.py
Moving the following functions from exogenous/sun_models to
utils/cleaning
- clean_up_checkpoints
- clean_up_folder
Affected files
- kge_train.py
Removing unnecessary variables and lines in supervised path learning
algorithm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant