learn-abc commited on
Commit
9875abe
·
verified ·
1 Parent(s): 1de0576

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +172 -151
README.md CHANGED
@@ -6,202 +6,223 @@ tags:
6
  - base_model:adapter:TinyLlama/TinyLlama-1.1B-Chat-v1.0
7
  - lora
8
  - transformers
 
 
 
 
9
  ---
10
 
11
- # Model Card for Model ID
12
-
13
- <!-- Provide a quick summary of what the model is/does. -->
14
-
15
-
16
 
17
  ## Model Details
18
-
19
  ### Model Description
 
20
 
21
- <!-- Provide a longer summary of what this model is. -->
22
-
23
-
24
-
25
- - **Developed by:** [More Information Needed]
26
- - **Funded by [optional]:** [More Information Needed]
27
- - **Shared by [optional]:** [More Information Needed]
28
- - **Model type:** [More Information Needed]
29
- - **Language(s) (NLP):** [More Information Needed]
30
- - **License:** [More Information Needed]
31
- - **Finetuned from model [optional]:** [More Information Needed]
32
-
33
- ### Model Sources [optional]
34
-
35
- <!-- Provide the basic links for the model. -->
36
 
37
- - **Repository:** [More Information Needed]
38
- - **Paper [optional]:** [More Information Needed]
39
- - **Demo [optional]:** [More Information Needed]
40
 
41
  ## Uses
42
-
43
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
-
45
  ### Direct Use
 
46
 
47
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
-
49
- [More Information Needed]
50
-
51
- ### Downstream Use [optional]
52
 
53
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
54
 
55
- [More Information Needed]
 
 
56
 
57
  ### Out-of-Scope Use
 
58
 
59
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
-
61
- [More Information Needed]
 
 
62
 
63
  ## Bias, Risks, and Limitations
 
64
 
65
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
 
67
- [More Information Needed]
 
 
 
68
 
69
  ### Recommendations
70
-
71
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
-
73
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
 
75
  ## How to Get Started with the Model
76
-
77
- Use the code below to get started with the model.
78
-
79
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  ## Training Details
82
-
83
  ### Training Data
84
-
85
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
-
87
- [More Information Needed]
88
 
89
  ### Training Procedure
90
-
91
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
-
93
- #### Preprocessing [optional]
94
-
95
- [More Information Needed]
96
-
97
-
98
- #### Training Hyperparameters
99
-
100
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
-
102
- #### Speeds, Sizes, Times [optional]
103
-
104
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
-
106
- [More Information Needed]
 
 
 
 
 
 
 
107
 
108
  ## Evaluation
 
 
109
 
110
- <!-- This section describes the evaluation protocols and provides the results. -->
111
-
112
- ### Testing Data, Factors & Metrics
113
-
114
- #### Testing Data
115
-
116
- <!-- This should link to a Dataset Card if possible. -->
117
-
118
- [More Information Needed]
119
 
120
- #### Factors
 
121
 
122
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
-
124
- [More Information Needed]
125
-
126
- #### Metrics
127
-
128
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
-
130
- [More Information Needed]
131
 
132
  ### Results
 
133
 
134
- [More Information Needed]
135
-
136
- #### Summary
137
-
138
-
139
-
140
- ## Model Examination [optional]
141
-
142
- <!-- Relevant interpretability work for the model goes here -->
143
-
144
- [More Information Needed]
145
 
146
  ## Environmental Impact
 
147
 
148
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
-
150
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
-
152
- - **Hardware Type:** [More Information Needed]
153
- - **Hours used:** [More Information Needed]
154
- - **Cloud Provider:** [More Information Needed]
155
- - **Compute Region:** [More Information Needed]
156
- - **Carbon Emitted:** [More Information Needed]
157
-
158
- ## Technical Specifications [optional]
159
 
 
160
  ### Model Architecture and Objective
161
-
162
- [More Information Needed]
163
 
164
  ### Compute Infrastructure
165
-
166
- [More Information Needed]
167
-
168
- #### Hardware
169
-
170
- [More Information Needed]
171
-
172
- #### Software
173
-
174
- [More Information Needed]
175
-
176
- ## Citation [optional]
177
-
178
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
-
180
- **BibTeX:**
181
-
182
- [More Information Needed]
183
-
184
- **APA:**
185
-
186
- [More Information Needed]
187
-
188
- ## Glossary [optional]
189
-
190
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
-
192
- [More Information Needed]
193
-
194
- ## More Information [optional]
195
-
196
- [More Information Needed]
197
-
198
- ## Model Card Authors [optional]
199
-
200
- [More Information Needed]
201
 
202
  ## Model Card Contact
203
 
204
- [More Information Needed]
205
- ### Framework versions
 
 
 
 
206
 
