Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bge-m3 and Nomic 1.5 embeddings. #1182

Merged
merged 6 commits into from
Feb 14, 2024
Merged

Add bge-m3 and Nomic 1.5 embeddings. #1182

merged 6 commits into from
Feb 14, 2024

Conversation

nsthorat
Copy link
Contributor

@nsthorat nsthorat commented Feb 14, 2024

Fixes #1148

I added two versions of the Nomic 1.5 embeddings, which use matryoshka_dim dims, see: https://huggingface.co/nomic-ai/nomic-embed-text-v1.5

Demo: https://lilacai-nikhil-staging.hf.space/datasets#local/glue_ax_map&schemaCollapsed=false

@nsthorat nsthorat changed the title [not ready] Add bge-m3 embeddings. Add bge-m3 and Nomic 1.5 embeddings. Feb 14, 2024
@lilacai lilacai deleted a comment from review-notebook-app bot Feb 14, 2024
Copy link
Contributor

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

pyproject.toml Outdated
@@ -86,6 +89,7 @@ hdbscan = { version = "^0.8.33", optional = true }

[tool.poetry.extras]
all = [
"bge",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these have to be pypi packages, not aliases to groups

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

embeddings = self._model.encode(doc, convert_to_tensor=True)
# Extract the dense vectors from the model.
embeddings = F.layer_norm(embeddings, normalized_shape=(embeddings.shape[1],))
embeddings = embeddings[:, : self._matryoshka_dim]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are dimensions sorted by importance , like PCA ? curious why we can just take the last 256/512 dimensions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats the magic of matryoshka_dim.. it's not PCA exactly, afaict it's baked into the loss function: https://aniketrege.github.io/blog/2024/mrl/

@nsthorat nsthorat merged commit 5a36d26 into main Feb 14, 2024
4 checks passed
@nsthorat nsthorat deleted the nik-bge branch February 14, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can we add this open source multilingual embedding model?
2 participants