developerPushkal commited on
Commit
a675abb
Β·
verified Β·
1 Parent(s): 1fcd6eb

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +108 -0
README.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+
4
+ # Set device
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
+
7
+ # Model and tokenizer
8
+ model_name = "AventIQ-AI/gpt2-lmheadmodel-next-line-prediction-model"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
11
+
12
+ import html
13
+
14
+ # Define test text
15
+ sample_text = "Artificial intelligence is transforming"
16
+
17
+ # Tokenize input
18
+ inputs = tokenizer(sample_text, return_tensors="pt").to(device)
19
+
20
+ # Generate prediction
21
+ with torch.no_grad():
22
+ output_tokens = model.generate(
23
+ **inputs,
24
+ max_length=50,
25
+ num_beams=5,
26
+ repetition_penalty=1.5,
27
+ temperature=0.7,
28
+ top_k=50,
29
+ top_p=0.9,
30
+ do_sample=True,
31
+ no_repeat_ngram_size=2,
32
+ num_return_sequences=1,
33
+ early_stopping=True,
34
+ length_penalty=1.0,
35
+ pad_token_id=tokenizer.eos_token_id,
36
+ eos_token_id=tokenizer.eos_token_id,
37
+ return_dict_in_generate=True,
38
+ output_scores=True
39
+ )
40
+
41
+ # Decode and clean response
42
+ generated_response = tokenizer.decode(output_tokens.sequences[0], skip_special_tokens=True)
43
+ cleaned_response = html.unescape(generated_response).replace("#39;", "'").replace("quot;", '"')
44
+
45
+ print("\nGenerated Response:\n", cleaned_response)
46
+
47
+ ## GPT-2 for Next-line Prediction
48
+
49
+ This repository hosts a fine-tuned GPT-2 model optimized for **next-line prediction** tasks. The model has been fine-tuned on the **OpenWebText** dataset and quantized in **FP16** format to enhance efficiency without compromising performance.
50
+
51
+ ## Model Details
52
+
53
+ - **Model Architecture:** GPT-2 (Causal Language Model)
54
+ - **Task:** Next-line Prediction
55
+ - **Dataset:** OpenWebText (subset: `stas/openwebtext-10k`)
56
+ - **Quantization:** FP16 for reduced model size and faster inference
57
+ - **Fine-tuning Framework:** Hugging Face Transformers
58
+
59
+ ## Training Details
60
+
61
+ - **Number of Epochs:** 3
62
+ - **Batch Size:** 4
63
+ - **Evaluation Strategy:** Epoch
64
+ - **Learning Rate:** 5e-5
65
+
66
+ ## Evaluation Metrics (Perplexity Score)
67
+ Perplexity Score: 14.355693817138672
68
+
69
+ ## Limitations
70
+
71
+ - The model is optimized for English-language next-word prediction tasks.
72
+ - While quantization improves speed, minor accuracy degradation may occur.
73
+ - Performance on out-of-distribution text (e.g., highly technical or domain-specific data) may be limited.
74
+
75
+ ## Usage Instructions
76
+
77
+ ### Installation
78
+
79
+ ```sh
80
+ pip install transformers torch
81
+ ```
82
+
83
+ ### Loading the Model in Python
84
+
85
+ ```python
86
+ from transformers import AutoTokenizer, AutoModelForCausalLM
87
+ import torch
88
+
89
+ device = "cuda" if torch.cuda.is_available() else "cpu"
90
+
91
+ model_name = "AventIQ-AI/gpt2-lmheadmodel-next-line-prediction-model"
92
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
93
+ model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
94
+ ```
95
+
96
+ ## Repository Structure
97
+
98
+ ```
99
+ .
100
+ β”œβ”€β”€ model/ # Contains the quantized model files
101
+ β”œβ”€β”€ tokenizer_config/ # Tokenizer configuration and vocabulary files
102
+ β”œβ”€β”€ model.safetensors/ # Quantized Model
103
+ β”œβ”€β”€ README.md # Model documentation
104
+ ```
105
+
106
+ ## Contributing
107
+
108
+ Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.