207
- - PEFT 0.17.0
 
 
6
  - base_model:adapter:TinyLlama/TinyLlama-1.1B-Chat-v1.0
7
  - lora
8
  - transformers
9
+ - text-generation
10
+ - fine-tuned
11
+ - quotes
12
+ - tinyllama
13
  ---
14
 
15
+ # Model Card for learn-abc/tinyllama-custom-quotes
16
+ This model is a `PEFT (LoRA)` fine-tuned version of `TinyLlama/TinyLlama-1.1B-Chat-v1.0`. It has been specialized to act as an AI assistant that, when given an inspiring quote, provides the author's name, following a specific instruction-based chat format.
 
 
 
17
 
18
  ## Model Details
 
19
  ### Model Description
20
+ This model is a specialized version of `TinyLlama-1.1B-Chat-v1.0`, fine-tuned using the `QLoRA` technique. The primary objective of this fine-tuning was to adapt the base LLM's behavior to a specific task: generating the author's name for a given inspiring quote. It adheres to a conversational instruction format, making it suitable for focused Q&A on a dataset of `quotes` and `authors`.
21
 
22
+ * **Developed by:** The user (`learn-abc`)
23
+ * **Model type:** Causal Language Model (Fine-tuned adapter)
24
+ * **Language(s) (NLP):** English
25
+ * **License:** MIT
26
+ * **Finetuned from model:** TinyLlama/TinyLlama-1.1B-Chat-v1.0
 
 
 
 
 
 
 
 
 
 
27
 
28
+ ### Model Sources
29
+ * **Repository:** https://huggingface.co/learn-abc/tinyllama-custom-quotes
 
30
 
31
  ## Uses
 
 
 
32
  ### Direct Use
33
+ This model is intended for direct use in applications requiring highly specialized text generation for quotes. Specifically, it can be prompted with an inspiring quote in a predefined instruction format, and it will generate the corresponding author. It is ideal for:
34
 
35
+ * Automated quote attribution systems.
36
+ * Educational tools for learning about famous quotes.
37
+ * Integrating a quote-lookup feature into a chatbot or application.
 
 
38
 
39
+ ### Downstream Use
40
+ This fine-tuned adapter can be integrated into larger systems or applications that require accurate quote-to-author mapping. Examples include:
41
 
42
+ * Enhancing content creation tools that deal with quotations.
43
+ * Part of a larger RAG system where quotes need specific attribution.
44
+ * Specialized virtual assistants focused on literary or motivational content.
45
 
46
  ### Out-of-Scope Use
47
+ This model is not intended for:
48
 
49
+ * Generating general conversational text or engaging in open-ended dialogue.
50
+ * Providing factual information on topics outside of quote attribution.
51
+ * Generating code or structured data (unless further fine-tuned for such tasks).
52
+ * Use in high-stakes applications requiring absolute factual accuracy on diverse topics.
53
+ * Generating creative text that is not related to existing quotes and authors.
54
 
55
  ## Bias, Risks, and Limitations
56
+ This model inherits biases present in its base model, `TinyLlama/TinyLlama-1.1B-Chat-v1.0`, which was trained on a broad corpus. Additionally, biases from the `Abirate/english_quotes` dataset (e.g., disproportionate representation of certain authors, historical periods, or cultural perspectives) may be introduced or amplified.
57
 
58
+ ### Risks & Limitations:
59
 
60
+ * **Limited Scope:** Its specialization means it will not perform well on general language tasks.
61
+ * **Knowledge Cut-off:** While fine-tuned, its knowledge is primarily constrained to the quotes present in the training data. It will likely hallucinate or fail if asked about quotes or authors not in its training set.
62
+ * **Short Context:** As TinyLlama is a smaller model, its effective context window may limit its ability to process very long quotes or complex instructions, although the fine-tuning format is designed to mitigate this.
63
+ * **Hallucinations:** Despite fine-tuning, the model may still "hallucinate" authors for unknown quotes or misattribute known quotes if the input is ambiguous or outside its learned patterns.
64
 
65
  ### Recommendations
66
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. For critical applications, human review of generated outputs is recommended. It should primarily be used for its intended task of quote attribution based on the fine-tuning data. Developers should evaluate its performance on a representative dataset reflecting their specific use case to understand its limitations.
 
 
 
67
 
68
  ## How to Get Started with the Model
