Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,188 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
model_type: GPT2LMHeadModel
|
3 |
+
architectures:
|
4 |
+
- GPT2LMHeadModel
|
5 |
+
model_filename: pytorch_model.bin
|
6 |
+
config:
|
7 |
+
activation_function: gelu_new
|
8 |
+
attn_pdrop: 0.1
|
9 |
+
bos_token_id: 50256
|
10 |
+
embd_pdrop: 0.1
|
11 |
+
eos_token_id: 50256
|
12 |
+
initializer_range: 0.02
|
13 |
+
layer_norm_epsilon: 1e-05
|
14 |
+
n_ctx: 256
|
15 |
+
n_embd: 256
|
16 |
+
n_head: 16
|
17 |
+
n_layer: 24
|
18 |
+
n_positions: 256
|
19 |
+
n_special: 0
|
20 |
+
predict_special_tokens: true
|
21 |
+
resid_pdrop: 0.1
|
22 |
+
summary_activation: null
|
23 |
+
summary_first_dropout: 0.1
|
24 |
+
summary_proj_to_labels: true
|
25 |
+
summary_type: cls_index
|
26 |
+
summary_use_proj: true
|
27 |
+
task_specific_params:
|
28 |
+
text-generation:
|
29 |
+
do_sample: true
|
30 |
+
max_length: 200
|
31 |
+
vocab_size: 100314
|
32 |
license: apache-2.0
|
33 |
+
datasets:
|
34 |
+
- vicgalle/alpaca-gpt4
|
35 |
+
language:
|
36 |
+
- en
|
37 |
+
metrics:
|
38 |
+
- bleu
|
39 |
+
- accuracy
|
40 |
+
library_name: transformers
|
41 |
+
pipeline_tag: text-generation
|
42 |
---
|
43 |
+
|
44 |
+
# QNetworkGPT2Mini: Reinventing Text Generation with AI ππ€
|
45 |
+
|
46 |
+
![Text Generation](https://static.vecteezy.com/system/resources/previews/023/477/674/non_2x/ai-generative-blue-red-ink-splash-illustration-free-png.png)
|
47 |
+
|
48 |
+
---
|
49 |
+
## Hyperameters used
|
50 |
+
|
51 |
+
Here's a consolidated list of hyperparameters for your QNetworkGPT2 RL model:
|
52 |
+
|
53 |
+
- `input_dim`: Input dimension for the RL agent.
|
54 |
+
- `output_dim`: Output dimension for the RL agent.
|
55 |
+
- `hidden_dim`: Hidden dimension for the RL agent.
|
56 |
+
- `num_episodes`: Number of training episodes.
|
57 |
+
- `generate_interval`: Interval for text generation during training.
|
58 |
+
- `load_path`: Path to load a pre-trained model.
|
59 |
+
- `model_name`: GPT-2 model architecture name.
|
60 |
+
- `max_new_tokens`: Maximum new tokens allowed during text generation.
|
61 |
+
- `max_length`: Maximum sequence length for input data.
|
62 |
+
- `sequence_length`: Length of sequences in the dataset.
|
63 |
+
- `batch_size`: Batch size for training.
|
64 |
+
- `learning_rate`: Learning rate for optimization.
|
65 |
+
- `gamma`: Discount factor for rewards.
|
66 |
+
- `clip_epsilon`: Epsilon value for policy loss clipping.
|
67 |
+
- `entropy_beta`: Beta value for entropy regularization.
|
68 |
+
- `epsilon_start`: Initial epsilon for epsilon-greedy exploration.
|
69 |
+
- `epsilon_end`: Minimum epsilon value.
|
70 |
+
- `epsilon_decay`: Epsilon decay rate.
|
71 |
+
- `heuristic_fn`: Heuristic function for action selection.
|
72 |
+
- `max_new_tokens`: Maximum new tokens allowed during text generation.
|
73 |
+
- `save_path`: Path to save the trained model.
|
74 |
+
|
75 |
+
Researchers can use these hyperparameters to configure and train their QNetworkGPT2 RL models effectively for text generation tasks.
|
76 |
+
---
|
77 |
+
---
|
78 |
+
|
79 |
+
## Overview
|
80 |
+
|
81 |
+
QNetworkGPT2 is an extraordinary AI model that marries Reinforcement Learning (RL) with the power of the GPT-2 language model to create impressive text generation experiences. π
|
82 |
+
|
83 |
+
## Capabilities
|
84 |
+
|
85 |
+
### 1. Ultimate Flexibility
|
86 |
+
- Craft RL agents for diverse text generation tasks.
|
87 |
+
- Customize hyperparameters effortlessly.
|
88 |
+
- Harness the brilliance of GPT-2 for text generation magic.
|
89 |
+
|
90 |
+
### 2. Q-Network for Mastery
|
91 |
+
- Unleash the QNetwork class for Q-learning in text generation.
|
92 |
+
- Revel in its multi-layer neural network architecture with residual connections and strategic dropout rates.
|
93 |
+
- Empower your model with heuristic functions for ingenious action selection.
|
94 |
+
|
95 |
+
### 3. PPO Algorithm
|
96 |
+
- Embrace the Proximal Policy Optimization (PPO) algorithm for supreme policy updates.
|
97 |
+
- Sculpt policies with the wisdom of experiences and rewards.
|
98 |
+
|
99 |
+
### 4. Tailored RL Environment
|
100 |
+
- Tailor-make your own RL environment for text generation quests.
|
101 |
+
- Reward the AI with BLEU scores and semantic similarity.
|
102 |
+
- Dance through text generation steps with episode-ending conditions.
|
103 |
+
|
104 |
+
### 5. Replay Buffer and Memory
|
105 |
+
- Store and summon experiences with grace in a replay buffer.
|
106 |
+
- Command a replay memory class to oversee experiences like a pro.
|
107 |
+
|
108 |
+
### 6. Epsilon-Greedy Exploration
|
109 |
+
- The agent employs epsilon-greedy exploration for marvelous discoveries.
|
110 |
+
|
111 |
+
### 7. Target Network for Rock-Solid Stability
|
112 |
+
- Keep target networks in check for unwavering stability during Q-learning escapades.
|
113 |
+
|
114 |
+
---
|
115 |
+
|
116 |
+
## How It Operates
|
117 |
+
|
118 |
+
1. Birth an RL Agent, fine-tuned to your desires.
|
119 |
+
2. Train the agent using PPO magic or embrace Q-learning for epic journeys.
|
120 |
+
3. Birth text from input data with the policy network.
|
121 |
+
4. Evaluate the text's quality using BLEU and semantic beauty.
|
122 |
+
5. Commence your custom RL environment for text generation marvels.
|
123 |
+
|
124 |
+
---
|
125 |
+
|
126 |
+
## Uniqueness and Epicness
|
127 |
+
|
128 |
+
- The union of RL and GPT-2 for text generation mastery.
|
129 |
+
- Advanced text tasks unfold gracefully with QNetwork and its heuristic powers.
|
130 |
+
- The limitless canvas to create RL agents for every text challenge.
|
131 |
+
- Rewarding text quality and semantic harmony with AI-calculated rewards.
|
132 |
+
- The blueprint for a customizable and adaptable RL text generation paradise.
|
133 |
+
|
134 |
+
---
|
135 |
+
|
136 |
+
## Get Started Now
|
137 |
+
|
138 |
+
1. Forge your QNetworkGPT2 with personalized hyperparameters.
|
139 |
+
2. Unleash the potential with RL-based training.
|
140 |
+
3. Conjure text aligned with your task and dream.
|
141 |
+
4. Assess the text with metrics and demands.
|
142 |
+
5. Fine-tune and enhance for your text generation quest.
|
143 |
+
|
144 |
+
---
|
145 |
+
# Load model directly
|
146 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
147 |
+
|
148 |
+
tokenizer = AutoTokenizer.from_pretrained("ayjays132/QNetworkGPT2")
|
149 |
+
|
150 |
+
model = AutoModelForCausalLM.from_pretrained("ayjays132/QNetworkGPT2")
|
151 |
+
|
152 |
+
# Set the EOS token as the padding token
|
153 |
+
tokenizer.pad_token = tokenizer.eos_token
|
154 |
+
|
155 |
+
# Initialize a conversation history
|
156 |
+
conversation_history = []
|
157 |
+
|
158 |
+
# Start a conversation loop
|
159 |
+
while True:
|
160 |
+
# Get user input
|
161 |
+
user_input = input("You: ")
|
162 |
+
|
163 |
+
# Add user input to the conversation history
|
164 |
+
conversation_history.append(user_input)
|
165 |
+
|
166 |
+
# Concatenate the conversation strings
|
167 |
+
conversation_text = " ".join(conversation_history)
|
168 |
+
|
169 |
+
# Tokenize and pad the input
|
170 |
+
input_ids = tokenizer.encode(conversation_text, return_tensors="pt", padding=True, truncation=True)
|
171 |
+
|
172 |
+
# Generate a response
|
173 |
+
output_ids = model.generate(input_ids, max_length=150, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
|
174 |
+
|
175 |
+
# Decode the generated response
|
176 |
+
generated_response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
177 |
+
|
178 |
+
# Print the generated response
|
179 |
+
print("Bot:", generated_response)
|
180 |
+
|
181 |
+
# Add bot's response to the conversation history
|
182 |
+
conversation_history.append(generated_response)
|
183 |
+
---
|
184 |
+
## Explore and Create
|
185 |
+
|
186 |
+
QNetworkGPT2 is your ticket to exploring new horizons in text generation. From chatbots and content creation to storytelling and beyond, it's your AI companion for all text adventures. π
|
187 |
+
|
188 |
+
Embrace innovation, adaptation, and expansion to conquer your unique text generation challenges. Your text generation revolution starts here! ππ€
|