Skip to content

VarWizard: Better Code Quality Through Variable Name Refinement.

License

Notifications You must be signed in to change notification settings

FSoft-AI4Code/VarWizard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VarWizard: Better Code Quality Through Variable Name Refinement

Code License Python 3.7+ Downloads

Table of Contents

Introduction

VarWizard is a language model-based tool to help generate more meaningful variable names in source code than the original version. It supports 10 programming languages: c, cpp, java, javascript, go, python, php, c_sharp, ruby, rust.

An overview of VarWizard is in the following figure. VarWizard automatically extracts all variable names in a code snippet, and then it generates candidates for them.

overview

Installation

You can easily install this package by the command

    pip install varwizard

Usage

Command-line

You can use VarWizard by running the command

varwizard [--model-name {bloom-560m, codet5-base} (default: bloom-560m)]
            --input INPUT --lang {c,cpp,java,php,go,javascript,ruby,rust,python,c_sharp} 
            [--output-path OUTPUT_PATH (default: None)] [--max-input-len MAX_INPUT_LEN (default: 400)]
            [--device DEVICE (default: cpu)] [--penalty-alpha PENALTY_ALPHA (default: 0.6)] [--top-k TOP_K (default: 4)] [--max-new-tokens MAX_NEW_TOKENS (default: 100)]

Details for each argument can be found by varwizard --help

Python API

Another way is to use Python Apis. Here is a simple example in this way.

from varwizard import VarWizard

model = VarWizard(model_name = "bloom-560m")
code = """
function chunkData(str, chunk) {
  var chunk = [];
  var length = str.length;
  var i = 0;
  for (; i < length; i += chunk) {
    if (i + chunk < length) {
      chunk.push(str.substring(i, i + chunk));
    } else {
      chunk.push(str.substring(i, length));
    }
  }
  return chunk;
}
"""
print(model.make_new_code(code, 'javascript', device = 'cuda:0'))

VarWizard produces the output

function chunkData(data, length) {
  var result = [];
  var lengthOf = data.length;
  var pos = 0;
  for (; pos < lengthOf; pos += length) {
    if (pos + length < lengthOf) {
      result.push(data.substring(pos, pos + length));
    } else {
      result.push(data.substring(pos, lengthOf));
    }
  }
  return result;
} 

Playground

You can play at the link: https://varwizard.loca.lt. At the first time to access, you may need to enter: 4.193.50.237

Examples

There are some examples for VarWizard's usage. You can navigate to the folder examples and then go to any subfolder to run the script.

About

VarWizard: Better Code Quality Through Variable Name Refinement.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages