Package: codeassist
🇨🇳中文|🌐English|📖文档/Docs|🤖模型/ModelsCodeAssist: Advanced Code Completion ToolIntroductionCodeAssistis an advanced code completion tool that intelligently provides high-quality code completions for Python, Java, and C++ and so on.CodeAssist 是一个高级代码补全工具，高质量为 Python、Java 和 C++ 等编程语言补全代码FeaturesGPT based code completionCode completion forPython,Java,C++,javascriptand so onLine and block code completionTrain(Fine-tuning) and predict model with your own dataRelease ModelsArchBaseModelModelModel SizeGPTgpt2shibing624/code-autocomplete-gpt2-base487MBGPTdistilgpt2shibing624/code-autocomplete-distilgpt2-python319MBGPTbigcode/starcoderWizardLM/WizardCoder-15B-V1.029GBDemoHuggingFace Demo:https://huggingface.co/spaces/shibing624/code-autocompletebackend model:shibing624/code-autocomplete-gpt2-baseInstallpipinstalltorch# conda install pytorchpipinstall-Ucodeassistorgitclonehttps://github.com/shibing624/codeassist.gitcdCodeAssist
pythonsetup.pyinstallUsageWizardCoder modelWizardCoder-15b is fine-tunedbigcode/starcoderwith alpaca code data, you can use the following code to generate code:example:examples/wizardcoder_demo.pyimportsyssys.path.append('..')fromcodeassistimportWizardCoderm=WizardCoder("WizardLM/WizardCoder-15B-V1.0")print(m.generate('def load_csv_file(file_path):')[0])output:importcsvdefload_csv_file(file_path):"""Load data from a CSV file and return a list of dictionaries."""# Open the file in read modewithopen(file_path,'r')asfile:# Create a CSV reader objectcsv_reader=csv.DictReader(file)# Initialize an empty list to store the datadata=[]# Iterate over each row of dataforrowincsv_reader:# Append the row of data to the listdata.append(row)# Return the list of datareturndatamodel output is impressively effective, it currently supports English and Chinese input, you can enter instructions or code prefixes as required.distilgpt2 modeldistilgpt2 fine-tuned code autocomplete model, you can use the following code:example:examples/distilgpt2_demo.pyimportsyssys.path.append('..')fromcodeassistimportGPT2Coderm=GPT2Coder("shibing624/code-autocomplete-distilgpt2-python")print(m.generate('import torch.nn as')[0])output:importtorch.nnasnn
importtorch.nn.functionalasFUse with huggingface/transformers：example:examples/use_transformers_gpt2.pyTrain ModelTrain WizardCoder modelexample:examples/training_wizardcoder_mydata.pycdexamplesCUDA_VISIBLE_DEVICES=0,1pythontraining_wizardcoder_mydata.py--do_train--do_predict--num_epochs1--output_diroutputs-wizard--model_nameWizardLM/WizardCoder-15B-V1.0GPU memory: 31GBfinetune need 2*V100(32GB)inference need 1*V100(32GB)Train distilgpt2 modelexample:examples/training_gpt2_mydata.pycdexamples
pythontraining_gpt2_mydata.py--do_train--do_predict--num_epochs15--output_diroutputs-gpt2--model_namegpt2PS: fine-tuned result model is GPT2-python:shibing624/code-autocomplete-gpt2-base,
I spent about 24 hours with V100 to fine-tune it.Serverstart FastAPI server:example:examples/server.pycdexamples
pythonserver.pyopen url:http://0.0.0.0:8001/docsDatasetThis allows to customize dataset building. Below is an example of the building process.Let's use Python codes fromAwesome-pytorch-listWe want the model to help auto-complete codes at a general level. The codes of The Algorithms suits the need.This code from this project is well written (high-quality codes).dataset tree:examples/download/python
├──train.txt
└──valid.txt
└──test.txtThere are three ways to build dataset:Use the huggingface/datasets library load the dataset
huggingface datasetshttps://huggingface.co/datasets/shibing624/source_codefromdatasetsimportload_datasetdataset=load_dataset("shibing624/source_code","python")# python or java or cppprint(dataset)print(dataset['test'][0:10])output:DatasetDict({train:Dataset({features:['text'],num_rows:5215412})validation:Dataset({features:['text'],num_rows:10000})test:Dataset({features:['text'],num_rows:10000})}){'text':["            {'max_epochs': [1, 2]},\n",'            refit=False,\n','            cv=3,\n',"            scoring='roc_auc',\n",'        )\n','        search.fit(*data)\n','','    def test_module_output_not_1d(self, net_cls, data):\n','        from skorch.toy import make_classifier\n','        module = make_classifier(\n']}Download dataset from CloudNameSourceDownloadSizePython+Java+CPP source codeAwesome-pytorch-list(5.22 Million lines)github_source_code.zip105Mdownload dataset and unzip it, put toexamples/.Get source code from scratch and build datasetprepare_code_data.pycdexamples
pythonprepare_code_data.py--num_repos260ContactIssue(建议)
：邮件我：xuming:xuming624@qq.com微信我： 加我微信号：xuming624, 备注：个人名称-公司-NLP进NLP交流群。Citation如果你在研究中使用了codeassist，请按如下格式引用：APA:Xu, M. codeassist: Code AutoComplete with GPT model (Version 1.0.0) [Computer software]. https://github.com/shibing624/codeassistBibTeX:@software{Xu_codeassist,
author ={Ming Xu},
title ={CodeAssist: Code AutoComplete with Generation model},
url ={https://github.com/shibing624/codeassist},
version ={1.0.0}}LicenseThis repository is licensed under theThe Apache License 2.0.Please follow theAttribution-NonCommercial 4.0 Internationalto use the WizardCoder model.Contribute项目代码还很粗糙，如果大家对代码有所改进，欢迎提交回本项目，在提交之前，注意以下两点：在tests添加相应的单元测试使用python setup.py test来运行所有单元测试，确保所有单测都是通过的之后即可提交PR。Referencegpt-2-simplegalois-autocompleterWizardLM/WizardCoder-15B-V1.0