Views
No views yet
1from sentence_transformers import SentenceTransformer
2
3# Load the model
4model = SentenceTransformer('datalyes/patembed-base_small')
5
6# Encode patent texts
7patent_texts = [
8 "A method for manufacturing semiconductor devices...",
9 "An apparatus for processing chemical compounds...",
10]
11embeddings = model.encode(patent_texts)
12
13# Compute similarity
14from sentence_transformers import util
15similarity = util.cos_sim(embeddings[0], embeddings[1])
16print(f"Similarity: {similarity.item():.4f}")1from transformers import AutoTokenizer, AutoModel
2import torch
3import torch.nn.functional as F
4
5# Load model and tokenizer
6tokenizer = AutoTokenizer.from_pretrained('datalyes/patembed-base_small')
7model = AutoModel.from_pretrained('datalyes/patembed-base_small')
8
9def mean_pooling(model_output, attention_mask):
10 token_embeddings = model_output[0]
11 input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
12 return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
13
14# Tokenize and encode
15texts = ["A method for manufacturing semiconductor devices..."]
16encoded = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')
17
18with torch.no_grad():
19 model_output = model(**encoded)
20 embeddings = mean_pooling(model_output, encoded['attention_mask'])
21 embeddings = F.normalize(embeddings, p=2, dim=1)1from sentence_transformers import SentenceTransformer, util
2
3model = SentenceTransformer('datalyes/patembed-base_small')
4
5# Query patent
6query = "Method for reducing power consumption in mobile devices"
7
8# Candidate patents
9candidates = [
10 "A power management system for portable electronic devices...",
11 "Chemical composition for battery manufacturing...",
12 "Method for wireless data transmission in mobile networks...",
13]
14
15# Encode and retrieve
16query_emb = model.encode(query)
17candidate_embs = model.encode(candidates)
18
19# Compute similarities
20scores = util.cos_sim(query_emb, candidate_embs)[0]
21
22# Get ranked results
23results = [(candidates[i], scores[i].item()) for i in range(len(candidates))]
24results.sort(key=lambda x: x[1], reverse=True)
25
26for patent, score in results:
27 print(f"Score: {score:.4f} - {patent[:100]}...")1@misc{ayaou2025patentebcomprehensivebenchmarkmodel,
2 title={PatenTEB: A Comprehensive Benchmark and Model Family for Patent Text Embedding},
3 author={Iliass Ayaou and Denis Cavallucci},
4 year={2025},
5 eprint={2510.22264},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2510.22264}
9}