Integrate with Sentence Transformers, restore training-time tokenization on newer transformers

#1
by tomaarsen HF Staff - opened

Hello @JUNJIE99 @kekekeke @xiaoxiaoshadiao and team!

As a heads up, this PR is AI-generated but human-reviewed.

Pull Request overview

  • Integrate WeMM-Embedding-9B with Sentence Transformers v5.7+ via modules.json and trust_remote_code
  • Restore the training-time tokenization on transformers newer than the pinned 5.2.0

Details

This is the sister PR of the https://huggingface.co/tencent/WeMM-Embedding-2B/discussions/1, with the same changes to transformers and Sentence Transformers integration, but for the 9B model. See that PR description for more details.

You can test the Sentence Transformers integration with the following snippet:

from sentence_transformers import SentenceTransformer

model_id = "tencent/WeMM-Embedding-9B"
model = SentenceTransformer(model_id, trust_remote_code=True)

queries = [
    "Which Llama 4 model variants are available?",
    "How is mapo tofu prepared?",
]
documents = [
    "Mapo tofu is a Sichuan dish of soft tofu simmered in a spicy, numbing sauce of chili bean paste and Sichuan peppercorn.",
    {
        "image": "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/llama4_hgf.png",
        "text": "Represent this image.",
    },
    {
        "video": "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/mapo_tofu.mp4",
        "text": "Represent this video.",
    },
]

query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# (2, 4096) (3, 4096)

similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.2153, 0.5843, 0.1221],
#         [0.7665, 0.2604, 0.5366]])

To try it before merging, load the PR revision:
SentenceTransformer(model_id, revision="refs/pr/1", trust_remote_code=True).

Happy to tweak anything you'd like changed. Please let me know if you have any questions or feedback!

  • Tom Aarsen
tomaarsen changed pull request status to open
Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment