FiendFlb commited on
Commit
7c67bdb
·
verified ·
1 Parent(s): a23f9d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -13,7 +13,7 @@ def load_and_preprocess_data():
13
 
14
  # Preprocess the dataset: tokenize inputs
15
  def preprocess_function(examples):
16
- max_length = 4 # Now using 4 for both chosen and rejected
17
  inputs = {
18
  'input_ids': [],
19
  'attention_mask': [],
@@ -36,17 +36,18 @@ def load_and_preprocess_data():
36
  combined_input_ids = chosen_tokenized['input_ids'] + rejected_tokenized['input_ids']
37
  combined_attention_mask = chosen_tokenized['attention_mask'] + rejected_tokenized['attention_mask']
38
 
39
- # No need for padding or truncating since we're already at max length
40
  inputs['input_ids'].append(combined_input_ids)
41
  inputs['attention_mask'].append(combined_attention_mask)
42
- # Adjust labels to match new length; here assuming binary classification where first half is 'chosen'
43
- inputs['labels'].append(torch.tensor([1] * 2 + [0] * 2)) # 4 labels for 4 tokens
44
 
45
  # Convert lists to tensors for each batch
46
  inputs['input_ids'] = torch.tensor(inputs['input_ids'])
47
  inputs['attention_mask'] = torch.tensor(inputs['attention_mask'])
48
  inputs['labels'] = torch.stack(inputs['labels']) # Stack labels along batch dimension
49
 
 
 
50
  return inputs
51
  # Apply preprocessing to the dataset
52
  dataset = dataset.map(preprocess_function, batched=True, remove_columns=dataset.column_names)
 
13
 
14
  # Preprocess the dataset: tokenize inputs
15
  def preprocess_function(examples):
16
+ max_length = 4 # Using 4 for both chosen and rejected
17
  inputs = {
18
  'input_ids': [],
19
  'attention_mask': [],
 
36
  combined_input_ids = chosen_tokenized['input_ids'] + rejected_tokenized['input_ids']
37
  combined_attention_mask = chosen_tokenized['attention_mask'] + rejected_tokenized['attention_mask']
38
 
 
39
  inputs['input_ids'].append(combined_input_ids)
40
  inputs['attention_mask'].append(combined_attention_mask)
41
+ # Labels should be exactly 8 for each example (4 for chosen, 4 for rejected)
42
+ inputs['labels'].append(torch.tensor([1] * 4 + [0] * 4)) # 8 labels for 8 tokens
43
 
44
  # Convert lists to tensors for each batch
45
  inputs['input_ids'] = torch.tensor(inputs['input_ids'])
46
  inputs['attention_mask'] = torch.tensor(inputs['attention_mask'])
47
  inputs['labels'] = torch.stack(inputs['labels']) # Stack labels along batch dimension
48
 
49
+ print(f"Input_ids shape: {inputs['input_ids'].shape}, Labels shape: {inputs['labels'].shape}") # Debugging
50
+
51
  return inputs
52
  # Apply preprocessing to the dataset
53
  dataset = dataset.map(preprocess_function, batched=True, remove_columns=dataset.column_names)