Fizzarolli commited on
Commit
6b82a6c
·
verified ·
1 Parent(s): 89f0644

Upload 3 files

Browse files
Files changed (2) hide show
  1. output.json +0 -0
  2. output.py +46 -9
output.json CHANGED
The diff for this file is too large to render. See raw diff
 
output.py CHANGED
@@ -69,7 +69,10 @@ def generate_conversation_path(cursor, start_convo_id, start_dialogue_id, max_le
69
  if userscript:
70
  placeholder_text += f"Script: {userscript}; "
71
  placeholder_text = placeholder_text.rstrip("; ") + "]"
72
- path.append({"actor": actor_name, "dialogue": placeholder_text})
 
 
 
73
  else:
74
  path.append({"actor": actor_name, "dialogue": dialogue_text})
75
 
@@ -123,8 +126,9 @@ def main():
123
  num_paths_to_generate = 1000
124
  paths_generated = 0
125
 
126
- # Initialize Bloom filter
127
- bloom = ScalableBloomFilter(initial_capacity=100000, error_rate=0.001)
 
128
 
129
  # Either pick a random starting point:
130
  starting_dialogues = get_starting_dialogues(cursor)
@@ -138,14 +142,47 @@ def main():
138
  start_convo_id, start_dialogue_id = random.choice(starting_dialogues)
139
  path = generate_conversation_path(cursor, start_convo_id, start_dialogue_id)
140
 
141
- # Create unique key for conversation
142
- path_text = "".join(entry["dialogue"] for entry in path)
143
- path_hash = hashlib.sha256(path_text.encode()).hexdigest()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
- # Check for duplicates using Bloom filter
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  try:
147
- if path_hash not in bloom and any(entry["dialogue"][0] != "[" for entry in path):
148
- bloom.add(path_hash)
 
149
  conversations.append(path)
150
  paths_generated += 1
151
  pbar.update(1)
 
69
  if userscript:
70
  placeholder_text += f"Script: {userscript}; "
71
  placeholder_text = placeholder_text.rstrip("; ") + "]"
72
+ if placeholder_text == "[Action/Check:]":
73
+ pass
74
+ else:
75
+ path.append({"actor": actor_name, "dialogue": placeholder_text})
76
  else:
77
  path.append({"actor": actor_name, "dialogue": dialogue_text})
78
 
 
126
  num_paths_to_generate = 1000
127
  paths_generated = 0
128
 
129
+ # Track seen conversation patterns
130
+ seen_windows = set()
131
+ min_window_size = 5 # Minimum consecutive dialogues to consider for duplication
132
 
133
  # Either pick a random starting point:
134
  starting_dialogues = get_starting_dialogues(cursor)
 
142
  start_convo_id, start_dialogue_id = random.choice(starting_dialogues)
143
  path = generate_conversation_path(cursor, start_convo_id, start_dialogue_id)
144
 
145
+ # Skip paths that are too short
146
+ if len(path) < 5:
147
+ continue
148
+
149
+ # Create semantic key for conversation
150
+ path_text = " ".join(entry["dialogue"].strip().lower() for entry in path if not entry["dialogue"].startswith("["))
151
+
152
+ def is_duplicate(new_text):
153
+ """Check if new conversation contains or is contained within existing conversations"""
154
+ for existing in conversations:
155
+ existing_text = " ".join(entry["dialogue"].strip().lower() for entry in existing if not entry["dialogue"].startswith("["))
156
+ if len(new_text) < min_window_size or len(existing_text) < min_window_size:
157
+ continue
158
+ # Check for substring matches in either direction
159
+ if new_text in existing_text or existing_text in new_text:
160
+ return True
161
+ return False
162
 
163
+ # More efficient window-based check
164
+ def is_added(current_path):
165
+ """Check for matching subsequences using sliding window"""
166
+ path_dialogues = [entry["dialogue"] for entry in current_path if not entry["dialogue"].startswith("[")]
167
+ window = []
168
+ for dialogue in path_dialogues:
169
+ window.append(dialogue)
170
+ if len(window) > min_window_size:
171
+ window.pop(0)
172
+ if len(window) == min_window_size:
173
+ window_str = " ".join(window)
174
+ if window_str in seen_windows:
175
+ return True
176
+ # Add windows if not duplicate
177
+ for i in range(len(path_dialogues) - min_window_size + 1):
178
+ seen_windows.add(" ".join(path_dialogues[i:i+min_window_size]))
179
+ return False
180
+
181
+ # Check for duplicates
182
  try:
183
+ if (not is_duplicate(path_text) and
184
+ not is_added(path) and
185
+ any(entry["dialogue"][0] != "[" for entry in path)):
186
  conversations.append(path)
187
  paths_generated += 1
188
  pbar.update(1)