Spaces:
Runtime error
Runtime error
Update README
Browse files- README.md +48 -32
- sbert_cosine.py +21 -21
README.md
CHANGED
@@ -1,50 +1,66 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
- evaluate
|
7 |
-
- metric
|
8 |
-
description: "TODO: add a description here"
|
9 |
sdk: gradio
|
10 |
-
sdk_version: 3.
|
11 |
app_file: app.py
|
12 |
pinned: false
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
*Give a brief overview of this metric, including what task(s) it is usually used for, if any.*
|
21 |
|
22 |
-
##
|
23 |
-
*Give general statement of how to use the metric*
|
24 |
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
*List all input arguments in the format below*
|
29 |
-
- **input_field** *(type): Definition of input, with explanation if necessary. State any default value(s).*
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
*Give examples, preferrably with links to leaderboards or publications, to papers that have reported this metric, along with the values they have reported.*
|
39 |
|
40 |
-
|
41 |
-
*Give code examples of the metric being used. Try to include examples that clear up any potential ambiguity left from the metric description above. If possible, provide a range of examples that show both typical and atypical results, as well as examples where a variety of input parameters are passed.*
|
42 |
|
43 |
-
|
44 |
-
*Note any known limitations or biases that the metric has, with links and references if possible.*
|
45 |
|
46 |
## Citation
|
47 |
-
*Cite the source where this metric was introduced.*
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Test Sbert Cosine
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: purple
|
|
|
|
|
|
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
tags:
|
11 |
+
- evaluate
|
12 |
+
- metric
|
13 |
+
description: >-
|
14 |
+
Sbert cosine is a metric to score the semantic similarity of text generation tasks
|
15 |
+
|
16 |
+
This is not the official implementation of cosine similarity using SBERT
|
17 |
|
18 |
+
See the project at https://www.sbert.net/ for more information.
|
19 |
+
---
|
20 |
|
21 |
+
# Metric Card for SbertCosine
|
|
|
22 |
|
23 |
+
## Metric description
|
|
|
24 |
|
25 |
+
Sbert cosine is a metric to score the semantic similarity of text generation tasks
|
26 |
|
27 |
+
## How to use
|
|
|
|
|
28 |
|
29 |
+
```python
|
30 |
+
from evaluate import load
|
31 |
+
sbert_cosine = load("transZ/sbert_cosine")
|
32 |
+
predictions = ["hello there", "general kenobi"]
|
33 |
+
references = ["hello there", "general kenobi"]
|
34 |
+
results = sbert_cosine.compute(predictions=predictions, references=references, lang="en")
|
35 |
+
```
|
36 |
|
37 |
+
## Output values
|
38 |
|
39 |
+
Sbert cosine outputs a dictionary with the following values:
|
40 |
|
41 |
+
`score`: Range from 0.0 to 1.0
|
|
|
42 |
|
43 |
+
## Limitations and bias
|
|
|
44 |
|
45 |
+
The [official repo](https://github.com/UKPLab/sentence-transformers) showed that Sbert can capture the semantic of the sentence well
|
|
|
46 |
|
47 |
## Citation
|
|
|
48 |
|
49 |
+
```bibtex
|
50 |
+
@article{Reimers2019,
|
51 |
+
archivePrefix = {arXiv},
|
52 |
+
arxivId = {1908.10084},
|
53 |
+
author = {Reimers, Nils and Gurevych, Iryna},
|
54 |
+
doi = {10.18653/v1/d19-1410},
|
55 |
+
eprint = {1908.10084},
|
56 |
+
isbn = {9781950737901},
|
57 |
+
journal = {EMNLP-IJCNLP 2019 - 2019 Conference on Empirical Methods in Natural Language Processing and 9th International Joint Conference on Natural Language Processing, Proceedings of the Conference},
|
58 |
+
pages = {3982--3992},
|
59 |
+
title = {{Sentence-BERT: Sentence embeddings using siamese BERT-networks}},
|
60 |
+
year = {2019}
|
61 |
+
}
|
62 |
+
```
|
63 |
+
|
64 |
+
## Further References
|
65 |
+
- [Official website](https://www.sbert.net/)
|
66 |
+
|
sbert_cosine.py
CHANGED
@@ -11,52 +11,52 @@
|
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
-
"""
|
15 |
|
16 |
import evaluate
|
17 |
import datasets
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
# TODO: Add BibTeX citation
|
21 |
_CITATION = """\
|
22 |
-
@
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
"""
|
28 |
|
29 |
-
# TODO: Add description of the module here
|
30 |
_DESCRIPTION = """\
|
31 |
-
|
32 |
"""
|
33 |
|
34 |
|
35 |
-
# TODO: Add description of the arguments of the module here
|
36 |
_KWARGS_DESCRIPTION = """
|
37 |
-
Calculates how
|
38 |
Args:
|
39 |
predictions: list of predictions to score. Each predictions
|
40 |
should be a string with tokens separated by spaces.
|
41 |
references: list of reference for each prediction. Each
|
42 |
reference should be a string with tokens separated by spaces.
|
43 |
Returns:
|
44 |
-
|
45 |
-
another_score: description of the second score,
|
46 |
Examples:
|
47 |
Examples should be written in doctest format, and should illustrate how
|
48 |
to use the function.
|
49 |
|
50 |
-
>>>
|
51 |
-
>>> results = my_new_module.compute(references=[
|
52 |
>>> print(results)
|
53 |
-
{'
|
54 |
"""
|
55 |
|
56 |
-
# TODO: Define external resources urls if needed
|
57 |
-
BAD_WORDS_URL = "http://url/to/external/resource/bad_words.txt"
|
58 |
-
|
59 |
-
|
60 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
61 |
class sbert_cosine(evaluate.Metric):
|
62 |
"""TODO: Short description of my evaluation module."""
|
@@ -92,4 +92,4 @@ class sbert_cosine(evaluate.Metric):
|
|
92 |
accuracy = sum(i == j for i, j in zip(predictions, references)) / len(predictions)
|
93 |
return {
|
94 |
"accuracy": accuracy,
|
95 |
-
}
|
|
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
+
"""SBERT consime similarity metric."""
|
15 |
|
16 |
import evaluate
|
17 |
import datasets
|
18 |
+
import torch
|
19 |
+
import torch.nn as nn
|
20 |
|
|
|
|
|
21 |
_CITATION = """\
|
22 |
+
@article{Reimers2019,
|
23 |
+
archivePrefix = {arXiv},
|
24 |
+
arxivId = {1908.10084},
|
25 |
+
author = {Reimers, Nils and Gurevych, Iryna},
|
26 |
+
doi = {10.18653/v1/d19-1410},
|
27 |
+
eprint = {1908.10084},
|
28 |
+
isbn = {9781950737901},
|
29 |
+
journal = {EMNLP-IJCNLP 2019 - 2019 Conference on Empirical Methods in Natural Language Processing and 9th International Joint Conference on Natural Language Processing, Proceedings of the Conference},
|
30 |
+
pages = {3982--3992},
|
31 |
+
title = {{Sentence-BERT: Sentence embeddings using siamese BERT-networks}},
|
32 |
+
year = {2019}
|
33 |
}
|
34 |
"""
|
35 |
|
|
|
36 |
_DESCRIPTION = """\
|
37 |
+
Use SBERT to produce embedding and score the similarity by cosine similarity
|
38 |
"""
|
39 |
|
40 |
|
|
|
41 |
_KWARGS_DESCRIPTION = """
|
42 |
+
Calculates how semantic similarity are predictions given some references, using certain scores
|
43 |
Args:
|
44 |
predictions: list of predictions to score. Each predictions
|
45 |
should be a string with tokens separated by spaces.
|
46 |
references: list of reference for each prediction. Each
|
47 |
reference should be a string with tokens separated by spaces.
|
48 |
Returns:
|
49 |
+
score: description of the first score,
|
|
|
50 |
Examples:
|
51 |
Examples should be written in doctest format, and should illustrate how
|
52 |
to use the function.
|
53 |
|
54 |
+
>>> sbert_cosine = evaluate.load("transZ/sbert_cosine")
|
55 |
+
>>> results = my_new_module.compute(references=["Nice to meet you"], predictions=["It is my pleasure to meet you"])
|
56 |
>>> print(results)
|
57 |
+
{'score': 0.85}
|
58 |
"""
|
59 |
|
|
|
|
|
|
|
|
|
60 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
61 |
class sbert_cosine(evaluate.Metric):
|
62 |
"""TODO: Short description of my evaluation module."""
|
|
|
92 |
accuracy = sum(i == j for i, j in zip(predictions, references)) / len(predictions)
|
93 |
return {
|
94 |
"accuracy": accuracy,
|
95 |
+
}
|