Git Product home page Git Product logo

icl4code's Introduction

This is the replication package for our ASE 2023 paper "What Makes Good In-context Demonstrations for Code Intelligence Tasks with LLMs?". This repo contains the code and full experimental results. We study three aspects of demonstration construction including the selection of demonstration examples, the order of demonstration examples, and the number of demonstration examples.

Setup

You need to first have some OpenAI API keys and add them in api_keys list in {codex,gpt3.5,chatgpt}.py.

  • Package requirement of querying LLM:
pip install tqdm
pip install openai
pip install jsonlines
  • Package requirement for different prompt construction methods:
pip install numpy
pip install torch
pip install heapq
pip install sklearn
pip install gensim==3.4.0
pip install transformers
pip install sentence_transformers

Prompt construction

You can first run construction/preprocess.py to first complete the retrieval process. Then you can run construction/construction.py to get the prompt files. You can choose different selection methods, ordering methods, demonstration numbers or insturctions in construction/construction.py.

The code is based on code summarization. If you want to adopt it to other tasks, you can first preprocess your data into jsonlines format and change the directory and key name in these two files.

Experiments

Run {codex,gpt3.5,chatgpt}.py to get predictions for your prompts stored in files with jsonlines format. For example:

python chatgpt.py prompts/summary.jsonl

The results will be saved in prompts/summary_result_.jsonl. Note that CodeX is not available now since OpenAI has stopped its service.

Prompt examples

We show some examples of prompt files in the prompts folder. prompts/bug.jsonl presents an example of the task-level demonstration and the other two files are instance-level demonstrations.

icl4code's People

Contributors

shuzhenggao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.