Noinstruct Small Embedding V0
模型概述
該模型通過非對稱池化策略優化檢索性能,查詢使用均值池化,句子/文檔嵌入使用[CLS]表示,相比GIST-small-Embedding-v0具有更優的檢索表現。
模型特點
非對稱池化策略
查詢使用均值池化,句子/文檔嵌入使用[CLS]表示,優化不同場景下的嵌入效果
指令編碼獨立性
保持對任意指令編碼的獨立性,符合當前檢索任務嵌入模型的流行範式
檢索性能優化
相比GIST-small-Embedding-v0模型,在檢索任務上表現更優
模型能力
文本嵌入生成
語義相似度計算
信息檢索
使用案例
信息檢索
文檔檢索
根據查詢語句從大量文檔中檢索相關內容
相比GIST-small-Embedding-v0具有更高的檢索準確率
語義相似度計算
計算不同文本之間的語義相似度
通過非對稱池化策略獲得更準確的相似度評分
🚀 NoInstruct small Embedding v0
NoInstruct Embedding:非對稱池化就是你所需要的一切
該模型與 avsolatorio/GIST-small-Embedding-v0 模型相比,在檢索性能上有所提升。
GIST
系列模型在檢索任務上的表現存在不足。我們提出了一種方法,在對查詢進行編碼時,該方法在保持不依賴於為檢索任務的嵌入模型設計任意指令(這是當前嵌入模型中的一種流行範式)的同時,提高了檢索性能。
該模型的技術細節將很快公佈。
🚀 快速開始
環境依賴
該項目依賴於 transformers
、torch
庫,你可以使用以下命令進行安裝:
pip install transformers torch
代碼運行
以下是使用該模型的示例代碼:
from typing import Union
import torch
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("avsolatorio/NoInstruct-small-Embedding-v0")
tokenizer = AutoTokenizer.from_pretrained("avsolatorio/NoInstruct-small-Embedding-v0")
def get_embedding(text: Union[str, list[str]], mode: str = "sentence"):
model.eval()
assert mode in ("query", "sentence"), f"mode={mode} was passed but only `query` and `sentence` are the supported modes."
if isinstance(text, str):
text = [text]
inp = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
output = model(**inp)
# The model is optimized to use the mean pooling for queries,
# while the sentence / document embedding uses the [CLS] representation.
if mode == "query":
vectors = output.last_hidden_state * inp["attention_mask"].unsqueeze(2)
vectors = vectors.sum(dim=1) / inp["attention_mask"].sum(dim=-1).view(-1, 1)
else:
vectors = output.last_hidden_state[:, 0, :]
return vectors
texts = [
"Illustration of the REaLTabFormer model. The left block shows the non-relational tabular data model using GPT-2 with a causal LM head. In contrast, the right block shows how a relational dataset's child table is modeled using a sequence-to-sequence (Seq2Seq) model. The Seq2Seq model uses the observations in the parent table to condition the generation of the observations in the child table. The trained GPT-2 model on the parent table, with weights frozen, is also used as the encoder in the Seq2Seq model.",
"Predicting human mobility holds significant practical value, with applications ranging from enhancing disaster risk planning to simulating epidemic spread. In this paper, we present the GeoFormer, a decoder-only transformer model adapted from the GPT architecture to forecast human mobility.",
"As the economies of Southeast Asia continue adopting digital technologies, policy makers increasingly ask how to prepare the workforce for emerging labor demands. However, little is known about the skills that workers need to adapt to these changes"
]
# Compute embeddings
embeddings = get_embedding(texts, mode="sentence")
# Compute cosine-similarity for each pair of sentences
scores = F.cosine_similarity(embeddings.unsqueeze(1), embeddings.unsqueeze(0), dim=-1)
print(scores.cpu().numpy())
# Test the retrieval performance.
query = get_embedding("Which sentence talks about concept on jobs?", mode="query")
scores = F.cosine_similarity(query, embeddings, dim=-1)
print(scores.cpu().numpy())
後續支持
後續將支持 Sentence Transformers
庫。
💻 使用示例
基礎用法
以下代碼展示瞭如何使用該模型獲取文本嵌入,並計算文本之間的餘弦相似度:
from typing import Union
import torch
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("avsolatorio/NoInstruct-small-Embedding-v0")
tokenizer = AutoTokenizer.from_pretrained("avsolatorio/NoInstruct-small-Embedding-v0")
def get_embedding(text: Union[str, list[str]], mode: str = "sentence"):
model.eval()
assert mode in ("query", "sentence"), f"mode={mode} was passed but only `query` and `sentence` are the supported modes."
if isinstance(text, str):
text = [text]
inp = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
output = model(**inp)
# The model is optimized to use the mean pooling for queries,
# while the sentence / document embedding uses the [CLS] representation.
if mode == "query":
vectors = output.last_hidden_state * inp["attention_mask"].unsqueeze(2)
vectors = vectors.sum(dim=1) / inp["attention_mask"].sum(dim=-1).view(-1, 1)
else:
vectors = output.last_hidden_state[:, 0, :]
return vectors
texts = [
"Illustration of the REaLTabFormer model. The left block shows the non-relational tabular data model using GPT-2 with a causal LM head. In contrast, the right block shows how a relational dataset's child table is modeled using a sequence-to-sequence (Seq2Seq) model. The Seq2Seq model uses the observations in the parent table to condition the generation of the observations in the child table. The trained GPT-2 model on the parent table, with weights frozen, is also used as the encoder in the Seq2Seq model.",
"Predicting human mobility holds significant practical value, with applications ranging from enhancing disaster risk planning to simulating epidemic spread. In this paper, we present the GeoFormer, a decoder-only transformer model adapted from the GPT architecture to forecast human mobility.",
"As the economies of Southeast Asia continue adopting digital technologies, policy makers increasingly ask how to prepare the workforce for emerging labor demands. However, little is known about the skills that workers need to adapt to these changes"
]
# Compute embeddings
embeddings = get_embedding(texts, mode="sentence")
# Compute cosine-similarity for each pair of sentences
scores = F.cosine_similarity(embeddings.unsqueeze(1), embeddings.unsqueeze(0), dim=-1)
print(scores.cpu().numpy())
# Test the retrieval performance.
query = get_embedding("Which sentence talks about concept on jobs?", mode="query")
scores = F.cosine_similarity(query, embeddings, dim=-1)
print(scores.cpu().numpy())
高級用法
你可以根據實際需求修改 get_embedding
函數的參數,以適應不同的應用場景。例如,你可以修改 mode
參數來指定是獲取查詢嵌入還是句子嵌入:
# 以下代碼展示瞭如何獲取查詢嵌入
query_embedding = get_embedding("這是一個查詢示例", mode="query")
📚 詳細文檔
模型性能
該模型在多個數據集上進行了測試,以下是部分任務和數據集的性能指標:
任務類型 | 數據集名稱 | 準確率 | 平均精度 | F1值 |
---|---|---|---|---|
分類 | MTEB AmazonCounterfactualClassification (en) | 75.76119402985074 | 39.03628777559392 | 69.85860402259618 |
分類 | MTEB AmazonPolarityClassification | 93.29920000000001 | 90.03479490717608 | 93.28554395248467 |
分類 | MTEB AmazonReviewsClassification (en) | 49.98799999999999 | - | 49.46151232451642 |
... | ... | ... | ... | ... |
注意事項
- 該模型在查詢時使用均值池化,而句子/文檔嵌入使用
[CLS]
表示。 - 技術細節將很快公佈,請持續關注。
使用建議
- 在使用該模型時,確保輸入的文本長度在模型的最大輸入長度範圍內,避免因文本過長而導致的截斷問題。
- 對於不同的任務,可以根據實際情況調整
get_embedding
函數的mode
參數,以獲取更合適的嵌入表示。
📄 許可證
該項目採用 MIT 許可證。
Jina Embeddings V3
Jina Embeddings V3 是一個多語言句子嵌入模型,支持超過100種語言,專注於句子相似度和特徵提取任務。
文本嵌入
Transformers 支持多種語言

J
jinaai
3.7M
911
Ms Marco MiniLM L6 V2
Apache-2.0
基於MS Marco段落排序任務訓練的交叉編碼器模型,用於信息檢索中的查詢-段落相關性評分
文本嵌入 英語
M
cross-encoder
2.5M
86
Opensearch Neural Sparse Encoding Doc V2 Distill
Apache-2.0
基於蒸餾技術的稀疏檢索模型,專為OpenSearch優化,支持免推理文檔編碼,在搜索相關性和效率上優於V1版本
文本嵌入
Transformers 英語

O
opensearch-project
1.8M
7
Sapbert From PubMedBERT Fulltext
Apache-2.0
基於PubMedBERT的生物醫學實體表徵模型,通過自對齊預訓練優化語義關係捕捉
文本嵌入 英語
S
cambridgeltl
1.7M
49
Gte Large
MIT
GTE-Large 是一個強大的句子轉換器模型,專注於句子相似度和文本嵌入任務,在多個基準測試中表現出色。
文本嵌入 英語
G
thenlper
1.5M
278
Gte Base En V1.5
Apache-2.0
GTE-base-en-v1.5 是一個英文句子轉換器模型,專注於句子相似度任務,在多個文本嵌入基準測試中表現優異。
文本嵌入
Transformers 支持多種語言

G
Alibaba-NLP
1.5M
63
Gte Multilingual Base
Apache-2.0
GTE Multilingual Base 是一個多語言的句子嵌入模型,支持超過50種語言,適用於句子相似度計算等任務。
文本嵌入
Transformers 支持多種語言

G
Alibaba-NLP
1.2M
246
Polybert
polyBERT是一個化學語言模型,旨在實現完全由機器驅動的超快聚合物信息學。它將PSMILES字符串映射為600維密集指紋,以數值形式表示聚合物化學結構。
文本嵌入
Transformers

P
kuelumbus
1.0M
5
Bert Base Turkish Cased Mean Nli Stsb Tr
Apache-2.0
基於土耳其語BERT的句子嵌入模型,專為語義相似度任務優化
文本嵌入
Transformers 其他

B
emrecan
1.0M
40
GIST Small Embedding V0
MIT
基於BAAI/bge-small-en-v1.5模型微調的文本嵌入模型,通過MEDI數據集與MTEB分類任務數據集訓練,優化了檢索任務的查詢編碼能力。
文本嵌入
Safetensors 英語
G
avsolatorio
945.68k
29
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98