初始化项目,由ModelHub XC社区提供模型
Model: Locutusque/gpt2-large-conversational Source: Original Platform
This commit is contained in:
34
.gitattributes
vendored
Normal file
34
.gitattributes
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt 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
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz 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
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl 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
|
||||
*.safetensors 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
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
103
README.md
Normal file
103
README.md
Normal file
@@ -0,0 +1,103 @@
|
||||
---
|
||||
license: openrail
|
||||
datasets:
|
||||
- Locutusque/ColumnedChatCombined
|
||||
- crumb/Clean-Instruct-440k
|
||||
language:
|
||||
- en
|
||||
metrics:
|
||||
- bleu
|
||||
- perplexity
|
||||
- loss
|
||||
- reward
|
||||
- penalty
|
||||
pipeline_tag: text-generation
|
||||
inference:
|
||||
parameters:
|
||||
temperature: 0.8
|
||||
top_p: 0.14
|
||||
top_k: 41
|
||||
max_new_tokens: 250
|
||||
repetition_penalty: 1.176
|
||||
---
|
||||
# Model Card
|
||||
* this model is deprecated, please see https://huggingface.co/Locutusque/gpt2-large-conversational-retrain for a better performing model.
|
||||
## Model Details
|
||||
- Model Name: gpt2-large-conversational
|
||||
- Model Type: Language Modeling
|
||||
- Task: Generating Conversational Responses
|
||||
- Hardware: 1x Nvidia Titan V
|
||||
- Description: This model is trained on a dataset of conversations between a user and an AI assistant, with the goal of generating a coherent and relevant response to the user's input. It uses the GPT-2 architecture, a state-of-the-art transformer-based language model that is capable of generating high-quality text with a wide range of styles and tones. The model is fine-tuned on the conversational data using maximum likelihood estimation, and is evaluated based on its ability to generate responses that are both grammatically correct and semantically relevant to the user's input.
|
||||
## Intended Use
|
||||
This model is intended to be used for generating conversational responses in a variety of contexts, such as chatbots, virtual assistants, and customer service applications. It is designed to provide natural and engaging responses to user input, with a focus on maintaining a consistent tone and style throughout the conversation. The model is suitable for use in both text-based and voice-based interfaces, and can be easily integrated into existing applications using the PyTorch and Transformers frameworks.
|
||||
|
||||
## Training Data
|
||||
The model is trained on a large dataset of conversational data, consisting of interactions between users and an AI assistant. The data is preprocessed to remove any sensitive information and is formatted in a way that is suitable for training a language model. The training data is split into a training set and a validation set, with the training set used to update the model parameters and the validation set used to evaluate the model performance. The model was trained on 550,000 examples over 687,500 steps, it achieved decent metrics.
|
||||
## Model Architecture
|
||||
The model architecture used in this model is GPT-2, a transformer-based language model that is capable of generating high-quality text with a wide range of styles and tones. The GPT-2 architecture consists of a multi-layered decoder-only transformer, with self-attention mechanisms that allow the model to capture long-term dependencies and generate coherent text.
|
||||
|
||||
## Evaluation Metrics
|
||||
The model is evaluated based on several metrics, including loss, reward, penalty, BLEU score, and perplexity. The loss metric is calculated during training and reflects the difference between the predicted output and the actual output. The reward metric is based on the number of correct words generated by the model, while the penalty metric penalizes the model for repeating words consecutively. The BLEU score measures the similarity between the generated text and the ground truth text, while the perplexity metric measures how well the model is able to predict the next word in a sequence. During validation, the model achieved the following metrics:
|
||||
|
||||
- BLEU score: 12
|
||||
- perplexity: 38
|
||||
- loss: 3.1
|
||||
|
||||
## Limitations and Bias
|
||||
This model is not suitable for all use cases due to its limited training time on a weak computer. As a result, it may produce irrelevant or nonsensical responses. Additionally, it has not been fine-tuned to remember the chat history, is unable to provide follow-up responses, and it does not know the answer to many questions (it was only fine-tuned to respond in a conversational way). For optimal performance, I recommend using a GPU with at least 12 GB of VRAM and downloading the model manually instead of using the Transformers library. Here's how you should deploy the model:
|
||||
|
||||
```python
|
||||
import torch
|
||||
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
||||
start_token = "<|ASSISTANT|>"
|
||||
end_token = "<|"
|
||||
tokenizer = GPT2Tokenizer.from_pretrained('gpt2-large')
|
||||
model = GPT2LMHeadModel.from_pretrained('gpt2-large')
|
||||
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
||||
special_tokens = {
|
||||
"additional_special_tokens": ["<|USER|>", "<|ASSISTANT|>"]
|
||||
}
|
||||
tokenizer.add_special_tokens(special_tokens)
|
||||
model.resize_token_embeddings(len(tokenizer))
|
||||
model.load_state_dict(torch.load("path/to/model"))
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
model.to(device)
|
||||
def generate_text(model, tokenizer, prompt, max_length=256):
|
||||
prompt = f'<|USER|> {prompt} <|ASSISTANT|> '
|
||||
input_ids = tokenizer.encode(prompt, add_special_tokens=True, return_tensors="pt").to(device)
|
||||
attention_mask = torch.ones_like(input_ids).to(device)
|
||||
output = model.generate(input_ids,
|
||||
max_length=max_length,
|
||||
do_sample=True,
|
||||
top_k=35,
|
||||
top_p=0.80,
|
||||
pad_token_id=tokenizer.pad_token_id,
|
||||
eos_token_id=tokenizer.eos_token_id,
|
||||
attention_mask=attention_mask)
|
||||
output_ids = tokenizer.decode(output[0], skip_special_tokens=False)
|
||||
return output_ids
|
||||
# Loop to interact with the model
|
||||
while True:
|
||||
prompt = input("Enter a prompt (or 'q' to quit): ")
|
||||
if prompt == "q":
|
||||
break
|
||||
output_text = generate_text(model, tokenizer, prompt)
|
||||
text_between_tokens = output_text[output_text.find(start_token) + len(start_token):]
|
||||
out = text_between_tokens[:text_between_tokens.find(end_token)]
|
||||
print(out)
|
||||
```
|
||||
## Deploying and training the model
|
||||
The model has been fine-tuned on a specific input format that goes like this ```"<|USER|> {user prompt} <|ASSISTANT|> {model prediction} ".``` For the best performance from the model the input text should be as follows ```<|USER|> {dataset prompt} <|ASSISTANT|> ``` and the target/label should be as follows ```<|USER|> {dataset prompt} <|ASSISTANT|> {dataset output} ```. This model is also very fun to play with in text generation webui
|
||||
# [Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
|
||||
Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_Locutusque__gpt2-large-conversational)
|
||||
|
||||
| Metric | Value |
|
||||
|-----------------------|---------------------------|
|
||||
| Avg. | 28.45 |
|
||||
| ARC (25-shot) | 26.96 |
|
||||
| HellaSwag (10-shot) | 44.98 |
|
||||
| MMLU (5-shot) | 26.33 |
|
||||
| TruthfulQA (0-shot) | 39.6 |
|
||||
| Winogrande (5-shot) | 56.04 |
|
||||
| GSM8K (5-shot) | 0.08 |
|
||||
| DROP (3-shot) | 5.19 |
|
||||
5
added_tokens.json
Normal file
5
added_tokens.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"<|ASSISTANT|>": 50257,
|
||||
"<|SYSTEM|>": 50259,
|
||||
"<|USER|>": 50258
|
||||
}
|
||||
39
config.json
Normal file
39
config.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"_name_or_path": "gpt2-large",
|
||||
"activation_function": "gelu_new",
|
||||
"architectures": [
|
||||
"GPT2LMHeadModel"
|
||||
],
|
||||
"attn_pdrop": 0.1,
|
||||
"bos_token_id": 50256,
|
||||
"embd_pdrop": 0.1,
|
||||
"eos_token_id": 50256,
|
||||
"initializer_range": 0.02,
|
||||
"layer_norm_epsilon": 1e-05,
|
||||
"model_type": "gpt2",
|
||||
"n_ctx": 1024,
|
||||
"n_embd": 1280,
|
||||
"n_head": 20,
|
||||
"n_inner": null,
|
||||
"n_layer": 36,
|
||||
"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": "bfloat16",
|
||||
"transformers_version": "4.30.1",
|
||||
"use_cache": true,
|
||||
"vocab_size": 50260
|
||||
}
|
||||
6
generation_config.json
Normal file
6
generation_config.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"_from_model_config": true,
|
||||
"bos_token_id": 50256,
|
||||
"eos_token_id": 50256,
|
||||
"transformers_version": "4.30.1"
|
||||
}
|
||||
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:158da0a28e2493a334e198751904c884a84dcae069d608072044bbb1280d404a
|
||||
size 1548113536
|
||||
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:bb0207e27054d22f3a930cd13d66f76dec16ab81352bbc7825774a288f395a16
|
||||
size 1548210205
|
||||
38
run_model.py
Normal file
38
run_model.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import torch
|
||||
from transformers import GPT2Tokenizer, AutoModelForCausalLM
|
||||
start_token = "<|ASSISTANT|>"
|
||||
end_token = "<|"
|
||||
tokenizer = GPT2Tokenizer.from_pretrained('gpt2-large')
|
||||
model = AutoModelForCausalLM.from_pretrained('gpt2-large', torch_dtype=torch.bfloat16)
|
||||
tokenizer.pad_token = "[PAD]"
|
||||
tokenizer.eos_token = "<|endoftext|>"
|
||||
tokenizer.add_special_tokens({"additional_special_tokens": ["<|ASSISTANT|>", "<|USER|>", "<|SYSTEM|>"]})
|
||||
model.resize_token_embeddings(len(tokenizer))
|
||||
model.load_state_dict(torch.load("/media/locutusque/T7/Projects/results/pytorch_model.bin"))
|
||||
model.cuda()
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
def generate_text(model, tokenizer, prompt, max_length=1024):
|
||||
prompt = f'<|USER|> {prompt} <|ASSISTANT|> '
|
||||
input_ids = tokenizer.encode(prompt, add_special_tokens=True, return_tensors="pt").to(device)
|
||||
attention_mask = torch.ones_like(input_ids).to(device)
|
||||
output = model.generate(input_ids,
|
||||
max_length=max_length,
|
||||
do_sample=True,
|
||||
top_k=0,
|
||||
top_p=0.1,
|
||||
temperature=0.75,
|
||||
repetition_penalty=1.176,
|
||||
pad_token_id=tokenizer.pad_token_id,
|
||||
eos_token_id=tokenizer.eos_token_id,
|
||||
attention_mask=attention_mask)
|
||||
output_ids = tokenizer.decode(output[0], skip_special_tokens=False)
|
||||
return output_ids
|
||||
# Loop to interact with the model
|
||||
while True:
|
||||
prompt = input("Enter a prompt (or 'q' to quit): ")
|
||||
if prompt == "q":
|
||||
break
|
||||
output_text = generate_text(model, tokenizer, prompt)
|
||||
text_between_tokens = output_text[output_text.find(start_token) + len(start_token):]
|
||||
out = text_between_tokens[:text_between_tokens.find(end_token)]
|
||||
print(out)
|
||||
11
special_tokens_map.json
Normal file
11
special_tokens_map.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"additional_special_tokens": [
|
||||
"<|ASSISTANT|>",
|
||||
"<|USER|>",
|
||||
"<|SYSTEM|>"
|
||||
],
|
||||
"bos_token": "<|endoftext|>",
|
||||
"eos_token": "<|endoftext|>",
|
||||
"pad_token": "[PAD]",
|
||||
"unk_token": "<|endoftext|>"
|
||||
}
|
||||
100337
tokenizer.json
Normal file
100337
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
9
tokenizer_config.json
Normal file
9
tokenizer_config.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"add_prefix_space": false,
|
||||
"bos_token": "<|endoftext|>",
|
||||
"clean_up_tokenization_spaces": true,
|
||||
"eos_token": "<|endoftext|>",
|
||||
"model_max_length": 1024,
|
||||
"tokenizer_class": "GPT2Tokenizer",
|
||||
"unk_token": "<|endoftext|>"
|
||||
}
|
||||
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