🚀 syubraj/sentence_similarity_nepali
這是一個 sentence-transformers 模型,它可以將句子和段落映射到一個 768 維的密集向量空間,可用於聚類或語義搜索等任務。
🚀 快速開始
安裝依賴
如果你已經安裝了 sentence-transformers,使用這個模型會很方便:
pip install -U sentence-transformers
使用示例
基礎用法
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('syubraj/sentence_similarity_nepali')
embeddings = model.encode(sentences)
print(embeddings)
高級用法
在沒有安裝 sentence-transformers 的情況下,你可以按以下方式使用該模型:首先,將輸入數據傳入 Transformer 模型,然後對上下文詞嵌入應用正確的池化操作。
from transformers import AutoTokenizer, AutoModel
import torch
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
sentences = ['This is an example sentence', 'Each sentence is converted']
tokenizer = AutoTokenizer.from_pretrained('syubraj/sentence_similarity_nepali')
model = AutoModel.from_pretrained('syubraj/sentence_similarity_nepali')
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 詳細文檔
評估結果
有關此模型的自動評估,請參閱 Sentence Embeddings Benchmark:https://seb.sbert.net
訓練參數
該模型使用以下參數進行訓練:
數據加載器:
torch.utils.data.dataloader.DataLoader
,長度為 288,參數如下:
{'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
損失函數:
sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss
fit()
方法的參數:
{
"epochs": 8,
"evaluation_steps": 1000,
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 231,
"weight_decay": 0.01
}
完整模型架構
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)
引用與作者
更多信息
你可以在 Github 上找到更多信息。