Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,133 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: en
|
3 |
+
pipeline_tag: sentence-similarity
|
4 |
+
tags:
|
5 |
+
- patent-similarity
|
6 |
+
- sentence-transformers
|
7 |
+
- feature-extraction
|
8 |
+
- sentence-similarity
|
9 |
+
- transformers
|
10 |
+
datasets:
|
11 |
+
- patents
|
12 |
license: apache-2.0
|
13 |
---
|
14 |
+
|
15 |
+
# paecter
|
16 |
+
|
17 |
+
This is a [sentence-transformers](https://www.SBERT.net) model: It can be used to generate 1024 dimensional dense vector for patent texts for downstream tasks like semantic search, prior art search, clustering, and patent landscaping.
|
18 |
+
|
19 |
+
<!--- Describe your model here -->
|
20 |
+
|
21 |
+
## Usage (Sentence-Transformers)
|
22 |
+
|
23 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
24 |
+
|
25 |
+
```
|
26 |
+
pip install -U sentence-transformers
|
27 |
+
```
|
28 |
+
|
29 |
+
Then you can use the model like this:
|
30 |
+
|
31 |
+
```python
|
32 |
+
from sentence_transformers import SentenceTransformer
|
33 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
34 |
+
|
35 |
+
model = SentenceTransformer('paecter')
|
36 |
+
embeddings = model.encode(sentences)
|
37 |
+
print(embeddings)
|
38 |
+
```
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
## Usage (HuggingFace Transformers)
|
43 |
+
Without [sentence-transformers](https://www.SBERT.net), 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.
|
44 |
+
|
45 |
+
```python
|
46 |
+
from transformers import AutoTokenizer, AutoModel
|
47 |
+
import torch
|
48 |
+
|
49 |
+
|
50 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
51 |
+
def mean_pooling(model_output, attention_mask):
|
52 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
53 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
54 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
55 |
+
|
56 |
+
|
57 |
+
# Sentences we want sentence embeddings for
|
58 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
59 |
+
|
60 |
+
# Load model from HuggingFace Hub
|
61 |
+
tokenizer = AutoTokenizer.from_pretrained('paecter')
|
62 |
+
model = AutoModel.from_pretrained('paecter')
|
63 |
+
|
64 |
+
# Tokenize sentences
|
65 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
66 |
+
|
67 |
+
# Compute token embeddings
|
68 |
+
with torch.no_grad():
|
69 |
+
model_output = model(**encoded_input)
|
70 |
+
|
71 |
+
# Perform pooling. In this case, mean pooling.
|
72 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
73 |
+
|
74 |
+
print("Sentence embeddings:")
|
75 |
+
print(sentence_embeddings)
|
76 |
+
```
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
## Evaluation Results
|
81 |
+
|
82 |
+
<!--- Describe how your model was evaluated -->
|
83 |
+
|
84 |
+
For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=paecter)
|
85 |
+
|
86 |
+
|
87 |
+
## Training
|
88 |
+
The model was trained with the parameters:
|
89 |
+
|
90 |
+
**DataLoader**:
|
91 |
+
|
92 |
+
`torch.utils.data.dataloader.DataLoader` of length 318750 with parameters:
|
93 |
+
```
|
94 |
+
{'batch_size': 4, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
|
95 |
+
```
|
96 |
+
|
97 |
+
**Loss**:
|
98 |
+
|
99 |
+
`sentence_transformers.losses.CustomTripletLoss.CustomTripletLoss` with parameters:
|
100 |
+
```
|
101 |
+
{'distance_metric': 'TripletDistanceMetric.EUCLIDEAN', 'triplet_margin': 1}
|
102 |
+
```
|
103 |
+
|
104 |
+
Parameters of the fit()-Method:
|
105 |
+
```
|
106 |
+
{
|
107 |
+
"epochs": 1,
|
108 |
+
"evaluation_steps": 4000,
|
109 |
+
"evaluator": "sentence_transformers.evaluation.TripletEvaluator.TripletEvaluator",
|
110 |
+
"max_grad_norm": 1,
|
111 |
+
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
|
112 |
+
"optimizer_params": {
|
113 |
+
"lr": 1e-05
|
114 |
+
},
|
115 |
+
"scheduler": "WarmupLinear",
|
116 |
+
"steps_per_epoch": null,
|
117 |
+
"warmup_steps": 31875.0,
|
118 |
+
"weight_decay": 0.01
|
119 |
+
}
|
120 |
+
```
|
121 |
+
|
122 |
+
|
123 |
+
## Full Model Architecture
|
124 |
+
```
|
125 |
+
SentenceTransformer(
|
126 |
+
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
|
127 |
+
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
|
128 |
+
)
|
129 |
+
```
|
130 |
+
|
131 |
+
## Citing & Authors
|
132 |
+
|
133 |
+
<!--- Describe where people can find more information -->
|