Views
No views yet

| Dimension | Pearson Correlation | Spearman Correlation |
|---|---|---|
| 768d | 0.8894 | 0.8358 |
| 512d | 0.8959 | 0.8395 |
| 256d | 0.8979 | 0.8470 |
| 128d | 0.9182 | 0.8562 |
| 64d | 0.9066 | 0.8434 |
| Dimension | Pearson Correlation | Spearman Correlation |
|---|---|---|
| 768d | 0.8205 | 0.8258 |
| 512d | 0.8193 | 0.8227 |
| 256d | 0.8191 | 0.8246 |
| 128d | 0.8115 | 0.8183 |
| 64d | 0.7962 | 0.8077 |
1from sentence_transformers import SentenceTransformer
2
3# Load the model
4model = SentenceTransformer('AhmedZaky1/DIMI-embedding-v3-silma-sts-matryoshka', trust_remote_code=True)
5
6# Example sentences in Arabic and English
7sentences = [
8 "هذا مثال جميل للذكاء الاصطناعي", # Arabic
9 "This is a beautiful example of artificial intelligence", # English
10 "التعلم الآلي يغير العالم", # Arabic
11 "Machine learning is changing the world" # English
12]
13
14# Generate embeddings
15embeddings = model.encode(sentences)
16print(f"Embedding shape: {embeddings.shape}")
17
18# Calculate cosine similarity
19from sklearn.metrics.pairwise import cosine_similarity
20similarity_matrix = cosine_similarity(embeddings)
21print("Similarity matrix:")
22print(similarity_matrix)1# Use different embedding dimensions
2dimensions = [768, 512, 256, 128, 64]
3
4for dim in dimensions:
5 # Truncate embeddings to specific dimension
6 truncated_embeddings = embeddings[:, :dim]
7 print(f"Dimension {dim}: {truncated_embeddings.shape}")
8
9 # Calculate similarity with truncated embeddings
10 similarity = cosine_similarity(truncated_embeddings)
11 print(f"Average similarity at {dim}d: {similarity.mean():.4f}")1import numpy as np
2
3# Query and corpus
4query = "ما هو الذكاء الاصطناعي؟" # "What is artificial intelligence?"
5corpus = [
6 "الذكاء الاصطناعي هو محاكاة الذكاء البشري",
7 "Machine learning is a subset of AI",
8 "Deep learning uses neural networks",
9 "التعلم العميق يستخدم الشبكات العصبية"
10]
11
12# Encode query and corpus
13query_embedding = model.encode([query])
14corpus_embeddings = model.encode(corpus)
15
16# Find most similar documents
17similarities = cosine_similarity(query_embedding, corpus_embeddings)[0]
18top_indices = np.argsort(similarities)[::-1]
19
20print(f"Query: {query}")
21print("\nMost similar documents:")
22for i, idx in enumerate(top_indices[:3]):
23 print(f"{i+1}. {corpus[idx]} (similarity: {similarities[idx]:.4f})")1@misc{dimi-embedding-v3-2024,
2 title={DIMI-embedding-v3-silma-sts-matryoshka: Multilingual Sentence Embeddings for Arabic-English Semantic Similarity},
3 author={Ahmed Zaky},
4 year={2024},
5 publisher={Hugging Face},
6 url={https://huggingface.co/AhmedZaky1/DIMI-embedding-v3-silma-sts-matryoshka}
7}MIT License
Copyright (c) 2024 Ahmed Zaky
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.