MiniCPM-Embedding-Light incorporates bidirectional attention and Weighted Mean Pooling [1] in its architecture. The model underwent multi-stage training using approximately 260 million training examples, including open-source, synthetic, and proprietary data.
We also invite you to explore the UltraRAG series:
[1] Muennighoff, N. (2022). Sgpt: Gpt sentence embeddings for semantic search. arXiv preprint arXiv:2202.08904.
模型信息 Model Information
模型大小:440M
嵌入维度:1024
最大输入token数:8192
Model Size: 440M
Embedding Dimension: 1024
Max Input Tokens: 8192
使用方法 Usage
输入格式 Input Format
本模型支持 query 侧指令,格式如下:
MiniCPM-Embedding-Light supports query-side instructions in the following format:
Instruction: {{ instruction }} Query: {{ query }}
例如:
For example:
Instruction: 为这个医学问题检索相关回答。Query: 咽喉癌的成因是什么?
Instruction: Given a claim about climate change, retrieve documents that support or refute the claim. Query: However the warming trend is slower than most climate models have forecast.
也可以不提供指令,即采取如下格式:
MiniCPM-Embedding-Light also works in instruction-free mode in the following format:
Query: {{ query }}
环境要求 Requirements
transformers==4.37.2
示例脚本 Demo
Huggingface Transformers
from transformers import AutoModel
import torch
model_name = "OpenBMB/MiniCPM-Embedding-Light"
model = AutoModel.from_pretrained(model_name, trust_remote_code=True, torch_dtype=torch.float16).to("cuda")
# you can use flash_attention_2 for faster inference# model = AutoModel.from_pretrained(model_name, trust_remote_code=True, attn_implementation="flash_attention_2", torch_dtype=torch.float16).to("cuda")
model.eval()
queries = ["MiniCPM-o 2.6 A GPT-4o Level MLLM for Vision, Speech and Multimodal Live Streaming on Your Phone"]
passages = ["MiniCPM-o 2.6 is the latest and most capable model in the MiniCPM-o series. The model is built in an end-to-end fashion based on SigLip-400M, Whisper-medium-300M, ChatTTS-200M, and Qwen2.5-7B with a total of 8B parameters. It exhibits a significant performance improvement over MiniCPM-V 2.6, and introduces new features for real-time speech conversation and multimodal live streaming."]
embeddings_query_dense, embeddings_query_sparse = model.encode_query(queries, return_sparse_vectors=True)
embeddings_doc_dense, embeddings_doc_sparse = model.encode_corpus(passages, return_sparse_vectors=True)
dense_scores = (embeddings_query_dense @ embeddings_doc_dense.T)
print(dense_scores.tolist()) # [[0.6512398719787598]]print(model.compute_sparse_score_dicts(embeddings_query_sparse, embeddings_doc_sparse)) # [[0.27202296]]
dense_scores, sparse_scores, mixed_scores = model.compute_score(queries, passages)
print(dense_scores) # [[0.65123993]]print(sparse_scores) # [[0.27202296]]print(mixed_scores) # [[0.73284686]]
Sentence Transformers
import torch
from sentence_transformers import SentenceTransformer
model_name = "openbmb/MiniCPM-Embedding-Light"
model = SentenceTransformer(model_name, trust_remote_code=True, model_kwargs={"torch_dtype": torch.float16})
# you can use flash_attention_2 for faster inference# model = SentenceTransformer(model_name, trust_remote_code=True, model_kwargs={"attn_implementation": "flash_attention_2", "torch_dtype": torch.float16})
queries = ["中国的首都是哪里?"] # "What is the capital of China?"
passages = ["beijing", "shanghai"] # "北京", "上海"
INSTRUCTION = "Query: "
embeddings_query = model.encode(queries, prompt=INSTRUCTION)
embeddings_doc = model.encode(passages)
scores = (embeddings_query @ embeddings_doc.T)
print(scores.tolist()) # [[0.40356746315956116, 0.36183440685272217]]
from FlagEmbedding import FlagModel
model = FlagModel("OpenBMB/MiniCPM-Embedding-Light",
query_instruction_for_retrieval="Query: ",
pooling_method="mean",
trust_remote_code=True,
normalize_embeddings=True,
use_fp16=True)
# You can hack the __init__() method of the FlagEmbedding BaseEmbedder class to use flash_attention_2 for faster inference# self.model = AutoModel.from_pretrained(# model_name_or_path,# trust_remote_code=trust_remote_code,# cache_dir=cache_dir,# # torch_dtype=torch.float16, # we need to add this line to use fp16# # attn_implementation="flash_attention_2", # we need to add this line to use flash_attention_2# )
queries = ["中国的首都是哪里?"] # "What is the capital of China?"
passages = ["beijing", "shanghai"] # "北京", "上海"
embeddings_query = model.encode_queries(queries)
embeddings_doc = model.encode_corpus(passages)
scores = (embeddings_query @ embeddings_doc.T)
print(scores.tolist()) # [[0.40356746315956116, 0.36183440685272217]]
The models and weights of MiniCPM-Embedding-Light are completely free for academic research. After filling out a
"questionnaire"
for registration, MiniCPM-Embedding-Light weights are also available for free commercial use.
Runs of openbmb MiniCPM-Embedding-Light on huggingface.co
15.6K
Total runs
-343
24-hour runs
-389
3-day runs
-2.0K
7-day runs
6.5K
30-day runs
More Information About MiniCPM-Embedding-Light huggingface.co Model
MiniCPM-Embedding-Light huggingface.co
MiniCPM-Embedding-Light huggingface.co is an AI model on huggingface.co that provides MiniCPM-Embedding-Light's model effect (), which can be used instantly with this openbmb MiniCPM-Embedding-Light model. huggingface.co supports a free trial of the MiniCPM-Embedding-Light model, and also provides paid use of the MiniCPM-Embedding-Light. Support call MiniCPM-Embedding-Light model through api, including Node.js, Python, http.
MiniCPM-Embedding-Light huggingface.co is an online trial and call api platform, which integrates MiniCPM-Embedding-Light's modeling effects, including api services, and provides a free online trial of MiniCPM-Embedding-Light, you can try MiniCPM-Embedding-Light online for free by clicking the link below.
openbmb MiniCPM-Embedding-Light online free url in huggingface.co:
MiniCPM-Embedding-Light is an open source model from GitHub that offers a free installation service, and any user can find MiniCPM-Embedding-Light on GitHub to install. At the same time, huggingface.co provides the effect of MiniCPM-Embedding-Light install, users can directly use MiniCPM-Embedding-Light installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
MiniCPM-Embedding-Light install url in huggingface.co: