Skip to main content

logo

DocChecker: Bootstrapping Code-Text Pretrained Language Model to Detect Inconsistency Between Code and Comment


DocChecker Package

DocChecker is trained on top of encoder-decoder model to learn from code-text pairs. It is a tool that uses for automated detection to identify inconsistencies between code and docstrings, and generates comprehensive summary sentence to replace the old ones.

overview

Usage Scenario

Installation

Install the dependencies:

pip -r install requirements.txt

Inference

Since DocChecker is a Python package, users can use it by inference function.

from DocChecker.utils import inference

Parameters:

  • input_file_path (str): the file path that contains source code if users want to check all the functions in there.

  • raw_code (str): a sequence of source code if input_file_path is not given.

  • language (str, required): the programming language. We support 10 popular programming languages such as Java, JavaScript, Python, Ruby, Rust, Golang, C#, C++, C, and PHP.

  • output_file_path (str): if it is not None, the results from our tool will be written in this path; otherwise, they will be printed on the screen. Returns:

  • list of dictionaries, including:

    • function_name: the name of each function in the raw code
    • code: code snippet
    • docstring: the docstring corresponding code snippet
    • predict: the prediction of DocChecker. It returns "Inconsistent!” for the inconsistent pair and “Consistent!” means the docstring is consistent with the code in a code-text pair
    • recommend_docstring: If a code-text pair is considered as “Inonsistent!”, DocChecker will give a comprehensive docstring to replace its docstring, otherwise, it will keep the original version.

Example

from DocChecker.utils import inference

code = """
def inject_func_as_unbound_method(class_, func, method_name=None):
    # This is actually quite simple
    if method_name is None:
        method_name = get_funcname(func)
    setattr(class_, method_name, func)

def e(message, exit_code=None):
    # Print an error log message.
    print_log(message, YELLOW, BOLD)
    if exit_code is not None:
        sys.exit(exit_code)
"""

inference(raw_code=code, language='python')

>>> [
    {
    "function_name": "inject_func_as_unbound_method",
    "code": "def inject_func_as_unbound_method(class_, func, method_name=None):\n    \n    if method_name is None:\n        method_name = get_funcname(func)\n    setattr(class_, method_name, func)",
    "docstring": " This is actually quite simple",
    "predict": "Inconsistent!",
    "recommended_docstring": "Inject a function as an unbound method."
	},
	{
	    "function_name": "e",
	    "code": "def e(message, exit_code=None):\n    \n    print_log(message, YELLOW, BOLD)\n    if exit_code is not None:\n        sys.exit(exit_code)",
	    "docstring": "Print an error log message.",
	    "predict": "Consistent!",
	    "recommended_docstring": "Print an error log message."
	}
	]

Reference

More details can be found in our paper. If you use this code or our package, please consider citing us:

@article{DocChecker,
  title={Bootstrapping Code-Text Pretrained Language Model to Detect Inconsistency Between Code and Comment},
  author={},
  journal={},
  pages={},
  year={2023}
}

Contact us

If you have any questions, comments or suggestions, please do not hesitate to contact us.

License

MIT License

Metadata

Release files for docchecker 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docchecker 0.1.3
File Size Uploaded
docchecker-0.1.3.tar.gz 55.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docchecker 0.1.3
File Interpreter ABI Platform
docchecker-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 117.0 kB

Release files / docchecker-0.1.3.tar.gz

Download URL docchecker-0.1.3.tar.gz
Size 55.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec9c523ccb41d9a1e6031fa0bd8a63908d548f1fbfa61771549289c5227dd569
BLAKE2b-256 checksum
How to use checksums
4e4d5560d427a3b32678a663791cac598bb694bc092e59ddb0cb389b11dca5ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / docchecker-0.1.3-py3-none-any.whl

Download URL docchecker-0.1.3-py3-none-any.whl
Size 61.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f36da9f8fa19244cb2690ee80d19a93e09294500004eca15fb81a0ba251472af
BLAKE2b-256 checksum
How to use checksums
b4252f72e8bc53fd1a959ec8124b329208df00a1003d17b6bb5c34a59f368772
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page