File size: 11,806 Bytes
9f55278 b953f93 97dd7a1 97c8648 9f55278 b6685a4 ebf3926 9f55278 97c8648 9f55278 ebf3926 9f55278 ebf3926 9f55278 ebf3926 9f55278 ebf3926 9f55278 ebf3926 9f55278 ebf3926 9f55278 e66fc88 9f55278 904b9ac 9f55278 904b9ac 9f55278 904b9ac 9f55278 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
---
language: en
thumbnail: >-
https://raw.githubusercontent.com/SpeedStar1O1/discord-bots/main/VergilpluseGPT2.png?token=GHSAT0AAAAAACC53HUTBR6T2QVILOHJ275QZD5AL4A
tags:
- gpt2
- dialogue
- response generation
- transformers
- pytorch
- text-generation
- conversational
- question-answering
license: mit
datasets:
- allenai/soda
- allenai/prosocial-dialog
- vicgalle/alpaca-gpt4
- conv_ai
- conv_ai_2
- conv_ai_3
metrics:
- accuracy
pipeline_tag: text-generation
---
Note: As of current writing this model is still under development.
## VergilGPT2
VergilGPT2 is an exceptional model harnessing the power of the renowned gpt2 architecture. It has undergone meticulous training on multiple datasets, including allenai/soda, allenai/prosocial-dialog, vicgalle/alpaca-gpt4, conv_ai, conv_ai_2, and conv_ai_3, using Google Collaboratory. This expansive training allows VergilGPT2 to excel as an interactive chatbot, delivering remarkable responses and engaging in meaningful conversations.
The incorporation of diverse datasets enriches VergilGPT2's capabilities. Among them, the allenai/soda dataset serves as a foundational pillar, offering an extensive corpus of conversational dialogue. With an impressive collection of 1.19 million training lines, 149,000 test lines, and 146,000 validation lines, this dataset provides a robust framework for fostering natural and coherent interactions. Spanning a file size of 856 MB, the dataset encompasses a wide range of conversational scenarios, ensuring comprehensive training.
Driven by the cutting-edge gpt2 model architecture and the rich context provided by multiple datasets, VergilGPT2 generates responses that exhibit fluency, coherence, and relevance. Its training on extensive conversational data enables it to capture the intricacies of human interaction, facilitating engaging and interactive experiences.
VergilGPT2 stands as a testament to the advancements in conversational AI, embodying the fusion of cutting-edge technology, meticulous training, and the diverse knowledge contained within the multiple datasets. This remarkable model holds immense potential for various applications, such as virtual assistants, dialogue systems, and interactive chatbot experiences.
While VergilGPT2 showcases impressive conversational capabilities, it is important to note that, like all language models, its responses are generated based on patterns and examples from the training data. As a result, occasional inaccuracies or nonsensical outputs may occur. Therefore, it is advisable to interpret and verify its responses in context.
Unleash the power of VergilGPT2 and immerse yourself in dynamic and captivating conversations that push the boundaries of interactive AI experiences. Let the conversations unfold and discover the true potential of this extraordinary model.
## Engaging with Vergil
If you're eager to have a conversation with VergilGPT2, you can utilize the following code snippet. Feel free to experiment with the variables 'temperature', 'top_k', 'top_p', to customize the response generation according to your preferences.
```python
import torch
import re
import random
from transformers import AutoTokenizer, AutoModelForCausalLM
def filter_english_words(text):
# Initialize an empty list to store the filtered words
filtered_text = []
# Split the input text into individual words
words = text.split()
# Iterate through the words
for word in words:
# Check if the word is a valid English word or a punctuation
if word.isalpha() or re.match(r'^[!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~]$', word):
# If it is, append it to the filtered text list
filtered_text.append(word)
# Return the filtered text as a string
return ' '.join(filtered_text)
def generate_response(model, tokenizer, input_text, max_length=300, min_length=20, num_return_sequences=1, temperature=0.2, top_k=50, top_p=0.9, num_beams=10, repetition_penalty=1.0):
input_ids = tokenizer.encode(input_text, return_tensors='pt')
# Set model to eval mode
model.eval()
# Generate responses using different decoding strategies
try:
output = model.generate(
input_ids=input_ids,
max_length=max_length,
min_length=min_length,
num_return_sequences=num_return_sequences,
temperature=temperature,
top_k=top_k,
top_p=top_p,
num_beams=num_beams,
no_repeat_ngram_size=2,
do_sample=True,
repetition_penalty=repetition_penalty # Added repetition_penalty
)
# Decode the generated responses
responses = [tokenizer.decode(o, skip_special_tokens=True) for o in output]
# Remove input_text from the responses
responses = [response[len(tokenizer.decode(input_ids[0], skip_special_tokens=True)):] for response in responses]
# Filter out non-English words
responses = [filter_english_words(response) for response in responses]
return responses
except RuntimeError:
return ["I'm sorry, I encountered an error while generating a response."]
# Load pre-trained model and tokenizer
access_token = "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"
model_id = "Starcodium/VergilGPT2"
tokenizer = AutoTokenizer.from_pretrained(model_id, revision="main", use_auth_token=access_token)
model = AutoModelForCausalLM.from_pretrained(model_id, revision="main", use_auth_token=access_token)
tokenizer.pad_token = tokenizer.eos_token
model.config.pad_token_id = model.config.eos_token_id
# Get user input and generate responses
while True:
input_text = input("Type 'quit' or 'exit' to stop runtime.\nEnter your input text: ")
if input_text.lower() in ["quit", "exit"]:
break
responses = generate_response(model, tokenizer, input_text, max_length=100, min_length=20, num_return_sequences=1, temperature=0.7, top_k=40, top_p=0.5, num_beams=1, repetition_penalty=1.2)
responses = [r for r in responses if r.strip() != '']
if responses:
response = responses[0]
else:
response = "I'm sorry, I don't have a response at the moment."
# Print the bot's response
print("Vergil: "+response)
```
This code snippet allows you to engage in conversations with VergilGPT2. Simply enter your input text, and VergilGPT2 will generate responses based on the provided context. Experiment with different values of the variables temperature, top_k, and top_p to customize the response generation process according to your desired preferences.
Please note that the code assumes you have access to the Starcodium/VergilGPT2 model and its associated tokenizer. Ensure you have the required authentication token (access_token) to access the model and tokenizer.
## Installation
Make sure to install the required dependencies by running the following commands:
(Note these installations were done in google collaboratory, if you are installing them on your local PC take out the '!')
```python
!pip install torch
!pip install datasets
!pip install transformers==4.29.2
!pip install tokenizers==0.13.3
!pip install toml==0.10.2
!pip install accelerate
```
## Training Example
To train a model on a dataset, you can use the following example:
```python
from datasets import load_dataset
dataset = load_dataset("allenai/soda")
```
In this example, we load the allenai/soda conversational dataset.
## Loading the Model
To load the original GPT2 model for training, you can use the following example:
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
```
To load the GPT2 model with the allenai/soda dataset, follow this example:
```python
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer, GPT2Config
from transformers import TextDataset, DataCollatorForLanguageModeling
from transformers import Trainer, TrainingArguments
from sklearn.model_selection import train_test_split
from datasets import load_dataset
from accelerate import Accelerator
# Define the model and tokenizer
model_name = "gpt2"
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPT2LMHeadModel.from_pretrained(model_name)
# Preprocess the dataset
def preprocess_dataset(example):
inputs = f"USER: {example['dialogue'][-2]} \nASSISTANT: {example['dialogue'][-1]}"
outputs = example['dialogue'][1:-1]
return {'inputs': inputs, 'outputs': outputs}
# Load and preprocess the dataset
dataset = load_dataset("allenai/soda")
dataset = dataset.map(preprocess_dataset)
```
## Loading & Training VergilGPT2
To load the VergilGPT2 model for training, you can use the following example:
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "VergilGPT2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
```
To load the VergilGPT2 model with the allenai/soda dataset, follow this example:
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from transformers import TextDataset, DataCollatorForLanguageModeling
from transformers import Trainer, TrainingArguments
from sklearn.model_selection import train_test_split
from datasets import load_dataset
from accelerate import Accelerator
# Define the model and tokenizer
model_name = "VergilGPT2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Preprocess the dataset
def preprocess_dataset(example):
inputs = f"USER: {example['dialogue'][-2]} \nASSISTANT: {example['dialogue'][-1]}"
outputs = example['dialogue'][1:-1]
return {'inputs': inputs, 'outputs': outputs}
# Load and preprocess the dataset
dataset = load_dataset("allenai/soda")
dataset = dataset.map(preprocess_dataset)
# Split the dataset into training and validation sets
train_dataset, val_dataset = train_test_split(dataset['train'], test_size=0.1, shuffle=True)
```
It is worth noting that VergilGPT2 is already trained on the allenai/soda dataset so in actual training be sure to change the conversational dialogue.
## Text Files
You can create an instance where your code can create text files so you can continue tarining and create check points:
```python
# Extract the 'text' column from the train_dataset and val_dataset
train_texts = train_dataset['inputs']
val_texts = val_dataset['inputs']
# Write train_texts to a text file
train_file = "train_texts.txt"
with open(train_file, 'w', encoding='utf-8') as f:
for text in train_texts:
f.write(text + '\n')
# Write val_texts to a text file
val_file = "val_texts.txt"
with open(val_file, 'w', encoding='utf-8') as f:
for text in val_texts:
f.write(text + '\n')
```
## Training Arguments
You can use these training arguments to train & fine-tune your model.
```python
# Define the training arguments
training_args = TrainingArguments(
output_dir=output_dir,
overwrite_output_dir=True,
num_train_epochs=3,
per_device_train_batch_size=4,
save_steps=500,
save_total_limit=2,
learning_rate=2e-5,
prediction_loss_only=True,
)
# Create the data collator
data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)
# Create the Accelerator instance
accelerator = Accelerator()
# Create the Trainer instance
trainer = Trainer(
model=model.to(accelerator.device),
args=training_args,
data_collator=data_collator,
train_dataset=train_text_dataset,
eval_dataset=val_text_dataset,
)
# Fine-tune the model
trainer = accelerator.prepare(trainer)
trainer.train()
# Save the fine-tuned model
trainer.save_model(output_dir)
``` |