69
+ To use this model for inference, you can load the base model and then load the PEFT adapters on top of it. Alternatively, you can directly load the merged model if it has been saved in a standalone format.
70
+
71
+ ```python
72
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
73
+ from peft import PeftModel
74
+ import torch
75
+
76
+ # Define the model paths
77
+ BASE_MODEL_NAME = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
78
+ FINE_TUNED_ADAPTER_PATH = "learn-abc/tinyllama-custom-quotes" # Your Hugging Face repo ID
79
+ MERGED_MODEL_PATH = "/tinyllama_custom_quotes_fine_funed/merged_model" # If you have saved the merged model locally
80
+
81
+ # Option 1: Load base model and then PEFT adapter (requires peft installed)
82
+ # Load base model
83
+ model = AutoModelForCausalLM.from_pretrained(
84
+ BASE_MODEL_NAME,
85
+ torch_dtype=torch.float16,
86
+ device_map="auto"
87
+ )
88
+ # Load fine-tuned adapter
89
+ model = PeftModel.from_pretrained(model, FINE_TUNED_ADAPTER_PATH)
90
+ model = model.merge_and_unload() # Merge adapters for easier inference
91
+
92
+ # Option 2: Directly load the merged model if it was saved as a full model
93
+ # model = AutoModelForCausalLM.from_pretrained(
94
+ # MERGED_MODEL_PATH,
95
+ # torch_dtype=torch.float16,
96
+ # device_map="auto"
97
+ # )
98
+
99
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_NAME)
100
+ tokenizer.pad_token = tokenizer.eos_token
101
+ tokenizer.padding_side = "right"
102
+
103
+ # Create a text generation pipeline
104
+ generator = pipeline(task="text-generation", model=model, tokenizer=tokenizer)
105
+
106
+ # Example usage
107
+ test_quote = "The only way to do great work is to love what you do."
108
+ formatted_prompt = f"""<s>[INST] <<SYS>>
109
+ You are an AI assistant that is an expert in writing inspiring quotes. Your task is to provide an inspiring quote for the user based on the given concept, followed by the author's name.
110
+ </SYS>>
111
+
112
+ {test_quote} [/INST]"""
113
+
114
+ result = generator(formatted_prompt, max_new_tokens=50, num_return_sequences=1)
115
+ generated_text = result[0]['generated_text']
116
+
117
+ print(f"Prompt: {test_quote}")
118
+ print(f"Generated Author: {generated_text.split('[/INST]')[-1].strip()}")
119
+ ```
120
 
121
  ## Training Details
 
122
  ### Training Data
123
+ The model was fine-tuned on a subset of the `Abirate/english_quotes` dataset. This dataset contains English quotes paired with their respective authors. The data was preprocessed to fit the Llama 2 chat instruction format, ensuring the model learned to map a given quote (as an "instruction") to its author (as the "response"). Each training sample was formatted as:
124
+ ```bash
125
+ <s>[INST] <<SYS>>{system_prompt}</SYS>>\n\n{quote} [/INST] {author}</s>
126
+ ```
127
 
128
  ### Training Procedure
