Update README.md
Browse files
README.md
CHANGED
|
@@ -33,67 +33,9 @@ pipeline_tag: sentence-similarity
|
|
| 33 |
---
|
| 34 |
|
| 35 |
|
| 36 |
-
#
|
| 37 |
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
| 38 |
|
| 39 |
-
## Usage (Sentence-Transformers)
|
| 40 |
-
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
| 41 |
-
|
| 42 |
-
```
|
| 43 |
-
pip install -U sentence-transformers
|
| 44 |
-
```
|
| 45 |
-
|
| 46 |
-
Then you can use the model like this:
|
| 47 |
-
```python
|
| 48 |
-
from sentence_transformers import SentenceTransformer
|
| 49 |
-
sentences = ["This is an example sentence", "Each sentence is converted"]
|
| 50 |
-
|
| 51 |
-
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 52 |
-
embeddings = model.encode(sentences)
|
| 53 |
-
print(embeddings)
|
| 54 |
-
```
|
| 55 |
-
|
| 56 |
-
## Usage (HuggingFace Transformers)
|
| 57 |
-
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.
|
| 58 |
-
|
| 59 |
-
```python
|
| 60 |
-
from transformers import AutoTokenizer, AutoModel
|
| 61 |
-
import torch
|
| 62 |
-
import torch.nn.functional as F
|
| 63 |
-
|
| 64 |
-
#Mean Pooling - Take attention mask into account for correct averaging
|
| 65 |
-
def mean_pooling(model_output, attention_mask):
|
| 66 |
-
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
| 67 |
-
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
| 68 |
-
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# Sentences we want sentence embeddings for
|
| 72 |
-
sentences = ['This is an example sentence', 'Each sentence is converted']
|
| 73 |
-
|
| 74 |
-
# Load model from HuggingFace Hub
|
| 75 |
-
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
|
| 76 |
-
model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
|
| 77 |
-
|
| 78 |
-
# Tokenize sentences
|
| 79 |
-
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
| 80 |
-
|
| 81 |
-
# Compute token embeddings
|
| 82 |
-
with torch.no_grad():
|
| 83 |
-
model_output = model(**encoded_input)
|
| 84 |
-
|
| 85 |
-
# Perform pooling
|
| 86 |
-
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
| 87 |
-
|
| 88 |
-
# Normalize embeddings
|
| 89 |
-
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
| 90 |
-
|
| 91 |
-
print("Sentence embeddings:")
|
| 92 |
-
print(sentence_embeddings)
|
| 93 |
-
```
|
| 94 |
-
|
| 95 |
-
------
|
| 96 |
-
|
| 97 |
## Background
|
| 98 |
|
| 99 |
The project aims to train sentence embedding models on very large sentence level datasets using a self-supervised
|
|
|
|
| 33 |
---
|
| 34 |
|
| 35 |
|
| 36 |
+
# Matisse6410/MNLP_M2_document_encoder
|
| 37 |
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
## Background
|
| 40 |
|
| 41 |
The project aims to train sentence embedding models on very large sentence level datasets using a self-supervised
|