ivxxdegen commited on
Commit
4ba1c51
Β·
1 Parent(s): b6e95ca
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -54,13 +54,18 @@ if not os.path.exists(dataset_path):
54
  # --- Load the dataset using pandas ---
55
  print("πŸ“₯ Loading dataset using pandas...")
56
  df = pd.read_json(dataset_path, lines=True)
57
- # Create new columns by extracting text from the nested JSON objects
 
58
  df["tweet_text"] = df["tweet"].apply(lambda x: x.get("content", "") if isinstance(x, dict) else str(x))
59
  df["lore_text"] = df["lore"].apply(lambda x: x.get("response", "") if isinstance(x, dict) else str(x))
60
- # Optionally, drop the original columns if desired:
61
- # df = df.drop(columns=["tweet", "lore"])
 
 
 
62
  dataset = Dataset.from_pandas(df)
63
  print("Dataset columns:", dataset.column_names)
 
64
 
65
  # --- Split the dataset into train and evaluation subsets ---
66
  split_dataset = dataset.train_test_split(test_size=0.1, seed=42)
@@ -76,7 +81,7 @@ model = AutoModelForCausalLM.from_pretrained(
76
  trust_remote_code=True,
77
  device_map="auto",
78
  max_memory=max_memory,
79
- offload_folder=offload_folder,
80
  low_cpu_mem_usage=True,
81
  offload_state_dict=True
82
  )
@@ -84,7 +89,7 @@ torch.cuda.empty_cache()
84
  model.gradient_checkpointing_enable()
85
 
86
  # --- Integrate PEFT (LoRA) ---
87
- # Based on your inspection, we target "qkv_proj" (update if needed)
88
  lora_config = LoraConfig(
89
  r=16,
90
  lora_alpha=32,
@@ -98,7 +103,7 @@ model.print_trainable_parameters()
98
  # --- Preprocess the dataset ---
99
  def preprocess_function(examples):
100
  combined_texts = []
101
- # Use the new flattened columns "tweet_text" and "lore_text"
102
  tweets = examples.get("tweet_text", [])
103
  lores = examples.get("lore_text", [])
104
  for tweet, lore in zip(tweets, lores):
@@ -118,12 +123,12 @@ def add_labels(batch):
118
  print("πŸ›  Adding labels to train dataset...")
119
  tokenized_train = tokenized_train.map(add_labels, batched=True)
120
  print("πŸ›  Adding labels to eval dataset...")
121
- tokenized_eval = eval_dataset.map(add_labels, batched=True)
122
 
123
  # --- Set training arguments ---
124
  training_args = TrainingArguments(
125
  output_dir=output_dir,
126
- evaluation_strategy="epoch",
127
  logging_dir="./logs",
128
  logging_steps=500,
129
  num_train_epochs=3,
 
54
  # --- Load the dataset using pandas ---
55
  print("πŸ“₯ Loading dataset using pandas...")
56
  df = pd.read_json(dataset_path, lines=True)
57
+
58
+ # Flatten nested JSON columns: extract "content" from tweet and "response" from lore.
59
  df["tweet_text"] = df["tweet"].apply(lambda x: x.get("content", "") if isinstance(x, dict) else str(x))
60
  df["lore_text"] = df["lore"].apply(lambda x: x.get("response", "") if isinstance(x, dict) else str(x))
61
+
62
+ # Optionally drop the original nested columns:
63
+ df = df.drop(columns=["tweet", "lore"])
64
+
65
+ # Now convert the flattened DataFrame into a Hugging Face Dataset.
66
  dataset = Dataset.from_pandas(df)
67
  print("Dataset columns:", dataset.column_names)
68
+ # Expected columns are now: ['tweet_text', 'lore_text'] plus any others
69
 
70
  # --- Split the dataset into train and evaluation subsets ---
71
  split_dataset = dataset.train_test_split(test_size=0.1, seed=42)
 
81
  trust_remote_code=True,
82
  device_map="auto",
83
  max_memory=max_memory,
84
+ offload_folder="./offload",
85
  low_cpu_mem_usage=True,
86
  offload_state_dict=True
87
  )
 
89
  model.gradient_checkpointing_enable()
90
 
91
  # --- Integrate PEFT (LoRA) ---
92
+ # Based on your inspection, we target "qkv_proj". Update if necessary.
93
  lora_config = LoraConfig(
94
  r=16,
95
  lora_alpha=32,
 
103
  # --- Preprocess the dataset ---
104
  def preprocess_function(examples):
105
  combined_texts = []
106
+ # Use the new flattened columns: "tweet_text" and "lore_text"
107
  tweets = examples.get("tweet_text", [])
108
  lores = examples.get("lore_text", [])
109
  for tweet, lore in zip(tweets, lores):
 
123
  print("πŸ›  Adding labels to train dataset...")
124
  tokenized_train = tokenized_train.map(add_labels, batched=True)
125
  print("πŸ›  Adding labels to eval dataset...")
126
+ tokenized_eval = tokenized_eval.map(add_labels, batched=True)
127
 
128
  # --- Set training arguments ---
129
  training_args = TrainingArguments(
130
  output_dir=output_dir,
131
+ evaluation_strategy="epoch", # (Deprecated: use eval_strategy in future versions)
132
  logging_dir="./logs",
133
  logging_steps=500,
134
  num_train_epochs=3,