129
+ The model was fine-tuned using the `QLoRA` (Quantized Low-Rank Adaptation) method, a parameter-efficient fine-tuning technique.
130
+
131
+ ### Preprocessing
132
+ The `Abirate/english_quotes` dataset was loaded and a custom `format_instruction` function was applied to transform each quote-author pair into the Llama 2 chat template. The dataset was then tokenized using the `TinyLlama/TinyLlama-1.1B-Chat-v1.0` tokenizer, with truncation to `max_seq_length=512` and `right-padding`. Labels were created by copying the input IDs. The dataset was split into `90%` training and `10%` evaluation sets.
133
+
134
+ ### Training Hyperparameters
135
+ * **Training regime:** bf16 mixed precision
136
+ * **Optimizer:** paged_adamw_32bit
137
+ * **Learning Rate:** 2e-4
138
+ * **Weight Decay:** 0.001
139
+ * **Gradient Norm Clipping:** 0.3
140
+ * **Warmup Ratio:** 0.03
141
+ * **Number of Epochs:** 1
142
+ * **Per Device Train Batch Size:** 2
143
+ * **Gradient Accumulation Steps:** 2 (resulting in an effective batch size of 4)
144
+ * **LoRA Config:** r=64, lora_alpha=16, lora_dropout=0.1, bias="none", task_type="CAUSAL_LM"
145
+ * **LoRA Target Modules:** ["q_proj", "v_proj", "k_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
146
+ * **Gradient Checkpointing:** Enabled with `use_reentrant=False`
147
+
148
+ ### Speeds, Sizes, Times
149
+ * **Model Parameters:** 1.1 Billion (base model)
150
+ * **Trainable Parameters (LoRA):** Approximately `0.05%` of total parameters (specific number depends on exact model architecture).
151
+ * **Training Time:** The training ran for approximately 1 hour and 35 minutes for 400 steps on the specified hardware.
152
+ * **Checkpoint Size:** Only the PEFT adapters (small, typically in MBs) are saved during training, along with tokenizer files. The full merged model is saved once at the end.
153
 
154
  ## Evaluation
155
+ ### Testing Data
156
+ The model was evaluated on a `10%` split of the `Abirate/english_quotes dataset`, which was held out from the training data. This validation set consists of tokenized quote-author pairs.
157
 
158
+ ### Factors
159
+ Evaluation was performed across the entire validation dataset. No specific subpopulations or sub-domains were isolated for disaggregated analysis.
 
 
 
 
 
 
 
160
 
161
+ ### Metrics
162
+ The primary metric used for evaluation during training was:
163
 
164
+ * **eval_loss (Validation Loss):** A measure of how well the model predicts the next token on the unseen validation data. Lower values indicate better performance.
 
 
 
 
 
 
 
 
165
 
166
  ### Results
167
+ During training, the eval_loss reached approximately `0.3576` at the end of the single epoch. This indicates the model learned effectively to predict the author given the quote in the specified format.
168
 
169
+ ### Summary
170
+ The fine-tuning process successfully adapted the TinyLlama model to the task of quote attribution, as evidenced by the low validation loss. The model demonstrates the ability to generate the correct author for quotes it was fine-tuned on, following the Llama 2 chat instruction template.
 
 
 
 
 
 
 
 
 
171
 
172
  ## Environmental Impact
173
+ Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
174
 
175
+ * **Hardware Type:** NVIDIA GPU (e.g., `T4` or similar with ~14.57 GiB VRAM)
176
+ * **Hours used:** ~1.6 hours
177
+ * **Cloud Provider:** User's Cloud Provider (e.g., AWS EC2)
178
+ * **Carbon Emitted:** ~50 - 100 grams of CO2eq (estimated based on typical cloud GPU power consumption and average grid emission factors for a short training run). This is a very low emission given the small model size and short training duration.
 
 
 
 
 
 
 
179
 
180
+ ## Technical Specifications
181
  ### Model Architecture and Objective
182
+ The model is based on the `TinyLlama-1.1B-Chat-v1.0` architecture, which is a decoder-only transformer model similar to Llama 2. Its objective was fine-tuned to perform causal language modeling, specifically predicting the author token sequence following a given quote within a chat-based instruction prompt. The `QLoRA` method efficiently adapts this architecture by injecting low-rank adapters without fully retraining all original parameters.
 
183
 
184
  ### Compute Infrastructure
185
+ ### Hardware
186
+ The fine-tuning was performed on a system equipped with an `NVIDIA GPU` having approximately `14.57 GiB` of VRAM.
187
+
188
+ ### Software
189
+ * **Operating System:** Linux (e.g., Ubuntu)
190
+ * **Python Version:** Python 3.12+
191
+ * **Deep Learning Framework:** PyTorch
192
+ * **Libraries:** Hugging Face transformers, datasets, peft, bitsandbytes, trl.
193
+
194
+ ## Citation
195
+ ### BibTeX:
196
+ ```bash
197
+ @misc{tinyllama_custom_quotes_fine_tuned,
198
+ author = {learn-abc},
199
+ title = {TinyLlama Custom Quotes Fine-Tune},
200
+ year = {2025},
201
+ publisher = {Hugging Face},
202
+ journal = {Hugging Face Hub},
203
+ howpublished = {\url{https://huggingface.co/learn-abc/tinyllama-custom-quotes}}
204
+ }
205
+ ```
206
+
207
+ ### APA:
208
+
209
+ learn-abc. (2025). TinyLlama Custom Quotes Fine-Tune. Hugging Face. Retrieved from `https://huggingface.co/learn-abc/tinyllama-custom-quotes`
210
+
211
+ ## Glossary
212
+ * **LoRA (Low-Rank Adaptation):** A parameter-efficient fine-tuning technique that adds small, trainable matrices (adapters) to a pre-trained model, significantly reducing the number of parameters that need to be updated during fine-tuning.
213
+ * **QLoRA (Quantized LoRA):** An extension of LoRA that further reduces memory usage by quantizing the pre-trained model's weights to 4-bit precision during training.
214
+ * **Causal Language Model:** A type of language model that predicts the next token in a sequence based only on the preceding tokens.
215
+ * **PEFT (Parameter-Efficient Fine-Tuning):** A family of methods designed to fine-tune large models more efficiently by updating only a small subset of the model's parameters.
216
+ * **Hallucination:** When an LLM generates plausible but factually incorrect or fabricated information.
 
 
 
 
217
 
218
  ## Model Card Contact
219
 
220
+ ### Contact Me
221
+ For any inquiries or support, please reach out to:
222
+
223
+ * **Author:** [Abhishek Singh](https://github.com/SinghIsWriting/)
224
+ * **LinkedIn:** [My LinkedIn Profile](https://www.linkedin.com/in/abhishek-singh-bba2662a9)
225
+ * **Portfolio:** [Abhishek Singh Portfolio](https://portfolio-abhishek-singh-nine.vercel.app/)
226
 
227
+ Framework versions
228
+ PEFT 0.17.0