{"id":13810676,"url":"https://github.com/Huffon/sentence-similarity","last_synced_at":"2025-05-14T15:31:00.264Z","repository":{"id":130943963,"uuid":"219465349","full_name":"Huffon/sentence-similarity","owner":"Huffon","description":"This repository contains various ways to calculate sentence vector similarity using NLP models","archived":true,"fork":false,"pushed_at":"2020-04-14T06:03:17.000Z","size":220,"stargazers_count":199,"open_issues_count":1,"forks_count":34,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-14T00:52:06.067Z","etag":null,"topics":["natural-language-processing","sentence-embedding","sentence-similarity","vector-similarity"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Huffon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-04T09:37:35.000Z","updated_at":"2025-01-17T12:55:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"e5a9199a-e5cf-4ba1-b6d7-9fd62ee10fab","html_url":"https://github.com/Huffon/sentence-similarity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huffon%2Fsentence-similarity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huffon%2Fsentence-similarity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huffon%2Fsentence-similarity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huffon%2Fsentence-similarity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Huffon","download_url":"https://codeload.github.com/Huffon/sentence-similarity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171661,"owners_count":22026485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["natural-language-processing","sentence-embedding","sentence-similarity","vector-similarity"],"created_at":"2024-08-04T03:00:22.612Z","updated_at":"2025-05-14T15:31:00.256Z","avatar_url":"https://github.com/Huffon.png","language":"Python","funding_links":[],"categories":["See also"],"sub_categories":["Text matching"],"readme":"# Sentence Similarity Calculator\nThis repo contains various ways to calculate the similarity between source and target sentences. You can choose **the pre-trained models** you want to use such as _ELMo_, _BERT_ and _Universal Sentence Encoder (USE)_.\n\nAnd you can also choose **the method** to be used to get the similarity:\n\n    1. Cosine similarity\n    2. Manhattan distance\n    3. Euclidean distance\n    4. Angular distance\n    5. Inner product\n    6. TS-SS score\n    7. Pairwise-cosine similarity\n    8. Pairwise-cosine similarity + IDF\n    \nYou can experiment with (**The number of models**) x (**The number of methods**) combinations!\n    \n\u003cbr/\u003e\n\n## Installation\n\n- This project is developed under **conda** enviroment\n- After cloning this repository, you can simply install all the dependent libraries described in `requirements.txt` with `bash install.sh`\n\n```\nconda create -n sensim python=3.7\nconda activate sensim\ngit clone https://github.com/Huffon/sentence-similarity.git\ncd sentence-similarity\nbash install.sh\n```\n\n\u003cbr/\u003e\n\n## Usage\n- To **test** your own sentences, you should fill out [**corpus.txt**](corpus.txt) with sentences as below:\n\n```\nI ate an apple.\nI went to the Apple.\nI ate an orange.\n...\n```\n\n- Then, **choose** the **model** and **method** to be used to calculate the similarity between source and target sentences\n\n```\npython sensim.py\n    --model    MODEL_NAME  [use, bert, elmo]\n    --method   METHOD_NAME [cosine, manhattan, euclidean, inner,\n                            ts-ss, angular, pairwise, pairwise-idf]\n    --verbose  LOG_OPTION (bool)\n```\n\n\u003cbr/\u003e\n\n## Examples\n- In this section, you can see the example result of `sentence-similarity`\n- As you know, there is a no **silver-bullet** which can calculate **_perfect similarity_** between sentences\n- You should conduct various experiments with your dataset\n    - _**Caution**_: `TS-SS score` might not fit with **sentence** similarity task, since this method originally devised to calculate the similarity between long documents\n- **Result**:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"600\" height=\"500\" src=\"img/result.png\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n## References\n### Papers\n- [Universal Sentence Encoder](https://arxiv.org/abs/1803.11175)\n- [Deep contextualized word representations](https://arxiv.org/abs/1802.05365)\n- [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805)\n- [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084)\n- [BERTScore: Evaluating Text Generation with BERT](https://arxiv.org/abs/1904.09675)\n- [A Hybrid Geometric Approach for Measuring Similarity Level Among Documents and Document Clustering](https://ieeexplore.ieee.org/document/7474366/metrics#metrics)\n\n\u003cbr/\u003e\n\n### Libraries\n- [TF-hub's Universal Sentence Encoder](https://tfhub.dev/google/universal-sentence-encoder/2)\n- [Allen NLP's ELMo](https://github.com/allenai/allennlp)\n- [Sentence Transformers](https://github.com/UKPLab/sentence-transformers)\n- [BERTScore](https://github.com/Tiiiger/bert_score)\n- [Vector Similarity](https://github.com/taki0112/Vector_Similarity)\n\n\u003cbr/\u003e\n\n### Articles\n- [An Overview of Sentence Embedding Methods](http://mlexplained.com/2017/12/28/an-overview-of-sentence-embedding-methods/)\n- [Comparing Sentence Similarity Methods](http://nlp.town/blog/sentence-similarity/)\n- [The Current Best of Universal Word Embeddings and Sentence Embeddings](https://medium.com/huggingface/universal-word-sentence-embeddings-ce48ddc8fc3a)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHuffon%2Fsentence-similarity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHuffon%2Fsentence-similarity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHuffon%2Fsentence-similarity/lists"}