FiendFlb commited on
Commit
acb5a43
·
verified ·
1 Parent(s): fb5819f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -24,13 +24,13 @@ def load_and_preprocess_data():
24
  example,
25
  truncation=True,
26
  padding='max_length',
27
- max_length=4
28
  )
29
  rejected_tokenized = tokenizer(
30
  example,
31
  truncation=True,
32
  padding='max_length',
33
- max_length=4
34
  )
35
 
36
  combined_input_ids = chosen_tokenized['input_ids'] + rejected_tokenized['input_ids']
@@ -40,7 +40,7 @@ def load_and_preprocess_data():
40
  # Ensure labels match the exact length of input_ids
41
  inputs['input_ids'].append(combined_input_ids)
42
  inputs['attention_mask'].append(combined_attention_mask)
43
- inputs['labels'].append(torch.tensor([1] * (label_length // 2) + [0] * (label_length - label_length // 2)))
44
 
45
  # Convert lists to tensors for each batch
46
  inputs['input_ids'] = torch.tensor(inputs['input_ids'], dtype=torch.long)
@@ -101,7 +101,7 @@ def train_model(dataset):
101
  # Gradio Interface function to predict
102
  def predict(text):
103
  # Tokenize the input text
104
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=4) # Adjust max_length to match preprocessing
105
  # Perform inference
106
  outputs = model(**inputs)
107
  prediction = torch.argmax(outputs.logits, dim=-1).item() # Get the class with the highest score
 
24
  example,
25
  truncation=True,
26
  padding='max_length',
27
+ max_length=32
28
  )
29
  rejected_tokenized = tokenizer(
30
  example,
31
  truncation=True,
32
  padding='max_length',
33
+ max_length=32
34
  )
35
 
36
  combined_input_ids = chosen_tokenized['input_ids'] + rejected_tokenized['input_ids']
 
40
  # Ensure labels match the exact length of input_ids
41
  inputs['input_ids'].append(combined_input_ids)
42
  inputs['attention_mask'].append(combined_attention_mask)
43
+ inputs['labels'].append(torch.tensor([1] * (label_length // 16) + [0] * (label_length - label_length // 16)))
44
 
45
  # Convert lists to tensors for each batch
46
  inputs['input_ids'] = torch.tensor(inputs['input_ids'], dtype=torch.long)
 
101
  # Gradio Interface function to predict
102
  def predict(text):
103
  # Tokenize the input text
104
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=32) # Adjust max_length to match preprocessing
105
  # Perform inference
106
  outputs = model(**inputs)
107
  prediction = torch.argmax(outputs.logits, dim=-1).item() # Get the class with the highest score