--- title: SemF1 tags: - evaluate - metric sdk: gradio sdk_version: 3.19.1 app_file: app.py pinned: false description: >- SEM-F1 metric leverages the pre-trained contextual embeddings and evaluates the model generated semantic overlap summary with the reference overlap summary. It evaluates the semantic overlap summary at the sentence level and computes precision, recall and F1 scores. Refer to the paper `SEM-F1: an Automatic Way for Semantic Evaluation of Multi-Narrative Overlap Summaries at Scale` for more details. --- # Metric Card for Sem-F1 ## Metric Description Sem-F1 metric leverages the pre-trained contextual embeddings and evaluates the model generated semantic overlap summary with the reference overlap summary. It evaluates the semantic overlap summary at the sentence level and computes precision, recall and F1 scores. ## How to Use Before using this metric, you need to install the dependencies - ```bash pip install -U sentence-transformers scikit-learn nltk ``` Sem-F1 takes 2 mandatory arguments: - `predictions` - List of predictions. Format varies based on `tokenize_sentences` and `multi_references` flags. - `references`: List of references. Format varies based on `tokenize_sentences` and `multi_references` flags. ```python from evaluate import load predictions = [ "I go to School. You are stupid.", "I love adventure sports.", ] references = [ "I go to School. You are stupid.", "I love outdoor sports.", ] metric = load("nbansal/semf1") results = metric.compute(predictions=predictions, references=references) for score in results: print(f"Precision: {score.precision}, Recall: {score.recall}, F1: {score.f1}") ``` Sem-F1 also accepts multiple optional arguments: - `model_type (str)`: Model to use for encoding sentences. Options: ['pv1', 'stsb', 'use'] - `pv1` - [paraphrase-distilroberta-base-v1](https://huggingface.co/sentence-transformers/paraphrase-distilroberta-base-v1) - `stsb` - [stsb-roberta-large](https://huggingface.co/sentence-transformers/stsb-roberta-large) - `use` - [Universal Sentence Encoder](https://huggingface.co/sentence-transformers/use-cmlm-multilingual) (Default) Furthermore, you can use any model on Huggingface/SentenceTransformer that is supported by SentenceTransformer such as `all-mpnet-base-v2` or `roberta-base` - `tokenize_sentences (bool)`: Flag to indicate whether to tokenize the sentences in the input documents. Default: True. - `multi_references (bool)`: Flag to indicate whether multiple references are provided. Default: False. - `gpu (Union[bool, str, int, List[Union[str, int]]])`: Whether to use GPU, CPU or multiple-processes for computation. - `batch_size (int)`: Batch size for encoding. Default: 32. - `verbose (bool)`: Flag to indicate verbose output. Default: False. Refer to the inputs descriptions for more detailed usage as follows: ```python import evaluate metric = evaluate.load("nbansal/semf1") print(metric.inputs_description) ``` [//]: # (*List all input arguments in the format below*) [//]: # (- **input_field** *(type): Definition of input, with explanation if necessary. State any default value(s).*) ### Output Values List of `Scores` dataclass corresponding to each sample - - `precision: float`: Precision score, which ranges from 0.0 to 1.0. - `recall: List[float]`: Recall score corresponding to each reference - `f1: float`: F1 score (between precision and average recall). ## Extensions Currently, we have only implemented the 3 encoders* that we experimented with in our [paper](https://aclanthology.org/2022.emnlp-main.49/). Furthermore, you can use any model on Huggingface/SentenceTransformer that is supported by SentenceTransformer such as `all-mpnet-base-v2` or `roberta-base`. If you want to use your own encoder model, either make sure that is supported by `SentenceTransformer`. Or if it's a completely new architecture, it can easily with extended for more models by extending the `Encoder` base class (Refer to `encoder_models.py` file). `*` *In out paper, we used the Tensorflow [version](https://www.tensorflow.org/hub/tutorials/semantic_similarity_with_tf_hub_universal_encoder) of the USE model, however, in our current implementation, we used [PyTorch version](https://huggingface.co/sentence-transformers/use-cmlm-multilingual).* [//]: # (*Give examples, preferrably with links to leaderboards or publications, to papers that have reported this metric, along with the values they have reported.*) [//]: # (### Examples) [//]: # (*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.*) [//]: # (## Limitations and Bias) [//]: # (*Note any known limitations or biases that the metric has, with links and references if possible.*) ## Citation ```bibtex @inproceedings{bansal-etal-2022-sem, title = "{SEM}-F1: an Automatic Way for Semantic Evaluation of Multi-Narrative Overlap Summaries at Scale", author = "Bansal, Naman and Akter, Mousumi and Karmaker Santu, Shubhra Kanti", editor = "Goldberg, Yoav and Kozareva, Zornitsa and Zhang, Yue", booktitle = "Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing", month = dec, year = "2022", address = "Abu Dhabi, United Arab Emirates", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2022.emnlp-main.49", doi = "10.18653/v1/2022.emnlp-main.49", pages = "780--792", abstract = "Recent work has introduced an important yet relatively under-explored NLP task called Semantic Overlap Summarization (SOS) that entails generating a summary from multiple alternative narratives which conveys the common information provided by those narratives. Previous work also published a benchmark dataset for this task by collecting 2,925 alternative narrative pairs from the web and manually annotating 411 different reference summaries by engaging human annotators. In this paper, we exclusively focus on the automated evaluation of the SOS task using the benchmark dataset. More specifically, we first use the popular ROUGE metric from text-summarization literature and conduct a systematic study to evaluate the SOS task. Our experiments discover that ROUGE is not suitable for this novel task and therefore, we propose a new sentence-level precision-recall style automated evaluation metric, called SEM-F1 (Semantic F1). It is inspired by the benefits of the sentence-wise annotation technique using overlap labels reported by the previous work. Our experiments show that the proposed SEM-F1 metric yields a higher correlation with human judgment and higher inter-rater agreement compared to the ROUGE metric.", } ``` ## Further References - [Paper](https://aclanthology.org/2022.emnlp-main.49/) - [Presentation Slides](https://auburn.box.com/s/rs5p7sttaonbvljnq0i5tk7xxw0vonn3) - [Video](https://youtu.be/f8wrtOd-2tc)