Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,31 @@ def load_and_preprocess_data():
|
|
| 10 |
|
| 11 |
# Extract "prompt" and "chosen"/"rejected" as input-output pairs
|
| 12 |
def process_row(example):
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return {
|
| 15 |
-
'prompt':
|
| 16 |
-
'chosen':
|
| 17 |
-
'rejected':
|
| 18 |
}
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
# Load the tokenizer (You can choose any model, here we use BERT)
|
| 23 |
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
|
|
|
|
| 10 |
|
| 11 |
# Extract "prompt" and "chosen"/"rejected" as input-output pairs
|
| 12 |
def process_row(example):
|
| 13 |
+
# Access the 'rows' key
|
| 14 |
+
rows = example['rows']
|
| 15 |
+
|
| 16 |
+
# Initialize lists for prompts, chosen, and rejected pairs
|
| 17 |
+
prompts = []
|
| 18 |
+
chosen_responses = []
|
| 19 |
+
rejected_responses = []
|
| 20 |
+
|
| 21 |
+
# Process each row within 'rows'
|
| 22 |
+
for row_data in rows:
|
| 23 |
+
row = row_data['row'] # Access the 'row' inside each row_data
|
| 24 |
+
|
| 25 |
+
prompts.append(row['prompt'])
|
| 26 |
+
chosen_responses.append(row['chosen'])
|
| 27 |
+
rejected_responses.append(row['rejected'])
|
| 28 |
+
|
| 29 |
+
# Return the processed result in the correct format
|
| 30 |
return {
|
| 31 |
+
'prompt': prompts,
|
| 32 |
+
'chosen': chosen_responses,
|
| 33 |
+
'rejected': rejected_responses
|
| 34 |
}
|
| 35 |
+
|
| 36 |
+
# Apply the processing function to the dataset
|
| 37 |
+
dataset = dataset.map(process_row, batched=True)
|
| 38 |
|
| 39 |
# Load the tokenizer (You can choose any model, here we use BERT)
|
| 40 |
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
|