codealpaca logo

codealpaca

Enrichment pending
sahil280114/codealpaca

codealpaca

GraphCanon updated today · GitHub synced today

1.5k
Stars
113
Forks
17
Open issues
19
Watchers
3y
Last push
Python Apache-2.0Created Mar 22, 2023

Trust & integrity

Full report
Maintenance
Dormant (1156d since push)
As of today · Source: github_public_v1
Provenance
Not a fork · Personal account
As of today · Source: github_public_v1
Security (OSV)
46 low (46 low)
As of today · Source: osv@v1

Public GitHub metadata and optional OSV dependency scans. Signals, not a guarantee. Trust methodology.

Capability facts

Languages
python

Source: github.language · Jul 11, 2026

Categories

Compatibility

Sourced claims from the README excerpt - not unsourced marketing copy.

OpenAI APIOpenAI API

Source: README excerpt (regex_v1, Jul 11, 2026)

1. Set environment variables `OPENAI_API_KEY` to your OpenAI API key.
Source link
Python runtimePython

Source: README excerpt (regex_v1, Jul 11, 2026)

3. Run `python -m generate_instruction generate_instruction_following_data` to generate the da
Source link

Tags

README

Code Alpaca: An Instruction-following LLaMA Model trained on code generation instructions

This is the repo for the Code Alpaca project, which aims to build and share an instruction-following LLaMA model for code generation. This repo is fully based on Stanford Alpaca ,and only changes the data used for training. Training approach is the same.

The repo contains:

  • The 20K data used for fine-tuning the model
  • The code for generating the data
  • The code for fine-tuning the model

Demo for the model can be found https://code-alpaca-demo.vercel.app/

Overview

The Code Alpaca models are fine-tuned from a 7B and 13B LLaMA model on 20K instruction-following data generated by the techniques in the Self-Instruct [1] paper, with some modifications that we discuss in the next section. Evals are still a todo.

The model is not finetuned to be safe and harmless, so be cautious.

Current release contains the data generation procedure, dataset, and training code. Model weights aren't part of the release for now, to respect OpenAI TOS and LLaMA license.

[1]: Self-Instruct: Aligning Language Model with Self Generated Instructions. Yizhong Wang, Yeganeh Kordi, Swaroop Mishra, Alisa Liu, Noah A. Smith, Daniel Khashabi, Hannaneh Hajishirzi. https://arxiv.org/abs/2212.10560

Data Release

data/code_alpaca_20k.json contains 20K instruction-following data used for fine-tuning the Code Alpaca model. This JSON file is a list of dictionaries, each dictionary contains the following fields:

  • instruction: str, describes the task the model should perform. Each of the 20K instructions is unique.
  • input: str, optional context or input for the task. For example, when the instruction is "Amend the following SQL query to select distinct elements", the input is the SQL query. Around 40% of the examples have an input.
  • output: str, the answer to the instruction as generated by text-davinci-003.

We used the following prompts for fine-tuning the model:

  • for examples with a non-empty input field:
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

### Instruction:
{instruction}

### Input:
{input}

### Response:
  • for examples with an empty input field:
Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
{instruction}

### Response:

During inference (eg for the web demo), we use the user instruction with an empty input field (second option).

Data Generation Process

Running the code
  1. Set environment variables OPENAI_API_KEY to your OpenAI API key.
  2. Install the dependencies with pip install -r requirements.txt.
  3. Run python -m generate_instruction generate_instruction_following_data to generate the data.
Data generation pipeline had minor changes from [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) - Modified prompt to focus on code generation/editing/optimization tasks instead of general tasks. - Modified seed tasks to only be related to code generation.

This produced an instruction-following dataset with 20K examples obtained at a much lower cost (less than $200). Also including a smaller 2k samples dataset which was used to derisk the approach and quality of the model.

Fine-tuning

Finetuned the models using standard Hugging Face training code and deepspeed with the following hyperparameters:

HyperparameterValue
Learning rate2e-5
Epochs3
Max length512
Weight decay0

Given Hugging Face hasn't officially supported the LLaMA models, we fine-tuned LLaMA wi