michaelfeil / michaelfeil/infinity

Discrepancy in embeddings similarity between Infinity and SentenceTransformer / HF TEI

Open
#634 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.9k
Forks
206
PR merge metrics
No merged PRs in 30d

Description

I’ve observed significant discrepancies in the embeddings produced by **Infinity** compared to **SentenceTransformer** for the same model:
`sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2`.

#### Example

When computing the cosine similarity between the embeddings of the two inputs `mountains` and `joyeux noel`:

```python
def cosine_similarity(vector1, vector2):
"""
Calculate cosine similarity between two vectors
"""
dot_product = np.dot(vector1, vector2)
magnitude1 = np.linalg.norm(vector1)
magnitude2 = np.linalg.norm(vector2)

if magnitude1 == 0 or magnitude2 == 0:
return 0

return dot_product / (magnitude1 * magnitude2)
```

* **Infinity result:** `0.497474`
* **SentenceTransformer result:** `0.354079`

The similarity score from SentenceTransformer matches what is reported in both:

* Hugging Face UI
* Hugging Face Text Embeddings Inference (TEI)

This suggests Infinity is producing different embeddings than the expected reference implementations.

Image

### Reproduction

**Infinity (CPU):**

```bash
docker run --rm -it \
-p 8080:8080 \
michaelf34/infinity:latest-cpu \
v2 \
--engine optimum \
--port 8080 \
--model-id sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
```

**Hugging Face TEI (CPU):**

```bash
docker run -p 8081:80 -v $volume:/data --pull always \
ghcr.io/huggingface/text-embeddings-inference-cpu:1.8 \
--model-id sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
```

**SentenceTransformer code**

```python
model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
embeddings = model.encode([text1, text2])
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Infinity and Hugging Face TEI Docker commands with sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2, then compare their embeddings for “mountains” and “joyeux noel” with the SentenceTransformer example. Done means Infinity produces embeddings whose cosine similarity matches the SentenceTransformer, Hugging Face UI, and TEI results.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
backend, 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.