Create README.md
#1
by
Jaemink
- opened
README.md
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SentiCSE
|
2 |
+
This is a roBERTa-base model trained on MR dataset and finetuned for sentiment analysis with the Sentiment tasks.
|
3 |
+
This model is suitable for English.
|
4 |
+
|
5 |
+
- Reference Paper: SentiCSE (Main of Coling 2024).
|
6 |
+
- Git Repo: https://github.com/nayohan/SentiCSE.
|
7 |
+
|
8 |
+
```python
|
9 |
+
import torch
|
10 |
+
from scipy.spatial.distance import cosine
|
11 |
+
from transformers import AutoTokenizer, AutoModel
|
12 |
+
|
13 |
+
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("DILAB-HYU/SentiCSE")
|
15 |
+
model = AutoModel.from_pretrained("DILAB-HYU/SentiCSE")
|
16 |
+
|
17 |
+
# Tokenize input texts
|
18 |
+
texts = [
|
19 |
+
"The food is delicious.",
|
20 |
+
"The atmosphere of the restaurant is good.",
|
21 |
+
"The food at the restaurant is devoid of flavor.",
|
22 |
+
"The restaurant lacks a good ambiance."
|
23 |
+
]
|
24 |
+
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
|
25 |
+
|
26 |
+
# Get the embeddings
|
27 |
+
with torch.no_grad():
|
28 |
+
embeddings = model(**inputs, output_hidden_states=True, return_dict=True).pooler_output
|
29 |
+
|
30 |
+
# Calculate cosine similarities
|
31 |
+
# Cosine similarities are in [-1, 1]. Higher means more similar
|
32 |
+
cosine_sim_0_1 = 1 - cosine(embeddings[0], embeddings[1])
|
33 |
+
cosine_sim_0_2 = 1 - cosine(embeddings[0], embeddings[2])
|
34 |
+
cosine_sim_0_3 = 1 - cosine(embeddings[0], embeddings[3])
|
35 |
+
|
36 |
+
print("Cosine similarity between \"%s\" and \"%s\" is: %.3f" % (texts[0], texts[1], cosine_sim_0_1))
|
37 |
+
print("Cosine similarity between \"%s\" and \"%s\" is: %.3f" % (texts[0], texts[2], cosine_sim_0_2))
|
38 |
+
print("Cosine similarity between \"%s\" and \"%s\" is: %.3f" % (texts[0], texts[3], cosine_sim_0_3))
|
39 |
+
|
40 |
+
```
|
41 |
+
Output:
|
42 |
+
|
43 |
+
```
|
44 |
+
Cosine similarity between "The food is delicious." and "The atmosphere of the restaurant is good." is: 0.942
|
45 |
+
Cosine similarity between "The food is delicious." and "The food at the restaurant is devoid of flavor." is: 0.703
|
46 |
+
Cosine similarity between "The food is delicious." and "The restaurant lacks a good ambiance." is: 0.656
|
47 |
+
```
|
48 |
+
|
49 |
+
## BibTeX entry and citation info
|
50 |
+
Please cite the reference paper if you use this model.
|
51 |
+
|
52 |
+
```
|
53 |
+
@article{2024SentiCES,
|
54 |
+
title={SentiCSE: A Sentiment-aware Contrastive Sentence Embedding Framework with Sentiment-guided Textual Similarity},
|
55 |
+
author={Kim, Jaemin and Na, Yohan and Kim, Kangmin and Lee, Sangrak and Chae, Dong-Kyu},
|
56 |
+
journal={Proceedings of the 30th International Conference on Computational Linguistics (COLING)},
|
57 |
+
year={2024},
|
58 |
+
}
|
59 |
+
```
|