Feature Extraction
Transformers
Safetensors
sentence-transformers
Chinese
English
mteb
custom_code
Eval Results (legacy)
Instructions to use openbmb/MiniCPM-Embedding with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-Embedding with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="openbmb/MiniCPM-Embedding", trust_remote_code=True)# Load model directly from transformers import MiniCPM model = MiniCPM.from_pretrained("openbmb/MiniCPM-Embedding", trust_remote_code=True, dtype="auto") - sentence-transformers
How to use openbmb/MiniCPM-Embedding with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("openbmb/MiniCPM-Embedding", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -344,7 +344,6 @@ When running evaluation on BEIR and C-MTEB/Retrieval, we use instructions in `in
|
|
| 344 |
|
| 345 |
```
|
| 346 |
transformers==4.37.2
|
| 347 |
-
flash-attn>2.3.5
|
| 348 |
```
|
| 349 |
|
| 350 |
### 示例脚本 Demo
|
|
@@ -358,7 +357,9 @@ import torch.nn.functional as F
|
|
| 358 |
|
| 359 |
model_name = "openbmb/MiniCPM-Embedding"
|
| 360 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 361 |
-
model = AutoModel.from_pretrained(model_name, trust_remote_code=True,
|
|
|
|
|
|
|
| 362 |
model.eval()
|
| 363 |
|
| 364 |
# 由于在 `model.forward` 中缩放了最终隐层表示,此处的 mean pooling 实际上起到了 weighted mean pooling 的作用
|
|
@@ -402,7 +403,9 @@ import torch
|
|
| 402 |
from sentence_transformers import SentenceTransformer
|
| 403 |
|
| 404 |
model_name = "openbmb/MiniCPM-Embedding"
|
| 405 |
-
model = SentenceTransformer(model_name, trust_remote_code=True, model_kwargs={
|
|
|
|
|
|
|
| 406 |
|
| 407 |
queries = ["中国的首都是哪里?"]
|
| 408 |
passages = ["beijing", "shanghai"]
|
|
|
|
| 344 |
|
| 345 |
```
|
| 346 |
transformers==4.37.2
|
|
|
|
| 347 |
```
|
| 348 |
|
| 349 |
### 示例脚本 Demo
|
|
|
|
| 357 |
|
| 358 |
model_name = "openbmb/MiniCPM-Embedding"
|
| 359 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 360 |
+
model = AutoModel.from_pretrained(model_name, trust_remote_code=True, torch_dtype=torch.float16).to("cuda")
|
| 361 |
+
# You can also use the following line to enable the Flash Attention 2 implementation
|
| 362 |
+
# model = AutoModel.from_pretrained(model_name, trust_remote_code=True, attn_implementation="flash_attention_2", torch_dtype=torch.float16).to("cuda")
|
| 363 |
model.eval()
|
| 364 |
|
| 365 |
# 由于在 `model.forward` 中缩放了最终隐层表示,此处的 mean pooling 实际上起到了 weighted mean pooling 的作用
|
|
|
|
| 403 |
from sentence_transformers import SentenceTransformer
|
| 404 |
|
| 405 |
model_name = "openbmb/MiniCPM-Embedding"
|
| 406 |
+
model = SentenceTransformer(model_name, trust_remote_code=True, model_kwargs={ "torch_dtype": torch.float16})
|
| 407 |
+
# You can also use the following line to enable the Flash Attention 2 implementation
|
| 408 |
+
# model = SentenceTransformer(model_name, trust_remote_code=True, attn_implementation="flash_attention_2", model_kwargs={ "torch_dtype": torch.float16})
|
| 409 |
|
| 410 |
queries = ["中国的首都是哪里?"]
|
| 411 |
passages = ["beijing", "shanghai"]
|