Repository navigation
Add embedding_huggingface() engine for step_sentence_embeddings() - #361
Merged
Merged
Conversation
Engines that can pin a version of their model report it through a new engine_revision() generic. It is NA for the custom and ollama engines.
Runs a sentence-transformers model through reticulate, pinned to a model revision. The loaded model is cached for the session and never stored in the recipe. On macOS the engine sets the OpenMP environment variables that stop R from aborting when torch is loaded.
Earlier test files start Python through the spaCy skip helper, which made the helper warn instead of message. The check is now mockable, and both branches are tested.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an engine that runs a sentence-transformers model from the Hugging Face Hub through reticulate, so
step_sentence_embeddings()can use local models without a server. The model is pinned with a requiredrevisionand only the id and revision are stored in the recipe, never the loaded model.tidy()for the step gained arevisioncolumn to show it.On macOS, starting Python after recipes is loaded aborts R with an OpenMP error, because data.table and torch each load a
libomp. The engine setsKMP_DUPLICATE_LIB_OKandOMP_NUM_THREADSbefore Python starts when they are unset, and says so, which is the same workaround the text package uses. The cost is a single-threaded model.Test plan
Most tests mock the Python boundary. The one live test is skipped unless
sentence_transformerscan be imported. To run it, point reticulate at an environment that has it, for exampleRETICULATE_PYTHON=/path/to/venv/bin/python3, and rundevtools::test(filter = "sentence_embeddings-huggingface"). It downloadsall-MiniLM-L6-v2and checks the embeddings against values from sentence-transformers.Part of #303.