Skip to main content

A fork of the InterCode benchmark used to evaluate natural language to Bash command translation.

Project description

InterCode-ALFA

Description

A fork of the InterCode benchmark used to evaluate natural language to Bash command translation.
HuggingFace Dataset
PyPI Package

InterCode-ALFA Diagram

Installation

  • Install Docker Engine - Instructions
  • Configure Docker for non-sudo users - Instructions
  • Create a python virtual environment
apt install python3.12-venv
python3 -m venv icalfa-venv
source icalfa-venv/bin/activate
  • Install InterCode-ALFA
pip install icalfa datasets tqdm
  • [Optional] If you want to use a local LLM, install Ollama
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.1:70b
  • [Optional] If you want to use the embedding comparison method, install mxbai-embed-large
ollama pull mxbai-embed-large

Usage

  • Run the benchmark
import os
from icalfa import submit_command
from datasets import load_dataset
from tqdm import tqdm

# Store OpenAI key as environment variable 
os.environ['ICALFA_OPENAI_API_KEY'] = '...'

# Load dataset
dataset = load_dataset("westenfelder/NL2SH-ALFA", "test", split="train")

# Iterate through the dataset
score = 0
for index, row in tqdm(enumerate(dataset), total=len(dataset)):

    # Retrieve natural language prompt
    prompt = row['nl']

    # Convert natural language prompt to Bash command here

    # Submit Bash command for benchmark scoring. 0 = incorrect, 1 = correct
    score += submit_command(index=index, command="...")

    # Retrieve ground truth commands
    ground_truth_command = row['bash']
    ground_truth_command2 = row['bash2']

# Print the benchmark result
print(score/len(dataset))
  • submit_command parameters
# By default icalfa uses OpenAI's GPT-4 model and expects an API key
submit_command(index, command, eval_mode="openai", eval_param="gpt-4-0613")

# A local model can be used via Ollama and does not require an API key
submit_command(index, command, eval_mode="ollama", eval_param="llama3.1:70b")

# You can also test the original method used in Princeton's InterCode benchmark
submit_command(index, command, eval_mode="tfidf")

# An embedding based comparison method is also available
# This uses the mxbai-embed-large model via Ollama, with the eval_param specifying the similarity threshold
submit_command(index, command, eval_mode="embed", eval_param=0.75)
  • Manage Docker containers
# Stop containers
docker stop $(docker ps -a --filter "name=intercode*" -q)

# Delete containers
docker rm $(docker ps -a --filter "name=intercode*" -q)

Building

# pip install build twine
# update version in pyproject.toml and __init__.py
rm -rf dist
python3 -m build
python3 -m twine upload --repository pypi dist/*
pip install --upgrade icalfa

Credits

InterCode-ALFA is a fork of the InterCode benchmark developed by the Princeton NLP group.
InterCode Website
InterCode PyPI Package

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icalfa-0.3.6.tar.gz (559.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

icalfa-0.3.6-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file icalfa-0.3.6.tar.gz.

File metadata

  • Download URL: icalfa-0.3.6.tar.gz
  • Upload date:
  • Size: 559.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for icalfa-0.3.6.tar.gz
Algorithm Hash digest
SHA256 c81162af4f3c404824d8710f57b6e7c4f200f36efbb8757ea05fe2f317f33730
MD5 b6a66833f19168e9d10ade8a4ccd11cc
BLAKE2b-256 65bba2c5f9ff840630d9265108e7f6b7a481175313cbed7a4641b3162c1f2d99

See more details on using hashes here.

File details

Details for the file icalfa-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: icalfa-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for icalfa-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 621590a41cd843793f669c2c097adab4924132fa693776d4866c9a0846217eeb
MD5 c6dd63ddcdedcdd64ab5c6e67ee69727
BLAKE2b-256 7839ddfe7082dfe918fbe663129c366de2655492f4e93767b6205da6f03ea913

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page