🚀 PatentSBERTa_V2
PatentSBERTa是一個基於深度自然語言處理(NLP)的混合模型,利用增強的SBERT進行專利距離計算和分類。它由奧爾堡大學商學院的AI: Growth - Lab開發。
該模型可將句子和段落映射到768維的密集向量空間,適用於聚類或語義搜索等任務。
- 論文鏈接:https://www.sciencedirect.com/science/article/abs/pii/S0040162524003329
- 代碼倉庫:https://github.com/AI - Growth - Lab/PatentSBERTa
🚀 快速開始
這是一個 sentence - transformers 模型,若要使用該模型,可按照以下步驟操作。
📦 安裝指南
若已安裝 sentence - transformers,使用此模型會很方便,可通過以下命令進行安裝:
pip install -U sentence-transformers
💻 使用示例
基礎用法(Sentence - Transformers)
安裝好 sentence - transformers
後,可按如下方式使用模型:
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('{MODEL_NAME}')
embeddings = model.encode(sentences)
print(embeddings)
高級用法(HuggingFace Transformers)
若未安裝 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('{MODEL_NAME}')
model = AutoModel.from_pretrained('{MODEL_NAME}')
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)
📚 詳細文檔
引用與作者
若引用此模型,請使用以下文獻:
Bekamiri, H., Hain, D. S., & Jurowetzki, R. (2024). PatentSBERTa: A deep NLP based hybrid model for patent distance and classification using augmented SBERT. Technological Forecasting and Social Change, 206, 123536.
評估結果
有關此模型的自動評估,請參閱 Sentence Embeddings Benchmark:https://seb.sbert.net
訓練參數
該模型的訓練參數如下:
數據加載器
torch.utils.data.dataloader.DataLoader
,長度為1658,參數如下:
{'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
損失函數
sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss
fit()
方法的參數:
{
"epochs": 4,
"evaluation_steps": 1000,
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 664,
"weight_decay": 0.01
}
完整模型架構
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: MPNetModel
(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})
)
模型標籤與示例
- 模型標籤:
- sentence - transformers
- feature - extraction
- sentence - similarity
- transformers
- 示例:
- 源句子:"A method for wireless charging using magnetic resonance"
- 對比句子:
- "Wireless power transfer through inductive coupling"
- "A new compound for pharmaceutical use in treating diabetes"
- "A method for data encryption in wireless communication"
- 示例標題:"Patent Similarity and Dissimilarity"