Update README.md
Browse files
README.md
CHANGED
@@ -778,7 +778,11 @@ pip install -U sentence-transformers
|
|
778 |
Then you can use the model like this:
|
779 |
```python
|
780 |
from sentence_transformers import SentenceTransformer
|
781 |
-
|
|
|
|
|
|
|
|
|
782 |
|
783 |
model = SentenceTransformer('dmlls/all-mpnet-base-v2-negation')
|
784 |
embeddings = model.encode(sentences)
|
@@ -793,7 +797,7 @@ from transformers import AutoTokenizer, AutoModel
|
|
793 |
import torch
|
794 |
import torch.nn.functional as F
|
795 |
|
796 |
-
#Mean Pooling - Take attention mask into account for correct averaging
|
797 |
def mean_pooling(model_output, attention_mask):
|
798 |
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
799 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
@@ -801,7 +805,10 @@ def mean_pooling(model_output, attention_mask):
|
|
801 |
|
802 |
|
803 |
# Sentences we want sentence embeddings for
|
804 |
-
sentences = [
|
|
|
|
|
|
|
805 |
|
806 |
# Load model from HuggingFace Hub
|
807 |
tokenizer = AutoTokenizer.from_pretrained('dmlls/all-mpnet-base-v2-negation')
|
@@ -820,7 +827,6 @@ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask']
|
|
820 |
# Normalize embeddings
|
821 |
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
822 |
|
823 |
-
print("Sentence embeddings:")
|
824 |
print(sentence_embeddings)
|
825 |
```
|
826 |
|
|
|
778 |
Then you can use the model like this:
|
779 |
```python
|
780 |
from sentence_transformers import SentenceTransformer
|
781 |
+
|
782 |
+
sentences = [
|
783 |
+
"I like rainy days because they make me feel relaxed.",
|
784 |
+
"I don't like rainy days because they don't make me feel relaxed."
|
785 |
+
]
|
786 |
|
787 |
model = SentenceTransformer('dmlls/all-mpnet-base-v2-negation')
|
788 |
embeddings = model.encode(sentences)
|
|
|
797 |
import torch
|
798 |
import torch.nn.functional as F
|
799 |
|
800 |
+
# Mean Pooling - Take attention mask into account for correct averaging
|
801 |
def mean_pooling(model_output, attention_mask):
|
802 |
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
803 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
|
|
805 |
|
806 |
|
807 |
# Sentences we want sentence embeddings for
|
808 |
+
sentences = [
|
809 |
+
"I like rainy days because they make me feel relaxed.",
|
810 |
+
"I don't like rainy days because they don't make me feel relaxed."
|
811 |
+
]
|
812 |
|
813 |
# Load model from HuggingFace Hub
|
814 |
tokenizer = AutoTokenizer.from_pretrained('dmlls/all-mpnet-base-v2-negation')
|
|
|
827 |
# Normalize embeddings
|
828 |
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
829 |
|
|
|
830 |
print(sentence_embeddings)
|
831 |
```
|
832 |
|