Autsadin commited on
Commit
2b9bd50
·
verified ·
1 Parent(s): 3211e99

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +81 -3
README.md CHANGED
@@ -1,3 +1,81 @@
1
- ---
2
- license: unknown
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Fine-Tuned GPT-2 Model for Instruction-Based Tasks
3
+
4
+ This model is a fine-tuned version of GPT-2, adapted for instruction-based tasks. It has been trained to provide helpful and coherent responses to a variety of prompts.
5
+
6
+ ## Model Description
7
+
8
+ This model is based on OpenAI's GPT-2 architecture and has been fine-tuned to respond to instructions in a format that mimics conversational exchanges. The fine-tuning process enhances its ability to follow specific instructions and generate appropriate responses, making it a valuable tool for interactive applications.
9
+
10
+ ### Example Usage
11
+
12
+ Below is an example of how to use the fine-tuned model in your application:
13
+
14
+ ```python
15
+ import torch
16
+ import random
17
+ import numpy as np
18
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
19
+
20
+ # Load the fine-tuned model and tokenizer
21
+ model = GPT2LMHeadModel.from_pretrained("your_model_path")
22
+ tokenizer = GPT2Tokenizer.from_pretrained("your_model_path")
23
+
24
+ # Set the seed value for reproducibility
25
+ seed_val = 42
26
+ random.seed(seed_val)
27
+ np.random.seed(seed_val)
28
+ torch.manual_seed(seed_val)
29
+ torch.cuda.manual_seed_all(seed_val)
30
+
31
+ # Define the template for instruction-based prompts
32
+ template = "<s>[INST] <<SYS>>
33
+ You are a helpful assistant
34
+ <</SYS>>
35
+
36
+ {instruct}[/INST]"
37
+
38
+ # Function to format prompts using the template
39
+ def format_entry(prompt):
40
+ return template.format(instruct=prompt)
41
+
42
+ # Define the input prompt
43
+ prompt = "What is a dog?"
44
+
45
+ # Tokenize the input prompt
46
+ inputs = tokenizer.encode(format_entry(prompt), return_tensors='pt')
47
+
48
+ # Generate a response
49
+ outputs = model.generate(
50
+ inputs,
51
+ max_length=256,
52
+ num_return_sequences=1,
53
+ top_k=50,
54
+ top_p=0.95,
55
+ temperature=0.8,
56
+ pad_token_id=tokenizer.eos_token_id,
57
+ do_sample=True,
58
+ early_stopping=True
59
+ )
60
+
61
+ # Decode and print the generated text
62
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
63
+ print(generated_text)
64
+
65
+ ### Explanation:
66
+
67
+ Training Data
68
+ The model was fine-tuned using the Alpaca GPT-4 dataset available at the following GitHub repository. Specifically, the alpaca_gpt4_data_en.zip dataset was utilized. This dataset includes a wide range of instruction-based prompts and responses, providing a robust foundation for the model's training.
69
+
70
+ Training Procedure
71
+ The fine-tuning process was carried out with the following hyperparameters:
72
+
73
+ Learning Rate: 2e-5
74
+ Batch Size (Train): 4
75
+ Batch Size (Eval): 4
76
+ Number of Epochs: 1
77
+ Weight Decay: 0.01
78
+ Training Environment
79
+ The model was trained using PyTorch and the Hugging Face transformers library. The training was performed on a GPU-enabled environment to accelerate the fine-tuning process. The training script ensures reproducibility by setting a consistent random seed across different components.
80
+
81
+