Add Sentence Transformers usage

#2
by tomaarsen HF Staff - opened

Hello!

Starting with the next Sentence Transformers release (v6.0.0, planned for around the 18th), this checkpoint loads directly as a multi-vector (ColBERT-style late interaction) retriever through the new MultiVectorEncoder, alongside its existing PyLate usage. This PR adds a Sentence Transformers usage section to the model card and a multi-vector tag. The weights and the existing usage are untouched.

I'd love to feature this model in that release's blog post and documentation, especially once it loads without the revision pin (that is, once this PR is merged).

pip install "sentence-transformers @ git+https://github.com/huggingface/sentence-transformers.git"
from sentence_transformers import MultiVectorEncoder

model = MultiVectorEncoder("yjoonjang/colbert-ko-v1", revision="refs/pr/2")

query = "뢉은 ν–‰μ„±μœΌλ‘œ μ•Œλ €μ§„ 행성은 λ¬΄μ—‡μΈκ°€μš”?"
documents = [
    "κΈˆμ„±μ€ 크기와 근접성이 λΉ„μŠ·ν•˜μ—¬ μ’…μ’… μ§€κ΅¬μ˜ 쌍λ‘₯이라고 λΆˆλ¦°λ‹€.",
    "화성은 뢉은 겉λͺ¨μŠ΅ λ•Œλ¬Έμ— μ’…μ’… 뢉은 행성이라고 λΆˆλ¦°λ‹€.",
    "νƒœμ–‘κ³„μ—μ„œ κ°€μž₯ 큰 행성인 λͺ©μ„±μ—λŠ” λšœλ ·ν•œ 뢉은 반점이 μžˆλ‹€.",
    "고리둜 유λͺ…ν•œ 토성은 λ•Œλ•Œλ‘œ 뢉은 ν–‰μ„±μœΌλ‘œ μ˜€μΈλœλ‹€.",
]

query_embeddings = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings[0].shape)
# (32, 128) (19, 128)

# MaxSim late-interaction scoring (higher is more relevant)
scores = model.similarity(query_embeddings, document_embeddings)
print(scores)
# tensor([[10.9423, 22.7836, 19.7410, 22.4239]])
  • 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