{ "info": { "author": "Taycir Yahmed", "author_email": "taycir.yahmed@gmail.com", "bugtrack_url": null, "classifiers": [ "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# mcQA : Multiple Choice Questions Answering \n\nAnswering multiple choice questions with Language Models.\n\n[![CircleCI](https://circleci.com/gh/mcQA-suite/mcQA.svg?style=svg)](https://circleci.com/gh/mcQA-suite/mcQA)\n[![PyPI Version](https://img.shields.io/pypi/v/mcqa.svg)](https://pypi.org/project/mcqa/)\n![GitHub](https://img.shields.io/github/license/mcqa-suite/mcqa.svg)\n[![codecov](https://codecov.io/gh/mcqa-suite/mcQA/branch/master/graph/badge.svg)](https://codecov.io/gh/mcqa-suite/mcQA)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)\n\n## Installation\n\n### With pip\n\n```shell\npip install mcqa\n```\n\n### From source\n\n```shell\ngit clone https://github.com/mcqa-suite/mcqa.git\ncd mcQA\npip install -e .\n```\n\n## Getting started\n\n### Data preparation\n\nTo train a `mcQA` model, you need to create a csv file with n+2 columns, n being the number of choices for each question. The first column should be the context sentence, the n following columns should be the choices for that question and the last column is the selected answer. \n\nBelow is an example of a 3 choice question (taken from the [CoS-E dataset](https://arxiv.org/pdf/1906.02361.pdf)) :\n\n| Context sentence | Choice 1 | Choice 2 | Choice 3 | Label|\n| ----------------- | --------------------|--------------------|--------------------|-------------|\n| People do what during their time off from work?| take trips | brow shorter | become hysterical | take trips |\n\nIf you have a trained `mcQA` model and want to infer on a dataset, it should have the same format as the train data, but the `label` column. \n\nSee example data preparation below:\n\n```python\nfrom mcqa.data import MCQAData\n\nmcqa_data = MCQAData(bert_model=\"bert-base-uncased\", \n lower_case=True, \n max_seq_length=256) \n \ntrain_dataset = mcqa_data.read(data_file='swagaf/data/train.csv', is_training=True)\ntest_dataset = mcqa_data.read(data_file='swagaf/data/test.csv', is_training=False)\n```\n\n### Model training \n\n```python\nfrom mcqa.models import Model\n\nmdl = Model(bert_model=\"bert-base-uncased\",\n device=\"cuda\") \n \nmdl.fit(train_dataset, \n train_batch_size=32, \n num_train_epochs=20)\n```\n\n### Prediction\n\n```python\npreds = mdl.predict(test_dataset, \n eval_batch_size=32)\n```\n\n### Evaluation\n\n```python\nfrom sklearn.metrics import accuracy_score\nfrom mcqa.data import get_labels\n\nprint(accuracy_score(preds, get_labels(train_dataset)))\n```\n## References\n\n| Type | Title | Author | Year |\n| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ---- |\n|:newspaper: Paper| [Explain Yourself! Leveraging Language Models for Commonsense Reasoning](https://arxiv.org/pdf/1906.02361.pdf)|Nazneen Fatema Rajani, Bryan McCann, Caiming Xiong and Richard Socher| ACL 2019|\n|:newspaper: Paper|[SWAG: A Large-Scale Adversarial Dataset for Grounded Commonsense Inference](https://arxiv.org/abs/1808.05326)|Rowan Zellers, Yonatan Bisk, Roy Schwartz and Yejin Choi|2018|", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mcQA-suite/mcQA", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "mcqa", "package_url": "https://pypi.org/project/mcqa/", "platform": "", "project_url": "https://pypi.org/project/mcqa/", "project_urls": { "Homepage": "https://github.com/mcQA-suite/mcQA" }, "release_url": "https://pypi.org/project/mcqa/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Answering multiple choice questions with Language Models.", "version": "0.1.1" }, "last_serial": 5687355, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "f353580fbccce6655865abb773dcc773", "sha256": "0200cdae704c3d77641ddc416f53661e2c080f99470a11bc9802d682178c2689" }, "downloads": -1, "filename": "mcqa-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f353580fbccce6655865abb773dcc773", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5490, "upload_time": "2019-07-15T20:53:03", "url": "https://files.pythonhosted.org/packages/9c/7d/0d66a36559901430d876b5c9151d44b4ef39fc4f25a870edc30971656b5b/mcqa-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dfaae4bf1c4152ecb4c8251fb7017b3c", "sha256": "6dffbf103356cf77b8f08254f7494b15bc09ebf20fbbf1d5584498f2944b8207" }, "downloads": -1, "filename": "mcqa-0.0.1.tar.gz", "has_sig": false, "md5_digest": "dfaae4bf1c4152ecb4c8251fb7017b3c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1143, "upload_time": "2019-07-15T20:53:05", "url": "https://files.pythonhosted.org/packages/da/c2/95b6db4fdddb5a2a026f9876bb52b8dd80b6765f11fae399b18502e07ad0/mcqa-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "eeb2b4a12b625fdb83e4ddf96f4815de", "sha256": "11d4966c82558aed83d6be9531c0d7e8c2b90c2f58f48bbb50f7e0a79460276f" }, "downloads": -1, "filename": "mcqa-0.1.0.tar.gz", "has_sig": false, "md5_digest": "eeb2b4a12b625fdb83e4ddf96f4815de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13756, "upload_time": "2019-07-26T09:22:57", "url": "https://files.pythonhosted.org/packages/b5/d7/1fa25c55e7cd0b4cc101ce4ddac2b811fe579253573c42f274b78cdd7b59/mcqa-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "2664ce9f09c18ae93148eaa7fa582fa2", "sha256": "7317fcf33d232cf42f70a097d9847e4f77433329188bff7635491387dcf5af13" }, "downloads": -1, "filename": "mcqa-0.1.1.tar.gz", "has_sig": false, "md5_digest": "2664ce9f09c18ae93148eaa7fa582fa2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15621, "upload_time": "2019-08-16T12:22:26", "url": "https://files.pythonhosted.org/packages/54/a7/92e02e08b640c6b4f339b249211688fc52b09ef32efb603527b766e4f0f2/mcqa-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2664ce9f09c18ae93148eaa7fa582fa2", "sha256": "7317fcf33d232cf42f70a097d9847e4f77433329188bff7635491387dcf5af13" }, "downloads": -1, "filename": "mcqa-0.1.1.tar.gz", "has_sig": false, "md5_digest": "2664ce9f09c18ae93148eaa7fa582fa2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15621, "upload_time": "2019-08-16T12:22:26", "url": "https://files.pythonhosted.org/packages/54/a7/92e02e08b640c6b4f339b249211688fc52b09ef32efb603527b766e4f0f2/mcqa-0.1.1.tar.gz" } ] }