BEncoderRT commited on
Commit
d6b1754
·
verified ·
1 Parent(s): 4bc9f2a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +142 -0
README.md CHANGED
@@ -152,8 +152,150 @@ model = PeftModel.from_pretrained(base_model, lora_repo)
152
 
153
  ```
154
 
 
 
 
 
155
 
 
 
 
 
 
 
 
 
 
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  ```
159
  python
 
152
 
153
  ```
154
 
155
+ ```
156
+ python
157
+
158
+ import torch
159
 
160
+ # Ensure the model is in evaluation mode
161
+ model.eval()
162
+
163
+ # Function to format prompts consistently with training data
164
+ def format_prompt(instruction, context=None):
165
+ if context:
166
+ 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"
167
+ else:
168
+ 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"
169
 
170
+ # Define a few test prompts
171
+ test_prompts = [
172
+ {
173
+ "instruction": "Explain the concept of photosynthesis in simple terms.",
174
+ "context": None
175
+ },
176
+ {
177
+ "instruction": "What is the capital of France?",
178
+ "context": None
179
+ },
180
+ {
181
+ "instruction": "Summarize the main idea of the following text:",
182
+ "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."
183
+ },
184
+ {
185
+ "instruction": "List three benefits of regular exercise.",
186
+ "context": None
187
+ }
188
+ ]
189
+
190
+ # Add the new test prompts (assuming `new_test_prompts` is defined as in the previous step)
191
+ new_test_prompts = [
192
+ {
193
+ "instruction": "Write a short, imaginative story about a cat who discovers a secret portal to another dimension under its owner's bed.",
194
+ "context": None
195
+ },
196
+ {
197
+ "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).",
198
+ "context": None
199
+ },
200
+ {
201
+ "instruction": "What is the capital of Australia?",
202
+ "context": None
203
+ },
204
+ {
205
+ "instruction": "Explain the difference between supervised and unsupervised learning in machine learning, and provide an example of when each would be used.",
206
+ "context": None
207
+ },
208
+ {
209
+ "instruction": "Summarize the following passage:",
210
+ "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."
211
+ }
212
+ ]
213
+ test_prompts.extend(new_test_prompts)
214
+
215
+ # Generate responses for each test prompt
216
+ print("\n--- Generating Responses ---\n")
217
+ with torch.no_grad():
218
+ for i, prompt_data in enumerate(test_prompts):
219
+ instruction = prompt_data["instruction"]
220
+ context = prompt_data["context"]
221
+
222
+ formatted_input = format_prompt(instruction, context)
223
+
224
+ # Tokenize the input prompt
225
+ inputs = tokenizer(formatted_input, return_tensors="pt").to(model.device)
226
+
227
+ # Generate response, explicitly using both eos_token_id and pad_token_id
228
+ outputs = model.generate(
229
+ **inputs,
230
+ max_new_tokens=150, # Limit the length of the generated response
231
+ do_sample=True, # Enable sampling for more diverse responses
232
+ temperature=0.7, # Control randomness (lower means less random)
233
+ top_k=50, # Consider only top 50 probable tokens
234
+ top_p=0.95, # Nucleus sampling
235
+ eos_token_id=tokenizer.eos_token_id,
236
+ pad_token_id=tokenizer.pad_token_id # Explicitly set pad_token_id
237
+ )
238
+
239
+ # Decode the generated tokens
240
+ # Exclude the input prompt from the decoded text to get only the model's response
241
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
242
+ response = generated_text[len(formatted_input):].strip()
243
+
244
+ print(f"### Test Prompt {i+1}: ###")
245
+ print(f"Instruction: {instruction}")
246
+ if context:
247
+ print(f"Context: {context}")
248
+ print(f"Model Response: {response}\n")
249
+
250
+ ```
251
+
252
+ ```
253
+ --- Generating Responses ---
254
+
255
+ ### Test Prompt 1: ###
256
+ Instruction: Explain the concept of photosynthesis in simple terms.
257
+ Model Response: Photosynthesis is a process by which plants convert sunlight to carbon dioxide and water. The process is called photosynthesis. When plants are in the green zone, the process of photosynthesis is called "greening". In the process of photosynthesis, plants release oxygen, which can then be used by other organisms. When the process of photosynthesis is not greening, plants do not use oxygen. Plants use carbon dioxide and water to produce food.
258
+
259
+ ### Test Prompt 2: ###
260
+ Instruction: What is the capital of France?
261
+ Model Response: Paris
262
+
263
+ ### Test Prompt 3: ###
264
+ Instruction: Summarize the main idea of the following text:
265
+ 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.
266
+ Model Response: The quick brown fox jumps over the lazy dog.
267
+
268
+ ### Test Prompt 4: ###
269
+ Instruction: List three benefits of regular exercise.
270
+ Model Response: 1. Strengthens muscles
271
+ 2. Improves cardiovascular system
272
+ 3. Enhances flexibility
273
+
274
+ ### Test Prompt 5: ###
275
+ Instruction: Write a short, imaginative story about a cat who discovers a secret portal to another dimension under its owner's bed.
276
+ Model Response: A cat named Buddy has a new toy for his brother, who lives in another house. When Buddy asks what he can do to help, his owner replies that he could help him move a heavy box into the attic. But the cat can't move the box because it's on the floor. So Buddy says he can help by moving it into the attic.
277
+
278
+ The cat knows it's in the attic because it heard the owner's voice saying, "Hey, Buddy, move the box," and it knows it's on the floor because it heard the owner saying, "Hey, Buddy, move the box." So the cat knows that the owner is in the attic, and it is in the attic.
279
+
280
+ ### Test Prompt 6: ###
281
+ 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).
282
+ Model Response: The answer is: 12 AM.
283
+
284
+ ### Test Prompt 7: ###
285
+ Instruction: What is the capital of Australia?
286
+ Model Response: Melbourne is the capital of Australia.
287
+
288
+ ### Test Prompt 8: ###
289
+ Instruction: Explain the difference between supervised and unsupervised learning in machine learning, and provide an example of when each would be used.
290
+ Model Response: There are two main differences between supervised and unsupervised learning. First, supervised learning requires an input to be labeled. This is typically done with a dataset that you collected and are able to use this dataset to train a model. Unsupervised learning, on the other hand, does not require any input, but instead relies on the data itself. This is often done with data that you are not able to collect, such as images or videos. Another difference is that supervised learning is based on models, whereas unsupervised learning is based on data. For example, if you have a dataset of pictures of dogs and humans, you can use a supervised learning model to learn about humans, and then use the same model to learn about
291
+
292
+ ### Test Prompt 9: ###
293
+ Instruction: Summarize the following passage:
294
+ 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.
295
+ Model Response: AI promises increased efficiency and innovative solutions, it also raises ethical concerns regarding job displacement, privacy, and bias in algorithms.
296
+
297
+
298
+ ```
299
 
300
  ```
301
  python