BEncoderRT commited on
Commit
eb03849
·
verified ·
1 Parent(s): 13142c8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -184
README.md CHANGED
@@ -130,190 +130,6 @@ model = PeftModel.from_pretrained(base_model, lora_repo)
130
 
131
  ```
132
 
133
- ```python
134
- import torch
135
-
136
- # Ensure the model is in evaluation mode
137
- model.eval()
138
-
139
- # Function to format prompts consistently with training data
140
- def format_prompt(instruction, context=None):
141
- if context:
142
- return f"Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{context}\n\n### Response:\n"
143
- else:
144
- return f"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Response:\n"
145
-
146
- # Define a few test prompts
147
- test_prompts = [
148
- {
149
- "instruction": "Explain the concept of photosynthesis in simple terms.",
150
- "context": None
151
- },
152
- {
153
- "instruction": "What is the capital of France?",
154
- "context": None
155
- },
156
- {
157
- "instruction": "Summarize the main idea of the following text:",
158
- "context": "The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram."
159
- },
160
- {
161
- "instruction": "List three benefits of regular exercise.",
162
- "context": None
163
- }
164
- ]
165
-
166
- # Add the new test prompts (assuming `new_test_prompts` is defined as in the previous step)
167
- new_test_prompts = [
168
- {
169
- "instruction": "Write a short, imaginative story about a cat who discovers a secret portal to another dimension under its owner's bed.",
170
- "context": None
171
- },
172
- {
173
- "instruction": "If a train leaves New York at 10 AM traveling at 60 mph and another train leaves Chicago at 11 AM traveling at 50 mph, and the cities are 800 miles apart, at what time do they meet? (Assume they are traveling towards each other on the same track).",
174
- "context": None
175
- },
176
- {
177
- "instruction": "What is the capital of Australia?",
178
- "context": None
179
- },
180
- {
181
- "instruction": "Explain the difference between supervised and unsupervised learning in machine learning, and provide an example of when each would be used.",
182
- "context": None
183
- },
184
- {
185
- "instruction": "Summarize the following passage:",
186
- "context": "The advent of artificial intelligence has brought forth a new era of technological advancement, impacting various sectors from healthcare to finance. While AI promises increased efficiency and innovative solutions, it also raises ethical concerns regarding job displacement, privacy, and bias in algorithms. Societies worldwide are grappling with how to regulate and integrate AI responsibly, balancing progress with human values. This calls for a multidisciplinary approach involving policymakers, technologists, ethicists, and the public to shape a future where AI serves humanity's best interests."
187
- }
188
- ]
189
- test_prompts.extend(new_test_prompts)
190
-
191
- # Generate responses for each test prompt
192
- print("\n--- Generating Responses ---\n")
193
- with torch.no_grad():
194
- for i, prompt_data in enumerate(test_prompts):
195
- instruction = prompt_data["instruction"]
196
- context = prompt_data["context"]
197
-
198
- formatted_input = format_prompt(instruction, context)
199
-
200
- # Tokenize the input prompt
201
- inputs = tokenizer(formatted_input, return_tensors="pt").to(model.device)
202
-
203
- # Generate response, explicitly using both eos_token_id and pad_token_id
204
- outputs = model.generate(
205
- **inputs,
206
- max_new_tokens=150, # Limit the length of the generated response
207
- do_sample=True, # Enable sampling for more diverse responses
208
- temperature=0.7, # Control randomness (lower means less random)
209
- top_k=50, # Consider only top 50 probable tokens
210
- top_p=0.95, # Nucleus sampling
211
- eos_token_id=tokenizer.eos_token_id,
212
- pad_token_id=tokenizer.pad_token_id # Explicitly set pad_token_id
213
- )
214
-
215
- # Decode the generated tokens
216
- # Exclude the input prompt from the decoded text to get only the model's response
217
- generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
218
- response = generated_text[len(formatted_input):].strip()
219
-
220
- print(f"### Test Prompt {i+1}: ###")
221
- print(f"Instruction: {instruction}")
222
- if context:
223
- print(f"Context: {context}")
224
- print(f"Model Response: {response}\n")
225
-
226
- ```
227
- ---
228
- ```
229
-
230
- --- Generating Responses ---
231
-
232
- ### Test Prompt 1: ###
233
- Instruction: Explain the concept of photosynthesis in simple terms.
234
- Model Response: Photosynthesis is a process in which green plants absorb sunlight and convert it to energy to be used by the living plant. The process of photosynthesis is the process of converting the energy from the sun's rays into an organic compound called a molecule. The process of photosynthesis occurs when the energy from the sun is transformed into chemical energy in the form of energy-rich molecules called pigments. The pigments of the plant are the photosynthetic products and they are absorbed by the plant. The process of photosynthesis is the process of converting the energy from the sun into organic compounds called pigments and absorbing them. In plants, the process of photosynthesis is the process of converting the energy from the sun into organic compounds and converting them into pigments.
235
-
236
- ### Test Prompt 2: ###
237
- Instruction: What is the capital of France?
238
- Model Response: Paris is the capital of France. The city is located on the Mediterranean coast of France and is considered to be the most densely populated city in the world. It has an estimated population of about 8.3 million people. It is the fourth most populous city in Europe and the second most populous city in North America. The city's economy is based on tourism, with most of the tourists coming from around the world. It is also a major international hub for finance and technology. The city has hosted many notable people, including the Pope, who is the longest serving Catholic leader in the world.
239
-
240
- The city is the seat of the region of Paris, which has its own government and a parliament called the National Assembly. It is the largest
241
-
242
- ### Test Prompt 3: ###
243
- Instruction: Summarize the main idea of the following text:
244
- Context: The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
245
- Model Response: The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
246
-
247
- In a pangram, the letters of the alphabet are grouped in a set of groups called "pangrams". The word "pangram" means "a pangram" or "a pangram-like structure".
248
-
249
- In the sentence "The quick brown fox jumps over the lazy dog" there are four groups of characters:
250
-
251
- The quick brown fox jumps over the lazy dog.
252
-
253
- The lazy dog is lazy.
254
-
255
- The quick brown fox jumps over the lazy dog.
256
-
257
- The lazy dog is not lazy.
258
-
259
- The quick brown
260
-
261
- ### Test Prompt 4: ###
262
- Instruction: List three benefits of regular exercise.
263
- Model Response: 1. It helps you stay fit.
264
- 2. It helps you relax.
265
- 3. It helps you lose weight.
266
- 4. It helps you lose your bad habits.
267
- 5. It helps you stay healthy.
268
- 6. It helps you improve your mood.
269
- 7. It helps you sleep better.
270
- 8. It helps you lose your extra weight.
271
- 9. It helps you lose your bad habits.
272
- 10. It helps you live longer.
273
- 11. It helps you live a healthier lifestyle.
274
- 12. It helps you live a healthier lifestyle.
275
- 13. It helps you live a healthier lifestyle.
276
- 14. It helps you live a healthier lifestyle.
277
- 15. It helps you live a healthier lifestyle.
278
-
279
- ### Test Prompt 5: ###
280
- Instruction: Write a short, imaginative story about a cat who discovers a secret portal to another dimension under its owner's bed.
281
- Model Response: Cat, a cat, was sleeping in her bed when she heard a loud noise. She woke up to find her owner, Mr. J, who was out of bed. He said that he heard a loud noise and wondered where the noise was coming from. He then saw the cat's paw print and realized that he was sleeping under his bed. The cat asked him why he was sleeping there and he explained that he had a secret portal to another dimension where he could escape. The cat then told him that he would have to share this secret with him. Mr. J agreed to share this secret with the cat. The cat explained to Mr. J that he would have to find a portal to get to this dimension. Mr. J looked for
282
-
283
- ### Test Prompt 6: ###
284
- Instruction: If a train leaves New York at 10 AM traveling at 60 mph and another train leaves Chicago at 11 AM traveling at 50 mph, and the cities are 800 miles apart, at what time do they meet? (Assume they are traveling towards each other on the same track).
285
- Model Response: The time of arrival is the same. The time of departure is different because the train leaving New York is traveling faster than the train leaving Chicago. If the train leaving New York is at 10 AM and the train leaving Chicago is at 11 AM, then the time of arrival is at 10:00 AM and the time of departure is at 11:00 AM. If the train leaving New York is at 10 AM and the train leaving Chicago is at 11 AM, then the time of arrival is at 10:00 AM and the time of departure is at 11:00 AM. So, the time of arrival is at 10:00 AM and the time of departure is at 11:00 AM.
286
-
287
- If the trains are traveling toward each other on
288
-
289
- ### Test Prompt 7: ###
290
- Instruction: What is the capital of Australia?
291
- Model Response: The capital of Australia is Sydney.
292
-
293
- Sydney is a city in Australia. It is a major city in Australia. It is the most populous city in Australia.
294
-
295
- Sydney is a major financial centre. It is the world's most populous city by a wide margin. It is the world's most populous city by a wide margin.
296
-
297
- Sydney is home to the Sydney Opera House and the National Library of Australia.
298
-
299
- Sydney is home to the Sydney Harbour Bridge and the Sydney Opera House.
300
-
301
- Sydney is home to the Sydney Cricket Ground and the Sydney Football Stadium.
302
-
303
- Sydney is home to the Sydney Tower and the Sydney Aquarium.
304
-
305
- ### Test Prompt 8: ###
306
- Instruction: Explain the difference between supervised and unsupervised learning in machine learning, and provide an example of when each would be used.
307
- Model Response: In machine learning, supervised learning requires a dataset that has been labelled by a human. This is often done by manually creating a labelled dataset that has to be annotated with a set of labels that a machine can understand. For example, a machine might be given a dataset of people's names and asked to categorize them. It might be possible for a machine to learn a person's name and then use it to classify the rest of the person's name. It's very easy to train a machine that can do this. However, there are a number of limitations with this approach. For example, a machine that can categorize a person's name may be unable to understand the person's ethnicity, nationality, or any other characteristics that a person might have
308
-
309
- ### Test Prompt 9: ###
310
- Instruction: Summarize the following passage:
311
- Context: The advent of artificial intelligence has brought forth a new era of technological advancement, impacting various sectors from healthcare to finance. While AI promises increased efficiency and innovative solutions, it also raises ethical concerns regarding job displacement, privacy, and bias in algorithms. Societies worldwide are grappling with how to regulate and integrate AI responsibly, balancing progress with human values. This calls for a multidisciplinary approach involving policymakers, technologists, ethicists, and the public to shape a future where AI serves humanity's best interests.
312
- Model Response: Artificial intelligence promises increased efficiency and innovative solutions, but also raises ethical concerns regarding job displacement, privacy, and bias in algorithms. Societies worldwide are grappling with how to regulate and integrate AI responsibly, balancing progress with human values. This calls for a multidisciplinary approach involving policymakers, technologists, ethicists, and the public to shape a future where AI serves humanity's best interests.
313
-
314
- Artificial intelligence promises increased efficiency and innovative solutions, but also raises ethical concerns regarding job displacement, privacy, and bias in algorithms. Societies worldwide are grappling with how to regulate and integrate AI responsibly, balancing progress with human values. This calls for a multidisciplinary approach involving policymakers, technologists, ethicists, and the public to shape
315
-
316
- ```
317
 
318
 
319
 
@@ -461,6 +277,116 @@ Base Model Response: Artificial intelligence promises increased efficiency and i
461
 
462
  The main challenge for society today is to balance progress with human values, and AI is a major part of this effort. We will never be able to fully harness the potential of AI, and its applications will always be subject to the same ethical issues that we face today. AI is already changing the way we do things. Its impact is already being
463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  ```
465
  ---
