CoolFace
Modelpublic

kdf/python-docstring-generation

sourceHugging Faceapache-2.0updated 4y agoView on Hugging Face
3likes71downloads
README.md129 linesDownload Raw Back to root
1---2license: apache-2.03widget:4- text: "<|endoftext|>\ndef load_excel(path):\n    return pd.read_excel(path)\n# docstring\n\"\"\""5---6 7## Basic info8 9model based [Salesforce/codegen-350M-mono](https://huggingface.co/Salesforce/codegen-350M-mono)10 11fine-tuned with data [codeparrot/github-code-clean](https://huggingface.co/datasets/codeparrot/github-code-clean)12 13data filter by python14 15## Usage16 17```python18from transformers import AutoTokenizer, AutoModelForCausalLM19 20model_type = 'kdf/python-docstring-generation'21tokenizer = AutoTokenizer.from_pretrained(model_type)22model = AutoModelForCausalLM.from_pretrained(model_type)23 24inputs = tokenizer('''<|endoftext|>25def load_excel(path):26    return pd.read_excel(path)27 28# docstring29"""''', return_tensors='pt')30 31doc_max_length = 12832 33generated_ids = model.generate(34    **inputs,35    max_length=inputs.input_ids.shape[1] + doc_max_length,36    do_sample=False,37    return_dict_in_generate=True,38    num_return_sequences=1,39    output_scores=True,40    pad_token_id=50256,41    eos_token_id=50256  # <|endoftext|>42)43 44ret = tokenizer.decode(generated_ids.sequences[0], skip_special_tokens=False)45print(ret)46 47```48 49## Prompt50 51You could give model a style or a specific language, for example:52 53```python54inputs = tokenizer('''<|endoftext|>55def add(a, b):56    return a + b57 58# docstring59"""60    Calculate numbers add.61 62    Args:63        a: the first number to add64        b: the second number to add65 66    Return:67        The result of a + b68"""69<|endoftext|>70def load_excel(path):71    return pd.read_excel(path)72 73# docstring74"""''', return_tensors='pt')75 76doc_max_length = 12877 78generated_ids = model.generate(79    **inputs,80    max_length=inputs.input_ids.shape[1] + doc_max_length,81    do_sample=False,82    return_dict_in_generate=True,83    num_return_sequences=1,84    output_scores=True,85    pad_token_id=50256,86    eos_token_id=50256  # <|endoftext|>87)88 89ret = tokenizer.decode(generated_ids.sequences[0], skip_special_tokens=False)90print(ret)91 92inputs = tokenizer('''<|endoftext|>93def add(a, b):94    return a + b95 96# docstring97"""98    计算数字相加99 100    Args:101        a: 第一个加数102        b: 第二个加数103 104    Return:105        相加的结果106"""107<|endoftext|>108def load_excel(path):109    return pd.read_excel(path)110 111# docstring112"""''', return_tensors='pt')113 114doc_max_length = 128115 116generated_ids = model.generate(117    **inputs,118    max_length=inputs.input_ids.shape[1] + doc_max_length,119    do_sample=False,120    return_dict_in_generate=True,121    num_return_sequences=1,122    output_scores=True,123    pad_token_id=50256,124    eos_token_id=50256  # <|endoftext|>125)126 127ret = tokenizer.decode(generated_ids.sequences[0], skip_special_tokens=False)128print(ret)129```