{"id":13595120,"url":"https://github.com/alibaba-edu/simple-effective-text-matching-pytorch","last_synced_at":"2025-04-09T10:32:56.449Z","repository":{"id":40284594,"uuid":"209494330","full_name":"alibaba-edu/simple-effective-text-matching-pytorch","owner":"alibaba-edu","description":"A pytorch implementation of the ACL2019 paper \"Simple and Effective Text Matching with Richer Alignment Features\".","archived":false,"fork":false,"pushed_at":"2022-08-24T08:06:59.000Z","size":176,"stargazers_count":305,"open_issues_count":5,"forks_count":54,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-06T17:45:51.047Z","etag":null,"topics":["deep-learning","nlp","pytorch","quora-question-pairs","snli"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alibaba-edu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-19T07:50:23.000Z","updated_at":"2024-09-20T08:20:42.000Z","dependencies_parsed_at":"2022-06-28T18:11:36.885Z","dependency_job_id":null,"html_url":"https://github.com/alibaba-edu/simple-effective-text-matching-pytorch","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/alibaba-edu%2Fsimple-effective-text-matching-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba-edu%2Fsimple-effective-text-matching-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba-edu%2Fsimple-effective-text-matching-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba-edu%2Fsimple-effective-text-matching-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alibaba-edu","download_url":"https://codeload.github.com/alibaba-edu/simple-effective-text-matching-pytorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248020593,"owners_count":21034459,"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":["deep-learning","nlp","pytorch","quora-question-pairs","snli"],"created_at":"2024-08-01T16:01:44.328Z","updated_at":"2025-04-09T10:32:51.441Z","avatar_url":"https://github.com/alibaba-edu.png","language":"Python","funding_links":[],"categories":["Python","Paper implementations｜论文实现","Paper implementations"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"readme":"# RE2\n\nThis is a pytorch implementation of the ACL 2019 paper \"Simple and Effective Text Matching with Richer Alignment Features\". The original Tensorflow implementation: https://github.com/alibaba-edu/simple-effective-text-matching.\n\n## Quick Links\n\n- [About](#simple-and-effective-text-matching)\n- [Setup](#setup)\n- [Usage](#usage)\n\n## Simple and Effective Text Matching\n\nRE2 is a fast and strong neural architecture for general purpose text matching applications. \nIn a text matching task, a model takes two text sequences as input and predicts their relationship.\nThis method aims to explore what is sufficient for strong performance in these tasks. \nIt simplifies many slow components which are previously considered as core building blocks in text matching,\nwhile keeping three key features directly available for inter-sequence alignment: \noriginal point-wise features, previous aligned features, and contextual features.\n\nRE2 achieves performance on par with the state of the art on four benchmark datasets: SNLI, SciTail, Quora and WikiQA,\nacross tasks of natural language inference, paraphrase identification and answer selection \nwith no or few task-specific adaptations. It has at least 6 times faster inference speed compared to similarly performed models.\n\n\u003cp align=\"center\"\u003e\u003cimg width=\"50%\" src=\"figure.png\" /\u003e\u003c/p\u003e\n\nThe following table lists major experiment results. \nThe paper reports the average and standard deviation of 10 runs. \nInference time (in seconds) is measured by processing a batch of 8 pairs of length 20 on Intel i7 CPUs.\nThe computation time of POS features used by CSRAN and DIIN is not included.\n\n|Model|SNLI|SciTail|Quora|WikiQA|Inference Time|\n|---|---|---|---|---|---|\n|[BiMPM](https://github.com/zhiguowang/BiMPM)|86.9|-|88.2|0.731|0.05|\n|[ESIM](https://github.com/lukecq1231/nli)|88.0|70.6|-|-|-|\n|[DIIN](https://github.com/YichenGong/Densely-Interactive-Inference-Network)|88.0|-|89.1|-|1.79|\n|[CSRAN](https://github.com/vanzytay/EMNLP2018_NLI)|88.7|86.7|89.2|-|0.28|\n|RE2|88.9±0.1|86.0±0.6|89.2±0.2|0.7618 ±0.0040|0.03~0.05|\n\nRefer to the paper for more details of the components and experiment results.\n\n## Setup\n\n- install python \u003e= 3.6 and pip\n- `pip install -r requirements.txt`\n- install [PyTorch](https://pytorch.org)\n- Download [GloVe word vectors](https://nlp.stanford.edu/projects/glove/) (glove.840B.300d) to `resources/`\n\nData used in the paper are prepared as follows:\n\n### SNLI\n\n- Download and unzip [SNLI](https://www.dropbox.com/s/0r82spk628ksz70/SNLI.zip?dl=0) \n(pre-processed by [Tay et al.](https://github.com/vanzytay/EMNLP2018_NLI)) to `data/orig`. \n- Unzip all zip files in the \"data/orig/SNLI\" folder. (`cd data/orig/SNLI \u0026\u0026 gunzip *.gz`)\n- `cd data \u0026\u0026 python prepare_snli.py` \n\n### SciTail\n\n- Download and unzip [SciTail](http://data.allenai.org.s3.amazonaws.com/downloads/SciTailV1.1.zip) \ndataset to `data/orig`.\n- `cd data \u0026\u0026 python prepare_scitail.py`\n\n### Quora\n\n- Download and unzip [Quora](https://drive.google.com/file/d/0B0PlTAo--BnaQWlsZl9FZ3l1c28/view?usp=sharing)\ndataset (pre-processed by [Wang et al.](https://github.com/zhiguowang/BiMPM)) to `data/orig`.\n- `cd data \u0026\u0026 python prepare_quora.py`\n\n### WikiQA\n\n- Download and unzip [WikiQA](https://www.microsoft.com/en-us/download/details.aspx?id=52419)\nto `data/orig`.\n- `cd data \u0026\u0026 python prepare_wikiqa.py`\n- Download and unzip [evaluation scripts](http://cs.stanford.edu/people/mengqiu/data/qg-emnlp07-data.tgz). \nUse the `make -B` command to compile the source files in `qg-emnlp07-data/eval/trec_eval-8.0`.\nMove the binary file \"trec_eval\" to `resources/`.\n\n## Usage\n\nTo train a new text matching model, run the following command: \n\n```bash\npython train.py $config_file.json5\n```\n\nExample configuration files are provided in `configs/`:\n\n- `configs/main.json5`: replicate the main experiment result in the paper.\n- `configs/robustness.json5`: robustness checks\n- `configs/ablation.json5`: ablation study\n\nThe instructions to write your own configuration files:\n\n```json5\n[\n    {\n        name: 'exp1', // name of your experiment, can be the same across different data\n        __parents__: [\n            'default', // always put the default on top\n            'data/quora', // data specific configurations in `configs/data`\n            // 'debug', // use \"debug\" to quick debug your code  \n        ],\n        __repeat__: 5,  // how may repetitions you want\n        blocks: 3, // other configurations for this experiment \n    },\n    // multiple configurations are executed sequentially\n    {\n        name: 'exp2', // results under the same name will be overwritten\n        __parents__: [\n            'default', \n            'data/quora',\n        ],\n        __repeat__: 5,  \n        blocks: 4, \n    }\n]\n```\n\nTo check the configurations only, use\n\n```bash\npython train.py $config_file.json5 --dry\n```\n\nTo evaluate an existed model, use `python evaluate.py $model_path $data_file`, here's an example:\n\n```bash\npython evaluate.py models/snli/benchmark/best.pt data/snli/train.txt \npython evaluate.py models/snli/benchmark/best.pt data/snli/test.txt \n```\n\n\u003e Note that multi-GPU training is not yet supported in the pytorch implementation. A single 16G GPU is sufficient for training when blocks \u003c 5 with hidden size 200 and batch size 512. All the results reported in the paper except the robustness checks can be reproduced with a single 16G GPU.\n\n## Citation\n\nPlease cite the ACL paper if you use RE2 in your work:\n\n```\n@inproceedings{yang2019simple,\n  title={Simple and Effective Text Matching with Richer Alignment Features},\n  author={Yang, Runqi and Zhang, Jianhai and Gao, Xing and Ji, Feng and Chen, Haiqing},\n  booktitle={Association for Computational Linguistics (ACL)},\n  year={2019}\n}\n```\n\n## License\nThis project is under Apache License 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba-edu%2Fsimple-effective-text-matching-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falibaba-edu%2Fsimple-effective-text-matching-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba-edu%2Fsimple-effective-text-matching-pytorch/lists"}