https://github.com/amazon-science/cocomic
CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Context
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Repository
CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Context
Basic Info
- Host: GitHub
- Owner: amazon-science
- License: apache-2.0
- Language: Python
- Default Branch: main
- Homepage: https://arxiv.org/abs/2212.10007
- Size: 1.22 MB
Statistics
- Stars: 17
- Watchers: 0
- Forks: 5
- Open Issues: 11
- Releases: 0
Metadata Files
README.md
CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Context
This repository conatins the code for the paper CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Context at LREC-COLING 2024.
You may also want to check out our other paper on CrossCodeEval at NeurIPS 2023.
Quick Links
Overvew
We propose CoCoMIC, a framework that incorporates cross-file context to learn the in-file and cross-file context jointly on top of pretrained code LMs.
CCFinder: Cross-file Context Finder
CCFinder parses the project hierarchy and code components to extract project information. CCFinder further builds a project context graph to represent the details of each component and the interactions among them. When an incomplete program requests completion, the tool will retrieve the neighbors of the pinpointed entities from the graph as the cross-file context of the current file.
CoCoMIC: Model Architecture
We propose a novel model architecture built on top of existing code LMs with joint attention to in-file and retrieved cross-file context. First, the model will compress cross-file context and build its representations. Second, when generating code completion, the model will attend to both the compressed cross-file context and the concrete in-file context.
Getting Started
Set up envionment
conda create -n cocomic python=3.9.13
conda activate cocomic
pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
pip install -r requirements.txt
Download and build tree-sitter library
``` mkdir tspackage; cd tspackage;
Download the tree-sitter package
git clone https://github.com/tree-sitter/tree-sitter-python.git;
checkout to 0.20.0 version
git checkout 2b9e9e0d231d5dd9f491d47f704817baee7d5af0; cd ..;
Build tree-sitter
python buildtslib.py ```
If the the commands finishes successfully, you should be able to see a ccfinder/cc_extractor/build/directory now under the package root, which contains a .so file
Use CCFinder
Input
The input is a folder containing the source code of a Python project.
Command
export PYTHONPATH=$(pwd)/ccfinder;
python ccfinder/build_crossfile_context.py --input_project <PATH_TO_PROJECT_FOLDER> --output_dir <OUTPUT_FOLDER>
Output
shell
|---<OUTPUT_FOLDER>
|---<PROJECT_NAME>_project_context.json # Hierarchical Project Context
|---<PROJECT_NAME>_project_context.node # List of Project Entities
|---<PROJECT_NAME>_project_context.edge.jsonl # List of Entity Relations
|---<PROJECT_NAME>_project_context.graph # Intermediate Graph Structure
|---<PROJECT_NAME>_project_context.graph.adj.pk # Intermediate Graph Structure in the format of Adjacency Matrix
|---<PROJECT_NAME>_retrieved_nodes.json # Retrieved Project Entities for each file in the project
Create Samples with Cross-file Context
Input
When you have a list of prompts for a specific project to complete, please format them with the following attribute and save them in a <PROJECT_NAME>_prompts.jsonl file, where each line corresponds to one sample
json
{"prompt":"...<IN-FILE CONTEXT>...","groundtruth":"...","metadata":{"file":"<ABSOLUTE_FILE_PATH>"}}
Command
python ccfinder/create_sample_w_cfc.py \
--retrieved_entity_file <PATH_TO>/<PROJECT_NAME>_retrieved_nodes.json \
--prompt_file <PATH_TO>/<PROJECT_NAME>_prompts.jsonl \
--output_file <PATH_TO>/<PROJECT_NAME>_prompts_with_cfc.jsonl
Output
The output will be a .jsonl file, and each line corresponds to a sample with its cross-file context in the following format
json
{
"prompt": " ... ",
"groundtruth": " ... ",
"retrieved_nodes": [
" ...<PROJECT_ENTITY>... ",
],
"retrieved_edges": [
["<ENTITY_IDX>", "<RELATION_TYPE>", "<RELATION__TYPE_IDX>", "<ENTITY_IDX>"],
],
"metadata": {
"file":"<ABSOLUTE_FILE_PATH>"
}
}
Owner
- Name: Amazon Science
- Login: amazon-science
- Kind: organization
- Website: https://amazon.science
- Twitter: AmazonScience
- Repositories: 80
- Profile: https://github.com/amazon-science
GitHub Events
Total
- Issues event: 1
- Watch event: 5
- Delete event: 1
- Issue comment event: 1
- Push event: 1
- Pull request event: 5
- Fork event: 2
- Create event: 3
Last Year
- Issues event: 1
- Watch event: 5
- Delete event: 1
- Issue comment event: 1
- Push event: 1
- Pull request event: 5
- Fork event: 2
- Create event: 3
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Zijian Wang | 2****g | 3 |
| Zijian Wang | z****n@a****m | 2 |
| Amazon GitHub Automation | 5****o | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 0
- Total pull requests: 6
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 6
Past Year
- Issues: 0
- Pull requests: 6
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 6
Top Authors
Issue Authors
- kezhen1 (1)
Pull Request Authors
- dependabot[bot] (10)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- GPUtil ==1.4.0
- GitPython ==3.1.27
- Levenshtein ==0.20.8
- Markdown ==3.4.1
- MarkupSafe ==2.1.1
- Pillow ==9.2.0
- PyYAML ==6.0
- Werkzeug ==2.2.2
- absl-py ==1.2.0
- accelerate ==0.13.1
- aiohttp ==3.8.1
- aiosignal ==1.2.0
- async-timeout ==4.0.2
- attrs ==22.1.0
- cachetools ==5.2.0
- charset-normalizer ==2.1.1
- click ==8.1.3
- colorama ==0.4.6
- cycler ==0.11.0
- datasets ==2.3.2
- deepspeed ==0.7.2
- dill ==0.3.5.1
- docker-pycreds ==0.4.0
- filelock ==3.8.0
- fonttools ==4.37.1
- frozenlist ==1.3.1
- fsspec ==2022.8.2
- fuzzywuzzy ==0.18.0
- gitdb ==4.0.9
- google-auth ==2.11.0
- google-auth-oauthlib ==0.4.6
- grpcio ==1.48.1
- hjson ==3.1.0
- huggingface-hub ==0.12.0
- idna ==3.3
- import-deps ==0.2.0
- importlib-metadata ==4.12.0
- joblib ==1.2.0
- kiwisolver ==1.4.4
- lightning-transformers ==0.2.1
- lxml ==4.9.1
- matplotlib ==3.5.3
- multidict ==6.0.2
- multiprocess ==0.70.13
- networkx ==2.8.4
- ninja ==1.10.2.3
- nltk ==3.7
- numpy ==1.23.1
- oauthlib ==3.2.1
- packaging ==21.3
- pandas ==1.4.4
- pathtools ==0.1.2
- portalocker ==2.6.0
- promise ==2.3
- protobuf ==3.20.1
- psutil ==5.9.2
- py-cpuinfo ==8.0.0
- pyDeprecate ==0.3.2
- pyarrow ==9.0.0
- pyasn1 ==0.4.8
- pyasn1-modules ==0.2.8
- pybind11 ==2.10.3
- pydantic ==1.10.2
- pylcs ==0.0.7
- pyparsing ==3.0.9
- python-dateutil ==2.8.2
- pytorch-lightning ==1.6.5
- pytz ==2022.2.1
- rapidfuzz ==2.13.2
- regex ==2022.9.13
- requests ==2.28.1
- requests-oauthlib ==1.3.1
- responses ==0.18.0
- rsa ==4.9
- sacrebleu ==2.3.1
- scipy ==1.8.1
- sentencepiece ==0.1.97
- sentry-sdk ==1.9.8
- setproctitle ==1.3.2
- shortuuid ==1.0.9
- six ==1.16.0
- smmap ==5.0.0
- tabulate ==0.9.0
- tensorboard ==2.9.0
- tensorboard-data-server ==0.6.1
- tensorboard-plugin-wit ==1.8.1
- timeout-decorator ==0.5.0
- tokenizers ==0.12.1
- torchmetrics ==0.9.3
- tqdm ==4.64.0
- transformers ==4.26.0
- tree-sitter ==0.20.0
- typing_extensions ==4.3.0
- ujson ==1.35
- urllib3 ==1.26.12
- wandb ==0.13.3
- xxhash ==3.0.0
- yarl ==1.8.1
- zipp ==3.8.1