初始化项目,由ModelHub XC社区提供模型
Model: shibing624/code-autocomplete-distilgpt2-python Source: Original Platform
This commit is contained in:
28
.gitattributes
vendored
Normal file
28
.gitattributes
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
model.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
140
README.md
Normal file
140
README.md
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
---
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
tags:
|
||||||
|
- code
|
||||||
|
- autocomplete
|
||||||
|
- pytorch
|
||||||
|
- en
|
||||||
|
license: apache-2.0
|
||||||
|
library_name: transformers
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
widget:
|
||||||
|
- text: import torch.nn as
|
||||||
|
---
|
||||||
|
|
||||||
|
# GPT2 for Code AutoComplete Model
|
||||||
|
code-autocomplete, a code completion plugin for Python.
|
||||||
|
|
||||||
|
**code-autocomplete** can automatically complete the code of lines and blocks with GPT2.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Open source repo:[code-autocomplete](https://github.com/shibing624/code-autocomplete),support GPT2 model, usage:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from autocomplete.gpt2_coder import GPT2Coder
|
||||||
|
|
||||||
|
m = GPT2Coder("shibing624/code-autocomplete-distilgpt2-python")
|
||||||
|
print(m.generate('import torch.nn as')[0])
|
||||||
|
```
|
||||||
|
|
||||||
|
Also, use huggingface/transformers:
|
||||||
|
|
||||||
|
*Please use 'GPT2' related functions to load this model!*
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
||||||
|
|
||||||
|
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
||||||
|
|
||||||
|
tokenizer = GPT2Tokenizer.from_pretrained("shibing624/code-autocomplete-distilgpt2-python")
|
||||||
|
model = GPT2LMHeadModel.from_pretrained("shibing624/code-autocomplete-distilgpt2-python")
|
||||||
|
|
||||||
|
prompts = [
|
||||||
|
"""from torch import nn
|
||||||
|
class LSTM(Module):
|
||||||
|
def __init__(self, *,
|
||||||
|
n_tokens: int,
|
||||||
|
embedding_size: int,
|
||||||
|
hidden_size: int,
|
||||||
|
n_layers: int):""",
|
||||||
|
"""import numpy as np
|
||||||
|
import torch
|
||||||
|
import torch.nn as""",
|
||||||
|
"import java.util.ArrayList",
|
||||||
|
"def factorial(n):",
|
||||||
|
]
|
||||||
|
for prompt in prompts:
|
||||||
|
input_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors='pt')
|
||||||
|
outputs = model.generate(input_ids=input_ids,
|
||||||
|
max_length=64 + len(prompt),
|
||||||
|
temperature=1.0,
|
||||||
|
top_k=50,
|
||||||
|
top_p=0.95,
|
||||||
|
repetition_penalty=1.0,
|
||||||
|
do_sample=True,
|
||||||
|
num_return_sequences=1,
|
||||||
|
length_penalty=2.0,
|
||||||
|
early_stopping=True)
|
||||||
|
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
||||||
|
print(decoded)
|
||||||
|
print("=" * 20)
|
||||||
|
```
|
||||||
|
|
||||||
|
output:
|
||||||
|
```shell
|
||||||
|
from torch import nn
|
||||||
|
class LSTM(Module):
|
||||||
|
def __init__(self, *,
|
||||||
|
n_tokens: int,
|
||||||
|
embedding_size: int,
|
||||||
|
hidden_size: int,
|
||||||
|
n_layers: int):
|
||||||
|
self.embedding_size = embedding_size
|
||||||
|
====================
|
||||||
|
import numpy as np
|
||||||
|
import torch
|
||||||
|
import torch.nn as nn
|
||||||
|
import torch.nn.functional as F
|
||||||
|
```
|
||||||
|
|
||||||
|
Model files:
|
||||||
|
```
|
||||||
|
code-autocomplete-distilgpt2-python
|
||||||
|
├── config.json
|
||||||
|
├── merges.txt
|
||||||
|
├── pytorch_model.bin
|
||||||
|
├── special_tokens_map.json
|
||||||
|
├── tokenizer_config.json
|
||||||
|
└── vocab.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### Train data
|
||||||
|
#### pytorch_awesome projects source code
|
||||||
|
|
||||||
|
download [code-autocomplete](https://github.com/shibing624/code-autocomplete),
|
||||||
|
```shell
|
||||||
|
cd autocomplete
|
||||||
|
python create_dataset.py
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want train code-autocomplete GPT2 model,refer [https://github.com/shibing624/code-autocomplete/blob/main/autocomplete/gpt2_coder.py](https://github.com/shibing624/code-autocomplete/blob/main/autocomplete/gpt2_coder.py)
|
||||||
|
|
||||||
|
|
||||||
|
### About GPT2
|
||||||
|
|
||||||
|
Test the whole generation capabilities here: https://transformer.huggingface.co/doc/gpt2-large
|
||||||
|
|
||||||
|
Pretrained model on English language using a causal language modeling (CLM) objective. It was introduced in
|
||||||
|
[this paper](https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
|
||||||
|
and first released at [this page](https://openai.com/blog/better-language-models/).
|
||||||
|
|
||||||
|
Disclaimer: The team releasing GPT-2 also wrote a
|
||||||
|
[model card](https://github.com/openai/gpt-2/blob/master/model_card.md) for their model. Content from this model card
|
||||||
|
has been written by the Hugging Face team to complete the information they provided and give specific examples of bias.
|
||||||
|
|
||||||
|
|
||||||
|
## Citation
|
||||||
|
|
||||||
|
```latex
|
||||||
|
@misc{code-autocomplete,
|
||||||
|
author = {Xu Ming},
|
||||||
|
title = {code-autocomplete: Code AutoComplete with GPT model},
|
||||||
|
year = {2022},
|
||||||
|
publisher = {GitHub},
|
||||||
|
journal = {GitHub repository},
|
||||||
|
url = {https://github.com/shibing624/code-autocomplete},
|
||||||
|
}
|
||||||
|
```
|
||||||
44
config.json
Normal file
44
config.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"_name_or_path": "distilgpt2",
|
||||||
|
"_num_labels": 1,
|
||||||
|
"activation_function": "gelu_new",
|
||||||
|
"architectures": [
|
||||||
|
"GPT2LMHeadModel"
|
||||||
|
],
|
||||||
|
"attn_pdrop": 0.1,
|
||||||
|
"bos_token_id": 50256,
|
||||||
|
"embd_pdrop": 0.1,
|
||||||
|
"eos_token_id": 50256,
|
||||||
|
"id2label": {
|
||||||
|
"0": "LABEL_0"
|
||||||
|
},
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"label2id": {
|
||||||
|
"LABEL_0": 0
|
||||||
|
},
|
||||||
|
"layer_norm_epsilon": 1e-05,
|
||||||
|
"model_type": "gpt2",
|
||||||
|
"n_ctx": 1024,
|
||||||
|
"n_embd": 768,
|
||||||
|
"n_head": 12,
|
||||||
|
"n_inner": null,
|
||||||
|
"n_layer": 6,
|
||||||
|
"n_positions": 1024,
|
||||||
|
"reorder_and_upcast_attn": false,
|
||||||
|
"resid_pdrop": 0.1,
|
||||||
|
"scale_attn_by_inverse_layer_idx": false,
|
||||||
|
"scale_attn_weights": true,
|
||||||
|
"summary_activation": null,
|
||||||
|
"summary_first_dropout": 0.1,
|
||||||
|
"summary_proj_to_labels": true,
|
||||||
|
"summary_type": "cls_index",
|
||||||
|
"summary_use_proj": true,
|
||||||
|
"task_specific_params": {
|
||||||
|
"text-generation": {
|
||||||
|
"do_sample": true,
|
||||||
|
"max_length": 50
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"torch_dtype": "float32",
|
||||||
|
"vocab_size": 50257
|
||||||
|
}
|
||||||
2
eval_results.txt
Normal file
2
eval_results.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
eval_loss = 1.186014711856842
|
||||||
|
perplexity = tensor(3.2740)
|
||||||
50001
merges.txt
Normal file
50001
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:cf0a57f0364f4544d7aee947972f8db7e2d44a4678ba7a08ea423190f19d7234
|
||||||
|
size 333950622
|
||||||
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:b552bf4a83162ab3fa5c9255ee3bc0d25cc1b6eda2b0c73f7434d6096c8a0f01
|
||||||
|
size 333972957
|
||||||
1
special_tokens_map.json
Normal file
1
special_tokens_map.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}}
|
||||||
1
tokenizer_config.json
Normal file
1
tokenizer_config.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"errors": "replace", "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "do_lower_case": false, "model_max_length": 1024, "special_tokens_map_file": null, "name_or_path": "distilgpt2", "tokenizer_class": "GPT2Tokenizer"}
|
||||||
1
vocab.json
Normal file
1
vocab.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user