Accenture / Accenture/AmpliGraph

Missing Mapping Dictionaries in Saved Model (CSV Training)

Open
#289 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

Description:

I am encountering an issue during inference with a model trained using a CSV file. The saved model does not include the necessary mapping dictionaries (entity_to_idx and relation_to_idx), which are typically stored in a DB file. This absence leads to a large number of triples being skipped during inference due to invalid keys.

Steps to Reproduce:

  1. Train an Ampligraph model (e.g., ComplEx, TransE) using data loaded from a CSV file.
  2. Save the trained model using ampligraph.utils.save_model().
  3. Load the saved model using ampligraph.utils.restore_model().
  4. Attempt to perform inference using the loaded model on a new set of triples.
  5. Observe a significant number of triples being skipped due to "invalid keys".
  6. Attempt to use ScoringBasedEmbeddingModel.get_invalid_keys() for filtering. Note that this function does not operate correctly without the mapping dictionaries.

Expected Behavior:

The saved model should include the mapping dictionaries (entity_to_idx and relation_to_idx) either within the model file itself or in a separate associated file (e.g., a DB file) to ensure proper inference on new data. Functions like get_invalid_keys() should be able to effectively identify and filter triples with unknown entities or relations using these saved mappings.

Actual Behavior:

The saved model does not contain the mapping dictionaries. Consequently, during inference, a large number of triples are flagged as containing invalid keys and skipped. The get_invalid_keys() function is ineffective in this scenario.

Additional Information:

  • Ampligraph Version: 2.1.0 (latest)
  • Training Data Format: CSV file
  • The ampligraph.utils.save_model() function does not appear to have a parameter to explicitly save the mapping dictionaries when training from CSV data.

Questions:

  1. What is the recommended way to ensure that the entity and relation mapping dictionaries are saved along with the model when training with CSV data?
  2. Is there a specific procedure or parameter that needs to be used during training or saving to include these mappings?
  3. If the DB file is not automatically saved, how can we manually save or access these dictionaries after training so they can be used for inference with the saved model?

Thank you for your time and assistance with this issue.

Reported by: Javier Martínez

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the CSV training and save_model()/restore_model() flow, then inspect how ScoringBasedEmbeddingModel.get_invalid_keys() obtains its mappings. Done means a restored model can access entity_to_idx and relation_to_idx and invalid-key filtering works for inference with new triples.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.