466
 
 
130
 
131
  ```
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
 
135
 
 
277
 
278
  The main challenge for society today is to balance progress with human values, and AI is a major part of this effort. We will never be able to fully harness the potential of AI, and its applications will always be subject to the same ethical issues that we face today. AI is already changing the way we do things. Its impact is already being
279
 
280
+ ```
281
+
282
+
283
+ ```
284
+ python
285
+ # Ensure the LoRA-tuned model is in evaluation mode
286
+ model.eval()
287
+
288
+ # Reuse the format_prompt function and test_prompts
289
+
290
+ print("\n--- Generating Responses from LO-RA TUNED MODEL ---\n")
291
+ with torch.no_grad():
292
+ for i, prompt_data in enumerate(test_prompts):
293
+ instruction = prompt_data["instruction"]
294
+ context = prompt_data["context"]
295
+
296
+ formatted_input = format_prompt(instruction, context)
297
+
298
+ # Tokenize the input prompt
299
+ inputs = tokenizer(formatted_input, return_tensors="pt").to(model.device)
300
+
301
+ # Generate response using the LO-RA TUNED MODEL
302
+ outputs = model.generate(
303
+ **inputs,
304
+ max_new_tokens=150,
305
+ do_sample=True,
306
+ temperature=0.7,
307
+ top_k=50,
308
+ top_p=0.95,
309
+ eos_token_id=tokenizer.eos_token_id,
310
+ pad_token_id=tokenizer.pad_token_id
311
+ )
312
+
313
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
314
+ response = generated_text[len(formatted_input):].strip()
315
+
316
+ print(f"### Test Prompt {i+1} (LO-RA MODEL): ###")
317
+ print(f"Instruction: {instruction}")
318
+ if context:
319
+ print(f"Context: {context}")
320
+ print(f"LoRA Model Response: {response}\n")
321
+
322
+ ```
323
+
324
+ ```
325
+
326
+ --- Generating Responses from LO-RA TUNED MODEL ---
327
+
328
+ ### Test Prompt 1 (LO-RA MODEL): ###
329
+ Instruction: Explain the concept of photosynthesis in simple terms.
330
+ LoRA Model Response: Photosynthesis is the process of photosynthesis and the conversion of light energy into chemical energy in the form of ATP. Photosynthesis is a very complicated process and requires a lot of energy to work. It involves converting light energy into chemical energy in the form of ATP. There are many different types of photosynthesis including photosynthesis of plant cells and photosynthesis of living organisms.
331
+
332
+ Photosynthesis is also the process that converts energy of the sun into fuel. The most common way that photosynthesis is accomplished is through the use of a process called photosynthesis. It is this process that is responsible for photosynthesis. In photosynthesis, the energy of the sun is converted into chemical energy in the form of ATP. The energy of the sun is converted into
333
+
334
+ ### Test Prompt 2 (LO-RA MODEL): ###
335
+ Instruction: What is the capital of France?
336
+ LoRA Model Response: Paris is the capital of France. It is also the largest city in the world by population. The city was founded in the 11th century and has been the seat of the French government since 1831. Paris has a population of around 3.7 million people. The city has over 100 museums, including the Louvre, the Eiffel Tower, the Orsay, the Sacré-Coeur, the Pompidou, and the Gare de Lyon. The French capital has a number of famous landmarks including the Arc de Triomphe, the Eiffel Tower, and the Petit Palais. Paris is the most visited city in the world by tourists. The city is home to some of the most famous artists, including
337
+
338
+ ### Test Prompt 3 (LO-RA MODEL): ###
339
+ Instruction: Summarize the main idea of the following text:
340
+ Context: The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
341
+ LoRA Model Response: The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
342
+
343
+ The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
344
+
345
+ The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
346
+
347
+ The quick brown fox jumps over the lazy dog. This sentence is often used to display all letters of the English alphabet, making it a pangram.
348
+
349
+ The quick brown fox jumps over the lazy dog. This sentence is often used to display all
350
+
351
+ ### Test Prompt 4 (LO-RA MODEL): ###
352
+ Instruction: List three benefits of regular exercise.
353
+ LoRA Model Response: Regular exercise is one of the most important things you can do for your health. Exercise is important for your brain and nervous system. Regular exercise is also important for your bones. It will help you sleep better. It will help you avoid many illnesses, including diabetes. It will help you get a good night's sleep. It will help you lose weight. It will help you keep your muscles strong. It will help you stay healthy. It will help you avoid many diseases, including heart disease, cancer, and stroke. It will help you avoid many illnesses, including asthma, emphysema, and some types of dementia. It will help you avoid many illnesses, including diabetes, heart
354
+
355
+ ### Test Prompt 5 (LO-RA MODEL): ###
356
+ Instruction: Write a short, imaginative story about a cat who discovers a secret portal to another dimension under its owner's bed.
357
+ LoRA Model Response: Cat's owner is reading a book on the couch, and her cat is watching her. Suddenly, the cat looks up from the book, and says, "I can see the portal!" The owner is so excited that she reaches for the book, and the cat opens it, revealing the portal. The owner is so excited that she falls into the portal and disappears. The cat is so sad that he missed the portal, but he is glad that he was able to get back. The owner runs through the portal, and the cat watches her disappear, and then he runs through the portal too. He is so happy that he was able to get back, but he is sad that he missed the portal. The cat is sad that he missed the
358
+
359
+ ### Test Prompt 6 (LO-RA MODEL): ###
360
+ Instruction: If a train leaves New York at 10 AM traveling at 60 mph and another train leaves Chicago at 11 AM traveling at 50 mph, and the cities are 800 miles apart, at what time do they meet? (Assume they are traveling towards each other on the same track).
361
+ LoRA Model Response: The answer is: they meet at 8:05 AM.
362
+
363
+ The reason is because the time it takes for one train to travel a given distance is a function of the speed of the train. If the speed of the train is 60 mph, then the time it takes for one train to travel 800 miles is 8 hours, or about 8 hours and 50 minutes.
364
+
365
+ If the speed of the train is 50 mph, then the time it takes for one train to travel 800 miles is 14 hours, or about 14 hours and 20 minutes.
366
+
367
+ So, by the time the train meets, it will have traveled 800 miles.
368
+
369
+ In this example, Chicago is at 8:05 AM, New York is at 10:05
370
+
371
+ ### Test Prompt 7 (LO-RA MODEL): ###
372
+ Instruction: What is the capital of Australia?
373
+ LoRA Model Response: Canberra is the capital of Australia. It is located in the state of Australia's north east and is about 250 miles (400 km) from Sydney. The city of Sydney is the main city in Australia and the fourth most populous city. Australia is one of the largest countries in the world by area and has a population of about 24 million people.
374
+
375
+ The city of Canberra is known for being home to the Australian Parliament and the National Library of Australia. The Australian Parliament was moved to the National Library in 2016. It is also home to the Australian Capital Territory Library and the Australian National University Library. The National Library of Australia is the largest library in Australia. The National Library of Australia has more than 1.3 million books
376
+
377
+ ### Test Prompt 8 (LO-RA MODEL): ###
378
+ Instruction: Explain the difference between supervised and unsupervised learning in machine learning, and provide an example of when each would be used.
379
+ LoRA Model Response: In supervised learning, the training data is used to train the model. In unsupervised learning, the model is not trained on the data, but rather, it learns to use data to predict unknown future events. For example, if you were to use a machine learning algorithm to classify a person's age, you would use a supervised algorithm to train your model to predict when the person will be 30, and you would use an unsupervised algorithm to predict when the person will be 60. You would then use the trained model to predict when the person will be 90, and you would use the trained model to predict when the person will be 120. In this example, you would use the model to predict when the person will be 30,
380
+
381
+ ### Test Prompt 9 (LO-RA MODEL): ###
382
+ Instruction: Summarize the following passage:
383
+ Context: The advent of artificial intelligence has brought forth a new era of technological advancement, impacting various sectors from healthcare to finance. While AI promises increased efficiency and innovative solutions, it also raises ethical concerns regarding job displacement, privacy, and bias in algorithms. Societies worldwide are grappling with how to regulate and integrate AI responsibly, balancing progress with human values. This calls for a multidisciplinary approach involving policymakers, technologists, ethicists, and the public to shape a future where AI serves humanity's best interests.
384
+ LoRA Model Response: AI has brought forth a new era of technological advancement, impacting various sectors from healthcare to finance. While AI promises increased efficiency and innovative solutions, it also raises ethical concerns regarding job displacement, privacy, and bias in algorithms. Societies worldwide are grappling with how to regulate and integrate AI responsibly, balancing progress with human values. This calls for a multidisciplinary approach involving policymakers, technologists, ethicists, and the public to shape a future where AI serves humanity's best interests.
385
+
386
+ Artificial intelligence has made it possible for computers to think. This has created a new generation of machines that are able to do things that humans are not. Some of these machines are capable of doing more than humans are able to do.
387
+
388
+ The first
389
+
390
  ```
391
  ---
392