Git Product home page Git Product logo

uncertaintypl's Introduction

Uncertainty Awareness of LLMs in Code Analysis

Uncertainty Awareness of Large Language Models Under Code Distribution Shifts: A Benchmark Study

A PyTorch implementation of two code analysis tasks, code summarization~(CS) and code completion~(CC) with four models. We use Python extractors to preprocess the raw code snippets. Users may further extend the work to other programming languages following our study.

Our study overview:

Code analysis mechanism:

Requirements

pip install -r requirements.txt

Quickstart

Step 0: Cloning this repository

git clone https://github.com/yul091/UncertaintyPL.git
cd UncertaintyPL

Step 1: Download our preprocessed datasets

Step 2: Fine-tuning a model

To train a model from scratch:

  • Code summarization:
python -B -m program_tasks.code_summary.main \
  --tk_path ${TK_PATH} --epochs ${EPOCHS} --batch ${BATCH} --lr ${LR} \
  --embed_dim ${EMBEDDING_DIM} --embed_path ${EMBEDDING_PATH} \
  --model_type ${MODEL_TYPE} \
  --train_data ${TRAIN_DATA} \
  --val_data ${VAL_DATA} \
  --test_data ${TEST_DATA} \
  --max_size ${MAX_SIZE} \
  --ensemble_models 5 \
  --do_train --do_eval \
  --embed_type ${EMBEDDING_TYPE} \
  --experiment_name ${EXPERIMENT_NAME} \
  --res_dir ${RES_DIR} | tee $EXPERIMENT_LOG
  • Code completion:
python -B -m program_tasks.code_completion.main \
  --train_data $TRAIN_DATA --val_data $VAL_DATA --test_data $TEST_DATA \
  --model_type $MODEL_TYPE \
  --ensemble_models 5 \
  --embedding_path $EMBEDDING_PATH \
  --embedding_type $EMBEDDING_TYPE \
  --embedding_dim $EMBEDDING_DIM \
  --do_train --do_eval \
  --epochs $EPOCHS --batch_size $BATCH --lr $LR --res_dir $RES_DIR \
  --experiment_name $EXPERIMENT_NAME | tee $EXPERIMENT_LOG

Step 3: Calibrating the model and quantifying the uncertainty scores

python test_uncertainty.py \
  --module_id $MODULE_ID --res_dir $RES_DIR \
  --data_dir $DATA_DIR --save_dir $SAVE_DIR \
  --train_batch_size $TRAIN_BATCH_SIZE \
  --test_batch_size $TEST_BATCH_SIZE \
  --ensemble_dirs $ENSEMBLE_DIRS \
  --max_size $MAX_SIZE | tee $EXPERIMENT_LOG

Step 4: Evaluation the effectiveness of different UE techniques:

  • Misclassification detection:
python -B -m Uncertainty_Eval.evaluation \
  --shift_type $SHIFT \
  --task $TASK \
  --model $MODEL | tee $EXPERIMENT_LOG
  • Selective prediction:
python input_validation.py \
  --shift_type $SHIFT \
  --task $TASK \
  --model $MODEL \
  --uncertainty_dir $METRICDIR \
  --out_dir $OUTDIR \
  --strategy coverage
  • OOD detection:
python -B -m Uncertainty_Eval.evaluation \
  --shift_type $SHIFT \
  --task $TASK \
  --ood \
  --model $MODEL | tee $EXPERIMENT_LOG

uncertaintypl's People

Contributors

yul091 avatar

Stargazers

 avatar

Watchers

 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.