ayushsinha commited on
Commit
7e426ce
Β·
verified Β·
1 Parent(s): 7ffdcf5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -1
README.md CHANGED
@@ -1 +1,87 @@
1
- # Microfiction Generation with GPT2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Microfiction Generation with GPT2
2
+
3
+ This repository hosts a quantized version of the GPT2 model, fine-tuned for microfiction generation tasks where model will generate short stories based on the prompt. The model has been optimized for efficient deployment while maintaining high accuracy, making it suitable for resource-constrained environments.
4
+
5
+ ## Model Details
6
+ - **Model Architecture:** GPT2
7
+ - **Task:** Microfiction Generation
8
+ - **Dataset:** Hugging Face's `Children-Stories-Collection`
9
+ - **Quantization:** Float16
10
+ - **Fine-tuning Framework:** Hugging Face Transformers
11
+
12
+ ## Usage
13
+ ### Installation
14
+ ```sh
15
+ pip install transformers torch
16
+ ```
17
+
18
+ ### Loading the Model
19
+ ```python
20
+ from transformers import AutoModelForCausalLM, AutoTokenizer
21
+ import torch
22
+
23
+ device = "cuda" if torch.cuda.is_available() else "cpu"
24
+
25
+ model_name = "AventIQ-AI/gpt2-microfiction-generation"
26
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
27
+ model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
28
+
29
+ def generate_story(prompt_text):
30
+ input_ids = tokenizer(prompt_text, return_tensors="pt").input_ids.to("cuda")
31
+
32
+ output = model.generate(
33
+ input_ids,
34
+ max_length=200, # Control output length
35
+ temperature=0.7, # Lower value = more deterministic, higher = more creative
36
+ top_p=0.9, # Nucleus sampling to avoid repetition
37
+ top_k=50, # Consider only top-k likely words
38
+ repetition_penalty=1.2, # Reduce repetitive text
39
+ do_sample=True,
40
+ )
41
+
42
+ return tokenizer.decode(output[0], skip_special_tokens=True)
43
+
44
+ # Test Example
45
+ prompt = "Write a short science fiction story about a man wakes up in an abandoned house with no memory of how he got there."
46
+ generated_text = generate_story(prompt)
47
+ print(generated_text)
48
+ ```
49
+
50
+ ## πŸ“Š ROUGE Evaluation Results
51
+ After fine-tuning the T5-Small model for text translation, we obtained the following ROUGE scores:
52
+
53
+ | **Metric** | **Score** | **Meaning** |
54
+ |------------|---------|--------------------------------------------------------------|
55
+ | **ROUGE-1** | 0.4673 (~46%) | Measures overlap of unigrams (single words) between the reference and generated text. |
56
+ | **ROUGE-2** | 0.2486 (~24%) | Measures overlap of bigrams (two-word phrases), indicating coherence and fluency. |
57
+ | **ROUGE-L** | 0.4595 (~45%) | Measures longest matching word sequences, testing sentence structure preservation. |
58
+ | **ROUGE-Lsum** | 0.4620 (~46%) | Similar to ROUGE-L but optimized for summarization tasks. |
59
+
60
+ ## Fine-Tuning Details
61
+ ### Dataset
62
+ The Hugging Face's `Children-Stories-Collection` dataset was used, containing various types of prompts and their related responses.
63
+
64
+ ### Training
65
+ - **Number of epochs:** 3
66
+ - **Save Steps:** 5000
67
+ - **Logging Steps:** 500
68
+
69
+ ### Quantization
70
+ Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
71
+
72
+ ## Repository Structure
73
+ ```
74
+ .
75
+ β”œβ”€β”€ model/ # Contains the quantized model files
76
+ β”œβ”€β”€ tokenizer_config/ # Tokenizer configuration and vocabulary files
77
+ β”œβ”€β”€ model.safetensors/ # Quantized Model
78
+ β”œβ”€β”€ README.md # Model documentation
79
+ ```
80
+
81
+ ## Limitations
82
+ - The model may not generalize well to domains outside the fine-tuning dataset.
83
+ - Currently, it only supports English to French translations.
84
+ - Quantization may result in minor accuracy degradation compared to full-precision models.
85
+
86
+ ## Contributing
87
+ Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.