Locutusque commited on
Commit
d3bd80b
1 Parent(s): dc0b02e

Upload 8 files

Browse files
README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: openrail
3
+ datasets:
4
+ - Locutusque/ColumnedChatCombined
5
+ language:
6
+ - en
7
+ - zh
8
+ - ru
9
+ metrics:
10
+ - bleu
11
+ - perplexity
12
+ - loss
13
+ - reward
14
+ - penalty
15
+ pipeline_tag: text-generation
16
+ ---
17
+ # Model Card
18
+ ## Model Details
19
+ - Model Name: gpt2-medium-conversational
20
+ - Model Type: Language Modeling
21
+ - Task: Generating Conversational Responses
22
+ - 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.
23
+ ## Intended Use
24
+ 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.
25
+
26
+ ## Training Data
27
+ 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 100,000 examples over 250,000 steps, it achieved decent metrics.
28
+ ## Model Architecture
29
+ 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 transformer encoder-decoder, with self-attention mechanisms that allow the model to capture long-term dependencies and generate coherent text.
30
+
31
+ ## Evaluation Metrics
32
+ 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:
33
+
34
+ - BLEU score: 11.4
35
+ - perplexity: 125
36
+ - loss: 3.8
37
+
38
+ ## Limitations and Bias
39
+ 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, we recommend using a GPU with at least 10GB of VRAM and downloading the model manually instead of using the Transformers library. Here's how you should deploy the model:
40
+
41
+ ```python
42
+ import torch
43
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
44
+
45
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2-medium')
46
+ model = GPT2LMHeadModel.from_pretrained('gpt2-medium')
47
+ tokenizer.add_special_tokens({'pad_token': '[PAD]'})
48
+ tokenizer.add_special_tokens({'eos_token': '<|End|>'})
49
+ special_tokens = {
50
+ "additional_special_tokens": ["<|USER|>", "<|SYSTEM|>", "<|ASSISTANT|>"]
51
+ }
52
+ tokenizer.add_special_tokens(special_tokens)
53
+ model.resize_token_embeddings(len(tokenizer))
54
+ model.load_state_dict(torch.load("path/to/model"))
55
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
56
+ model.to(device)
57
+ def generate_text(model, tokenizer, prompt, max_length=256):
58
+ prompt = f'<|USER|> {prompt} <|ASSISTANT|> '
59
+ input_ids = tokenizer.encode(prompt, add_special_tokens=True, return_tensors="pt").to(device)
60
+ attention_mask = torch.ones_like(input_ids).to(device)
61
+ output = model.generate(input_ids,
62
+ max_length=max_length,
63
+ do_sample=True,
64
+ top_k=35,
65
+ top_p=0.80,
66
+ pad_token_id=tokenizer.pad_token_id,
67
+ eos_token_id=tokenizer.eos_token_id,
68
+ attention_mask=attention_mask)
69
+ output_ids = tokenizer.decode(output[0], skip_special_tokens=False)
70
+ assistant_token_index = output_ids.index('<|ASSISTANT|>') + len('<|ASSISTANT|>')
71
+ next_token_index = output_ids.find('<|', assistant_token_index)
72
+ output_ids = output_ids[assistant_token_index:next_token_index]
73
+ return output_ids
74
+ # Loop to interact with the model
75
+ while True:
76
+ prompt = input("Enter a prompt (or 'q' to quit): ")
77
+ if prompt == "q":
78
+ break
79
+ output_text = generate_text(model, tokenizer, prompt)
80
+ print(output_text)
81
+ ```
82
+ ## Deploying and training the model
83
+ The model has been fine-tuned on a specific input format that goes like this ```"<|USER|> {user prompt} <|ASSISTANT|> {model prediction} <|End|>".``` 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} <|End|>```
added_tokens.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "<mask>": 50261,
3
+ "<|ASSISTANT|>": 50259,
4
+ "<|End|>": 50258,
5
+ "<|USER|>": 50260,
6
+ "[PAD]": 50257
7
+ }
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2-medium",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 1024,
16
+ "n_head": 16,
17
+ "n_inner": null,
18
+ "n_layer": 24,
19
+ "n_positions": 1024,
20
+ "n_special": 0,
21
+ "predict_special_tokens": true,
22
+ "reorder_and_upcast_attn": false,
23
+ "resid_pdrop": 0.1,
24
+ "scale_attn_by_inverse_layer_idx": false,
25
+ "scale_attn_weights": true,
26
+ "summary_activation": null,
27
+ "summary_first_dropout": 0.1,
28
+ "summary_proj_to_labels": true,
29
+ "summary_type": "cls_index",
30
+ "summary_use_proj": true,
31
+ "task_specific_params": {
32
+ "text-generation": {
33
+ "do_sample": true,
34
+ "max_length": 50
35
+ }
36
+ },
37
+ "torch_dtype": "float32",
38
+ "transformers_version": "4.28.1",
39
+ "use_cache": true,
40
+ "vocab_size": 50262
41
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.28.1"
6
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c7bcf0b889bbac6caacd033a41abe2016064ac8f197859783ce831d891847f00
3
+ size 1444589853
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|ASSISTANT|>",
4
+ "<|USER|>",
5
+ "<|End|>",
6
+ "<mask>"
7
+ ],
8
+ "bos_token": {
9
+ "content": "<|endoftext|>",
10
+ "lstrip": false,
11
+ "normalized": true,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ },
15
+ "eos_token": "<|End|>",
16
+ "pad_token": "[PAD]",
17
+ "unk_token": {
18
+ "content": "<|endoftext|>",
19
+ "lstrip": false,
20
+ "normalized": true,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "bos_token": {
5
+ "__type": "AddedToken",
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "clean_up_tokenization_spaces": true,
13
+ "eos_token": {
14
+ "__type": "AddedToken",
15
+ "content": "<|endoftext|>",
16
+ "lstrip": false,
17
+ "normalized": true,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "errors": "replace",
22
+ "model_max_length": 1024,
23
+ "pad_token": null,
24
+ "tokenizer_class": "GPT2Tokenizer",
25
+ "unk_token": {
26
+ "__type": "AddedToken",
27
+ "content": "<|endoftext|>",
28
+ "lstrip": false,
29
+ "normalized": true,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff