MiriUll commited on
Commit
5373044
·
1 Parent(s): b46a7db

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -7
README.md CHANGED
@@ -5,12 +5,16 @@ tags:
5
  - feature-extraction
6
  - sentence-similarity
7
  - transformers
8
-
 
 
 
9
  ---
10
 
11
- # {MODEL_NAME}
12
 
13
- This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
 
14
 
15
  <!--- Describe your model here -->
16
 
@@ -28,12 +32,31 @@ Then you can use the model like this:
28
  from sentence_transformers import SentenceTransformer
29
  sentences = ["This is an example sentence", "Each sentence is converted"]
30
 
31
- model = SentenceTransformer('{MODEL_NAME}')
32
  embeddings = model.encode(sentences)
33
  print(embeddings)
34
  ```
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
 
 
 
 
 
37
 
38
  ## Usage (HuggingFace Transformers)
39
  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.
@@ -54,8 +77,8 @@ def mean_pooling(model_output, attention_mask):
54
  sentences = ['This is an example sentence', 'Each sentence is converted']
55
 
56
  # Load model from HuggingFace Hub
57
- tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
58
- model = AutoModel.from_pretrained('{MODEL_NAME}')
59
 
60
  # Tokenize sentences
61
  encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
@@ -126,4 +149,5 @@ SentenceTransformer(
126
 
127
  ## Citing & Authors
128
 
129
- <!--- Describe where people can find more information -->
 
 
5
  - feature-extraction
6
  - sentence-similarity
7
  - transformers
8
+ - negation
9
+ license: mit
10
+ language:
11
+ - en
12
  ---
13
 
14
+ # NegMPNet
15
 
16
+ This is a negation-aware version of (all-mpnet-base-v2)[https://huggingface.co/sentence-transformers/all-mpnet-base-v2].
17
+ It is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
18
 
19
  <!--- Describe your model here -->
20
 
 
32
  from sentence_transformers import SentenceTransformer
33
  sentences = ["This is an example sentence", "Each sentence is converted"]
34
 
35
+ model = SentenceTransformer("tum-nlp/NegMPNet")
36
  embeddings = model.encode(sentences)
37
  print(embeddings)
38
  ```
39
 
40
+ ## Negation-awareness
41
+ This model has a better sensitivity towards negations compared to its base model. You can try it yourself:
42
+ ```python
43
+ from sentence_transformers import SentenceTransformer, util
44
+ import torch
45
+
46
+ base_model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2")
47
+ finetuned_model = SentenceTransformer("tum-nlp/NegMPNet")
48
+
49
+ def cos_similarities(references: list, candidates: list, model: SentenceTransformer, batch_size=8) -> torch.Tensor:
50
+ assert len(references) == len(candidates), "Number of references and candidates must be equal"
51
+ emb_ref = model.encode(references, batch_size=batch_size)
52
+ emb_cand = model.encode(candidates, batch_size=batch_size)
53
+ return torch.diag(util.cos_sim(emb_ref, emb_cand))
54
 
55
+ references = ["Ray charles is legendary.", "Ray charles is legendary"]
56
+ candidates = ["Ray charles is a legend.", "Ray charles isn't legendary."]
57
+ print(cos_similarities(references, candidates, base_model)) # prints tensor([0.9453, 0.8683]) -> no negation-awareness
58
+ print(cos_similarities(references, candidates, finetuned_model)) # prints tensor([0.9585, 0.4263]) -> sensitive to negation
59
+ ```
60
 
61
  ## Usage (HuggingFace Transformers)
62
  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.
 
77
  sentences = ['This is an example sentence', 'Each sentence is converted']
78
 
79
  # Load model from HuggingFace Hub
80
+ tokenizer = AutoTokenizer.from_pretrained("tum-nlp/NegMPNet")
81
+ model = AutoModel.from_pretrained("tum-nlp/NegMPNet")
82
 
83
  # Tokenize sentences
84
  encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
 
149
 
150
  ## Citing & Authors
151
 
152
+ If you use our model, please cite our INLG 2023 paper:
153
+ tba