{"id":13535105,"url":"https://github.com/graykode/KorQuAD-beginner","last_synced_at":"2025-04-02T00:32:29.219Z","repository":{"id":110173060,"uuid":"183613292","full_name":"graykode/KorQuAD-beginner","owner":"graykode","description":"Guide KorQuAD upload to leaderboard (EM 68.947 / F1 88.468) model which only use BERT-multilingual(single)","archived":false,"fork":false,"pushed_at":"2019-05-01T06:02:06.000Z","size":8405,"stargazers_count":41,"open_issues_count":0,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T17:04:02.990Z","etag":null,"topics":["bert","squad"],"latest_commit_sha":null,"homepage":"https://korquad.github.io/","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/graykode.png","metadata":{"files":{"readme":"README(EN).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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-26T11:00:51.000Z","updated_at":"2024-04-30T13:47:42.000Z","dependencies_parsed_at":"2023-04-13T21:32:28.299Z","dependency_job_id":null,"html_url":"https://github.com/graykode/KorQuAD-beginner","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/graykode%2FKorQuAD-beginner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graykode%2FKorQuAD-beginner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graykode%2FKorQuAD-beginner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graykode%2FKorQuAD-beginner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graykode","download_url":"https://codeload.github.com/graykode/KorQuAD-beginner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246735340,"owners_count":20825220,"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":["bert","squad"],"created_at":"2024-08-01T08:00:49.758Z","updated_at":"2025-04-02T00:32:24.175Z","avatar_url":"https://github.com/graykode.png","language":"Python","readme":"## KorQuAD-beginner\n\nThis is a repository for those who are trying [KorQuAD](https://korquad.github.io/) for the first time. I got f1 88.468 and EM(ExactMatch) 68.947, just with the BERT-multilingual(single) model, Only [google-research's BERT github](https://github.com/google-research/bert).\n\n![](leaderboard.jpg)\n\nWhile it was not difficult to achieve results simply by fine-tuning KorQuAD data, using `codalab` was very difficult for the first time. So this repository will also explain in detail how to use `codalab`, how to upload your result to KorQuAD leaderboard.\n\n\n\n### 1. fine-tuning KorQuAD\n\n It is very easy to fine-tuning if you use [google-research's BERT github](https://github.com/google-research/bert). Everything is possible with one line of this command. If you still use Google-research's BERT, Korean subtokens are processed as UNK because of `unicodedata.normalize(\"NFD\", text)`. Please see [here](https://github.com/google-research/bert/pull/228) and pull request [code](https://github.com/google-research/bert/pull/228/commits/c26341272de7c0d22cd65ea58d884323f64b7a92), if you want to more detail. I have already applied Korean Issue in my code. Also I used [**BERT-Base, Multilingual Cased (New, recommended)**](https://storage.googleapis.com/bert_models/2018_11_23/multi_cased_L-12_H-768_A-12.zip) for pre-trained weight(104 languages, 12-layer, 768-hidden, 12-heads, 110M parameters).\n\n```shell\n$ python run_squad.py \\\n  --vocab_file=multi_cased_L-12_H-768_A-12/vocab.txt \\\n  --bert_config_file=multi_cased_L-12_H-768_A-12/bert_config.json \\\n  --init_checkpoint=multi_cased_L-12_H-768_A-12/bert_model.ckpt \\\n  --do_train=True \\\n  --train_file=config/KorQuAD_v1.0_train.json \\\n  --do_predict=True \\\n  --predict_file=config/KorQuAD_v1.0_dev.json \\\n  --train_batch_size=4 \\\n  --num_train_epochs=3.0 \\\n  --max_seq_length=384 \\\n  --output_dir=./output \\\n  --do_lower_case=False\n```\n\nI trained in GeForce RTX 2080 and 11GB in memory, and it took about three to four hours.\n\nThen you can evaluate F1 and EM score.\n\n```shell\n$ python evaluate-v1.0.py config/KorQuAD_v1.0_dev.json output/predictions.json\n\n{\"f1\": 88.57661204608746, \"exact_match\": 69.05091790786284}\n```\n\n**Put your checkpoint files in config folder**\n\n\n\n### 2. Codalab Guide for submit KorQuAD\n\n##### 0. Sign up in Codalab\n\nSign up **worksheets**, not completion\n\n\n\n##### 1. Install Codalab Cli\n\nThe CLI only works with Python 2.7 right now, so if Python 3 is your default, I recommend `Anaconda` configure setting, rather than virtualenv. \n\n```shell\n$ conda create -n py27 python=2.7 anaconda\n$ conda activate py27\n(py27) $ pip install codalab -U --user\n```\n\n\n\n##### 2. Create New WorkSheet in Codalab\n\nClick the `New Worksheet` button in the upper right corner and name the worksheet.\n\n\n\n##### 3. Test predictions.json that is created on fine-tuning.\n\n\u003e If you don't want to see evaluation of Dev set, Just skip this part.\n\n1. Click `Upload` Button and upload `output/predictions.json` that is created on fine-tuning.\n\n2. In the web interface terminal at the top of the page, type the following command:\n\n   `\u003cname-of-your-uploaded-prediction-bundle\u003e` is uuid[0:8] of `output/predictions.json`.\n\n   ```shell\n   # web interface terminal\n   cl macro korquad-utils/dev-evaluate-v1.0 \u003cname-of-your-uploaded-prediction-bundle\u003e\n   ```\n\n   \n\n##### 4. Upload `src` , `config` folder\n\nThe reason for this division is that it takes a long time to upload the config folder (checkpoint files) every time.\n\n- src folder : only source files to run in Codalab, ex) `run_squad.py`\n- config folder : `bert_config.json`, `KorQuAD_v1.0_dev.json`,  `KorQuAD_v1.0_dev.json`, `vocab.txt`, `checkpoint files(fine-tuning checkpoint file)`\n\nUpload folders using `Codalab Cli`. You can also upload using the Web UI, but use cli because it's slow for folders.\n\n```shell\n# command on Anaconda-Python2.7\n# cl upload \u003cfolder-name\u003e -n \u003cbundle-name\u003e\n$ cl upload Leaderboard -n src\n$ cl upload config -n config\n```\n\n\n\n##### 5. Run learning model for dev set\n\n```shell\n# web interface terminal\ncl add bundle korquad-data//KorQuAD_v1.0_dev.json .\n```\n\nYou can see `bundle spec . doesn't match any bundles`, but It's not a problem to proceed.\n\nThen, Run learning model for dev set!\n\n:src, :config meaning of : `\u003cbundle-name\u003e`\n\n```shell\n# command on Anaconda-Python2.7\n$ cl run :KorQuAD_v1.0_dev.json :src :config \"python src/run_KorQuAD.py --bert_config_file=config/bert_config.json --vocab_file=config/vocab.txt --init_checkpoint=config/model.ckpt-45000 --do_predict=True --output_dir=output config/KorQuAD_v1.0_dev.json predictions.json\" -n run-predictions --request-docker-image tensorflow/tensorflow:1.12.0-gpu-py3 --request-memory 11g --request-gpus 1\n```\n\n###### Trouble shooting\n\n1. About argument : [Original KorQuAD tutorial](https://worksheets.codalab.org/worksheets/0x7b06f2ebd0584748a3a281018e7d19b0/), They recommend python arguments like this.\n\n   ```\n   python src/\u003cpath-to-prediction-program\u003e \u003cinput-data-json-file\u003e \u003coutput-prediction-json-path\u003e\n   ```\n\n   above command match below: `\u003cbundle-name\u003e`/file-name\n\n   ```\n   python src/run_KorQuAD.py --bert_config_file=config/bert_config.json --vocab_file=config/vocab.txt --init_checkpoint=config/model.ckpt-45000 --do_predict=True --output_dir=output config/KorQuAD_v1.0_dev.json predictions.json\n   ```\n\n2. About ImportError: libcuda.so.1 error : using `tensorflow 1.12.0` version docker with `python3` and `--request-gpus 1` to clearly specify the pin number.\n\n3. About out of memory : `--request-memory 11g`\n\n\n\n##### 6. Add prediction file(result of part 5) in Bundle\n\nAdd the prediction file to the bundle.: `MODELNAME` can't contain spaces and special characters.\n\n```shell\n# web interface terminal\ncl make run-predictions/predictions.json -n predictions-{MODELNAME}\n```\n\nLet's see if we can evaluate the prediction file of dev set.\n\n```shell\n# web interface terminal\ncl macro korquad-utils/dev-evaluate-v1.0 predictions-{MODELNAME}\n```\n\n\n\n##### 7 Submit(제출)\n\nAfter this,  To submit your result in leader board, see [Original KorQuAD tutorial](https://worksheets.codalab.org/worksheets/0x7b06f2ebd0584748a3a281018e7d19b0/) of part 3.\n\n![](result.jpg)\n\n\n\n## License\n\nThese Repository are all released under the same license as the source code (Apache 2.0) with [google-research BERT](https://github.com/google-research/bert), Tae Hwan Jung\n\n\n\n## Author\n\n- Tae Hwan Jung(Jeff Jung) @graykode, Kyung Hee Univ CE(Undergraduate).\n- Author Email : [nlkey2022@gmail.com](mailto:nlkey2022@gmail.com)\n- Reference : [Original KorQuAD tutorial](https://worksheets.codalab.org/worksheets/0x7b06f2ebd0584748a3a281018e7d19b0/), [The Land Of Galaxy Blog](http://mlgalaxy.blogspot.com/2019/02/bert-multilingual-model-korquad-part-2.html#comment-form)","funding_links":[],"categories":["BERT QA \u0026 RC task:"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraykode%2FKorQuAD-beginner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraykode%2FKorQuAD-beginner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraykode%2FKorQuAD-beginner/lists"}