vahidthegreat
commited on
Commit
•
c760c4d
1
Parent(s):
937277a
Update README.md
Browse files
README.md
CHANGED
@@ -44,14 +44,14 @@ tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
|
44 |
|
45 |
# Load and apply LoRA weights
|
46 |
lora_model = PeftModel.from_pretrained(base_model, "vahidthegreat/StanceAware-SBERT")
|
47 |
-
|
48 |
|
49 |
|
50 |
|
51 |
## Using the Model with the Siamese Network Class
|
52 |
|
53 |
The following custom `SiameseNetworkMPNet` class leverages the model for stance detection tasks. It pools embeddings and normalizes them for similarity calculations. This is for the sake of replicability of our exact results. But the model would work without this as well.
|
54 |
-
|
55 |
import torch
|
56 |
import torch.nn as nn
|
57 |
import torch.nn.functional as F
|
@@ -78,13 +78,13 @@ class SiameseNetworkMPNet(nn.Module):
|
|
78 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
79 |
|
80 |
return embeddings
|
81 |
-
|
82 |
|
83 |
|
84 |
## Example Usage for Two-Sentence Similarity
|
85 |
The following example shows how to use the Siamese network with two input sentences, calculating cosine similarity to compare stances.
|
86 |
|
87 |
-
|
88 |
from sklearn.metrics.pairwise import cosine_similarity
|
89 |
|
90 |
def two_sentence_similarity(model, tokenizer, text1, text2):
|
@@ -108,7 +108,7 @@ text2 = "I hate pineapple on pizza"
|
|
108 |
# Instantiate model and tokenizer
|
109 |
stance_model = SiameseNetworkMPNet(model_name=base_model_name, tokenizer=tokenizer)
|
110 |
two_sentence_similarity(stance_model, tokenizer, text1, text2)
|
111 |
-
|
112 |
|
113 |
|
114 |
|
@@ -139,4 +139,5 @@ If you use this model in your research, please cite our paper:
|
|
139 |
month={November 14},
|
140 |
url={https://hdl.handle.net/20.500.12761/1851},
|
141 |
note={Available online at https://hdl.handle.net/20.500.12761/1851}
|
142 |
-
}
|
|
|
|
44 |
|
45 |
# Load and apply LoRA weights
|
46 |
lora_model = PeftModel.from_pretrained(base_model, "vahidthegreat/StanceAware-SBERT")
|
47 |
+
```
|
48 |
|
49 |
|
50 |
|
51 |
## Using the Model with the Siamese Network Class
|
52 |
|
53 |
The following custom `SiameseNetworkMPNet` class leverages the model for stance detection tasks. It pools embeddings and normalizes them for similarity calculations. This is for the sake of replicability of our exact results. But the model would work without this as well.
|
54 |
+
```
|
55 |
import torch
|
56 |
import torch.nn as nn
|
57 |
import torch.nn.functional as F
|
|
|
78 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
79 |
|
80 |
return embeddings
|
81 |
+
```
|
82 |
|
83 |
|
84 |
## Example Usage for Two-Sentence Similarity
|
85 |
The following example shows how to use the Siamese network with two input sentences, calculating cosine similarity to compare stances.
|
86 |
|
87 |
+
```
|
88 |
from sklearn.metrics.pairwise import cosine_similarity
|
89 |
|
90 |
def two_sentence_similarity(model, tokenizer, text1, text2):
|
|
|
108 |
# Instantiate model and tokenizer
|
109 |
stance_model = SiameseNetworkMPNet(model_name=base_model_name, tokenizer=tokenizer)
|
110 |
two_sentence_similarity(stance_model, tokenizer, text1, text2)
|
111 |
+
```
|
112 |
|
113 |
|
114 |
|
|
|
139 |
month={November 14},
|
140 |
url={https://hdl.handle.net/20.500.12761/1851},
|
141 |
note={Available online at https://hdl.handle.net/20.500.12761/1851}
|
142 |
+
}
|
143 |
+
```
|