{"id":19932041,"url":"https://github.com/amazon-science/codesage","last_synced_at":"2025-04-07T13:04:20.686Z","repository":{"id":221268162,"uuid":"753889040","full_name":"amazon-science/CodeSage","owner":"amazon-science","description":"CodeSage: Code Representation Learning At Scale (ICLR 2024)","archived":false,"fork":false,"pushed_at":"2024-10-27T14:35:55.000Z","size":262,"stargazers_count":99,"open_issues_count":5,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-31T12:03:39.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://code-representation-learning.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/amazon-science.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-02-07T01:16:50.000Z","updated_at":"2025-03-24T07:59:37.000Z","dependencies_parsed_at":"2024-02-07T03:29:29.135Z","dependency_job_id":"7aa75778-1fcb-4e11-99e0-9523ebd2074a","html_url":"https://github.com/amazon-science/CodeSage","commit_stats":null,"previous_names":["amazon-science/codesage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2FCodeSage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2FCodeSage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2FCodeSage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazon-science%2FCodeSage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amazon-science","download_url":"https://codeload.github.com/amazon-science/CodeSage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657275,"owners_count":20974344,"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":[],"created_at":"2024-11-12T23:08:50.241Z","updated_at":"2025-04-07T13:04:20.664Z","avatar_url":"https://github.com/amazon-science.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CodeSage: Code Representation Learning At Scale\n\nThis repository contains the data and inference code of the ICLR 2024\npaper \"[CodeSage: Code Representation Learning At Scale](https://arxiv.org/abs/2402.01935).\" \n\nWork done by Dejiao Zhang*, Wasi Uddin Ahmad*, Ming Tan,\nHantian Ding, Ramesh Nallapati, Dan Roth, Xiaofei Ma, Bing Xiang (* \u003cem\u003eindicates equal contribution\u003c/em\u003e). \n\n## Overview\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"static/CodeSage_Key_Ingredients.png\" width=900\u003e\u003c/img\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003eAn overview of the key ingredients of CodeSage for code representation learning.\u003c/p\u003e\n\n## Environment Setup\n\n```\nconda create -n codesage_eval python=3.10\nconda activate codesage_eval\npip install -r requirements.txt\n```\n\n## Note\nCodeSage has been trained with block-attention. It requires appending the *EOS* token at the end of each sequence to ensure good performance. Below is an example of downloading the model and tokenizer. \n\n```angular2html\nmodel = AutoModel.from_pretrained(\"codesage/codesage-small\", trust_remote_code=True)\ntokenizer = AutoTokenizer(\"codesage/codesage-small\", add_eos_token=True, trust_remote_code=True)\n\ninputs = tokenizer.encode(\"def print_hello_world():\\tprint('Hello World!')\", return_tensors=\"pt\").to(device)\n\nembedding = model(inputs)[0]\n\nprint(f'Dimension of the embedding: {embedding[0].size()}')\n# Dimension of the embedding: torch.Size([14, 1024])\n```\n\n\n## Run Evaluation\n\n### Code-to-Code Search\n\nSee [data preparation](data/code2code/README.md) before running evaluation scripts.\n\n```\nbash scripts/run_code2code_search.sh MODEL_NAME SRC_LANG TGT_LANG\n```\n\nwhere\n\n- MODEL_NAME = `[codesage-small|codesage-base|codesage-large]`\n- SRC_LANG and TGT_LANG = `[python|java|c|c++|csharp|ruby|php|go|javascript|typescript]`\n\n### Text-to-Code Search\n\nSee [data preparation](data/nl2code/README.md) before running evaluation scripts.\n\n```\nbash scripts/run_nl2code_search.sh MODEL_NAME DATASET_NAME\n```\n\nwhere\n\n- MODEL_NAME = `[codesage-small|codesage-base|codesage-large]`\n- SRC_LANG and TGT_LANG = `[cosqa|advTest|csn]`\n\n### Code Classification\n\n```\n# clone detection\nbash scripts/run_clone_detection.sh\n# complexity prediction\nbash scripts/run_complexity_prediction.sh\n# defect prediction\nbash scripts/run_defect_prediction.sh\n# runtime error prediction\nbash scripts/run_runtime_error_prediction.sh\n```\n\n### Benchmark \nWanna compare CodeSage against the latest embedding model? Check out our code for [benchmarking](benchmark/run_benchmark.py)\n\n## Citation\n\n```\n@inproceedings{\nzhang2024code,\ntitle={{CODE} {REPRESENTATION} {LEARNING} {AT} {SCALE}},\nauthor={Dejiao Zhang and Wasi Uddin Ahmad and Ming Tan and Hantian Ding and Ramesh Nallapati and Dan Roth and Xiaofei Ma and Bing Xiang},\nbooktitle={The Twelfth International Conference on Learning Representations},\nyear={2024},\nurl={https://openreview.net/forum?id=vfzRRjumpX}\n}\n```\n\n## Contact\nIf you have any question regarding our paper or code, please feel free to start an issue or email Dejiao Zhang (dejiaozhang@gmail.com) and Wasi Ahmad (wasicse90@gmail.com).\n\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazon-science%2Fcodesage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famazon-science%2Fcodesage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazon-science%2Fcodesage/lists"}