Views
No views yet
sentencepiece
torch
transformers1import torch
2import torch.nn.functional as F
3from transformers import AutoModel, AutoTokenizer
4
5# You can download models from the Hugging Face Hub 🤗 as follows:
6tokenizer = AutoTokenizer.from_pretrained("pfnet/plamo-embedding-1b", trust_remote_code=True)
7model = AutoModel.from_pretrained("pfnet/plamo-embedding-1b", trust_remote_code=True)
8
9device = "cuda" if torch.cuda.is_available() else "cpu"
10model = model.to(device)
11
12query = "PLaMo-Embedding-1Bとは何ですか?"
13documents = [
14 "PLaMo-Embedding-1Bは、Preferred Networks, Inc. によって開発された日本語テキスト埋め込みモデルです。",
15 "最近は随分と暖かくなりましたね。"
16]
17
18with torch.inference_mode():
19 # For embedding query texts in information retrieval, please use the `encode_query` method.
20 # You also need to pass the `tokenizer`.
21 query_embedding = model.encode_query(query, tokenizer)
22 # For other texts/sentences, please use the `encode_document` method.
23 # Also, for applications other than information retrieval, please use the `encode_document` method.
24 document_embeddings = model.encode_document(documents, tokenizer)
25
26# The similarity between vectors obtained by inputting sentences into the model is high for similar sentences and low for dissimilar sentences.
27# This feature can be utilized for applications such as information retrieval.
28similarities = F.cosine_similarity(query_embedding, document_embeddings)
29print(similarities)
30# tensor([0.8812, 0.5533])encode_document and encode_query, texts exceeding the model's maximum context length of 4096 will be truncated. Be especially aware that for encode_query, a prefix is added internally, making the effective maximum context length slightly shorter.| Model | Avg. | Retrieval | STS | Classification | Reranking | Clustering | PairClassification |
|---|---|---|---|---|---|---|---|
| intfloat/multilingual-e5-large | 70.90 | 70.98 | 79.70 | 72.89 | 92.96 | 51.24 | 62.15 |
| pkshatech/GLuCoSE-base-ja-v2 | 72.23 | 73.36 | 82.96 | 74.21 | 93.01 | 48.65 | 62.37 |
| OpenAI/text-embedding-3-large | 74.05 | 74.48 | 82.52 | 77.58 | 93.58 | 53.32 | 62.35 |
| cl-nagoya/ruri-large-v2 | 74.55 | 76.34 | 83.17 | 77.18 | 93.21 | 52.14 | 62.27 |
| Sarashina-Embedding-v1-1B | 75.50 | 77.61 | 82.71 | 78.37 | 93.74 | 53.86 | 62.00 |
| PLaMo-Embedding-1B (This model) (*) | 76.10 | 79.94 | 83.14 | 77.20 | 93.57 | 53.47 | 62.37 |
@online{PLaMoEmbedding1B,
author = {Preferred Networks, Inc},
title = {PLaMo-Embedding-1B},
year = {2025},
url = {https://huggingface.co/pfnet/plamo-embedding-1b},
urldate = {2025-04-17}
}