Instructions to use graziasveva93/sbert-adapt-ub with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use graziasveva93/sbert-adapt-ub with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("graziasveva93/sbert-adapt-ub") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Transformers
How to use graziasveva93/sbert-adapt-ub with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("graziasveva93/sbert-adapt-ub") model = AutoModel.from_pretrained("graziasveva93/sbert-adapt-ub") - Notebooks
- Google Colab
- Kaggle
Patent SBERT-adapt-ub
Patent SBERT-adapt-ub is a domain-adapted SentenceTransformer model for computing semantic similarity between patent texts. It maps patent abstracts, claims, and other patent-related text into a 384-dimensional dense vector space, enabling downstream tasks such as patent-to-patent similarity, semantic search, clustering, technology mapping, and patent landscaping.
The model is based on sentence-transformers/all-MiniLM-L6-v2 and was further adapted to the patent domain using a triplet-learning setup. It is designed to produce sentence-level and paragraph-level embeddings that are more suitable for patent similarity analysis than generic sentence embeddings.
Usage (Sentence-Transformers)
Using this model becomes easy when you have sentence-transformers installed:
pip install -U sentence-transformers
Then you can use the model like this:
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('graziasveva93/sbert-adapt-ub')
embeddings = model.encode(sentences)
print(embeddings)
Usage (HuggingFace Transformers)
Without sentence-transformers, you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
from transformers import AutoTokenizer, AutoModel
import torch
#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
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 we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
model = AutoModel.from_pretrained('{MODEL_NAME}')
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
Evaluation Results
Evaluation of this model is available in our paper: https://arxiv.org/pdf/2403.16630
Training
The model was trained using the SentenceTransformers framework with a triplet-learning objective.
DataLoader:
torch.utils.data.dataloader.DataLoader of length 13,456 with parameters:
{
"batch_size": 8,
"sampler": "torch.utils.data.sampler.RandomSampler",
"batch_sampler": "torch.utils.data.sampler.BatchSampler"
}
Loss:
sentence_transformers.losses.TripletLoss.TripletLoss with parameters:
{
"distance_metric": "TripletDistanceMetric.EUCLIDEAN",
"triplet_margin": 5
}
Parameters of the fit()-Method:
{
"epochs": 1,
"evaluation_steps": 1000,
"evaluator": "sentence_transformers.evaluation.TripletEvaluator.TripletEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 1345,
"weight_decay": 0.01
}
Full Model Architecture
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({
'word_embedding_dimension': 384,
'pooling_mode_cls_token': False,
'pooling_mode_mean_tokens': True,
'pooling_mode_max_tokens': False,
'pooling_mode_mean_sqrt_len_tokens': False
})
)
The model uses sentence-transformers/all-MiniLM-L6-v2 as the base model. The underlying transformer is a BERT-style architecture with hidden size 384, 6 hidden layers, 12 attention heads, and a maximum sequence length of 512 tokens.
Citing & Authors
If you use this model, please cite the associated paper:
@misc{ascione2024comparative,
title={A comparative analysis of embedding models for patent similarity},
author={Ascione, Grazia Sveva and Sterzi, Valerio},
year={2024},
eprint={2403.16630},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Authors
- Grazia Sveva Ascione, Bordeaux School of Economics, Université de Bordeaux
- Downloads last month
- 2
Model tree for graziasveva93/sbert-adapt-ub
Base model
nreimers/MiniLM-L6-H384-uncased