Views
No views yet
1from llm2vec import LLM2Vec
2import torch
3
4# Load model
5model = LLM2Vec.from_pretrained(
6 "mayflowergmbh/smollm3-3b-embed-de",
7 device_map="auto",
8 torch_dtype=torch.bfloat16,
9)
10
11# Encode German texts
12texts = [
13 "Berlin ist die Hauptstadt von Deutschland.",
14 "Die deutsche Hauptstadt ist Berlin.",
15 "München ist eine Stadt in Bayern."
16]
17
18embeddings = model.encode(texts)
19
20# Calculate similarity
21from sklearn.metrics.pairwise import cosine_similarity
22similarity_matrix = cosine_similarity(embeddings)1from sentence_transformers import SentenceTransformer
2
3# Note: Requires adapter for sentence-transformers compatibility
4model = SentenceTransformer('path/to/smollm3-3b-embed-de')
5embeddings = model.encode(texts)1# Create document embeddings
2documents = [
3 "Die Katze sitzt auf dem Sofa.",
4 "Der Hund spielt im Garten.",
5 "Python ist eine Programmiersprache.",
6 "Machine Learning revolutioniert die Technologie."
7]
8doc_embeddings = model.encode(documents)
9
10# Search with a query
11query = "Haustiere und ihre Aktivitäten"
12query_embedding = model.encode([query])
13
14# Find most similar documents
15similarities = cosine_similarity(query_embedding, doc_embeddings)[0]
16top_indices = similarities.argsort()[-3:][::-1]
17
18for idx in top_indices:
19 print(f"Score: {similarities[idx]:.3f} - {documents[idx]}")Base Model: SmolLM3-3B
- Hidden Size: 2048
- Intermediate Size: 11008
- Number of Layers: 36
- Number of Attention Heads: 16
- Vocabulary Size: 128256
- Position Embeddings: 65536 (RoPE)1@misc{smollm3-embed-de,
2 title={SmolLM3-3B German Embeddings},
3 author={Johann-Peter Hartmann},
4 year={2025},
5 publisher={Mayflower GmbH},
6 url={https://huggingface.co/mayflowergmbh/smollm3-3b-embed-de}
7}
8
9@article{llm2vec,
10 title={LLM2Vec: Large Language Models Are Secretly Powerful Text Encoders},
11 author={Behnamghader, Parishad and others},
12 journal={arXiv preprint arXiv:2404.05961},
13 year={2024}
14}