awacke1 commited on
Commit
f0302d4
·
verified ·
1 Parent(s): 3eeab09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -1
app.py CHANGED
@@ -15,8 +15,37 @@ from gradio_client import Client
15
 
16
  warnings.filterwarnings('ignore')
17
 
18
- # Initialize story starters with added comedy section
 
 
19
  STORY_STARTERS = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  ['Adventure', 'In a hidden temple deep in the Amazon...'],
21
  ['Mystery', 'The detective found an unusual note...'],
22
  ['Romance', 'Two strangers meet on a rainy evening...'],
@@ -225,6 +254,115 @@ with gr.Blocks(title="AI Story Generator") as demo:
225
  headers=["Timestamp", "Preview", "Story Path", "Audio Path"],
226
  interactive=False
227
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
  # Event handlers
230
  def update_prompt(evt: gr.SelectData):
 
15
 
16
  warnings.filterwarnings('ignore')
17
 
18
+ # Initialize story starters from GPT
19
+ # Initialize story starters from Claude
20
+
21
  STORY_STARTERS = [
22
+
23
+ ["Adventure", "A lost map leads a group of unlikely friends on a treasure hunt through ancient ruins."],
24
+ ["Mystery", "A voice from an old radio transmits cryptic messages every night at 2 AM."],
25
+ ["Romance", "An artist begins receiving love letters from a stranger who knows every detail about their paintings."],
26
+ ["Sci-Fi", "In a future where memories can be traded, one person uncovers a memory that shouldn’t exist."],
27
+ ["Fantasy", "A seemingly ordinary child finds out they have the power to heal people but at a mysterious cost."],
28
+ ["Comedy-Sitcom", "The new roommate is convinced they are a spy, despite their day job at a coffee shop."],
29
+ ["Comedy-Workplace", "A filing cabinet at the office is actually a portal to another dimension."],
30
+ ["Comedy-Family", "A grandmother enters a contest to out-tech her tech-savvy grandkids and win the latest gadget."],
31
+ ["Comedy-Supernatural", "A vampire tries to survive in a world obsessed with healthy eating and organic lifestyles."],
32
+ ["Comedy-Travel", "An app glitch reroutes a couple on vacation to the world's quirkiest landmarks."],
33
+
34
+ ['Historical Epic', 'In 1922, when Howard Carter discovered King Tut\'s tomb, he also found a sealed chamber with strange inscriptions that nobody could translate...'],
35
+ ['Science Thriller', 'A quantum physicist working on parallel universe theory suddenly starts receiving messages from her alternate selves, all warning of an imminent catastrophe...'],
36
+ ['True Crime Drama', 'While renovating the infamous Winchester Mystery House, workers discover a previously unknown room containing a journal dated 2025...'],
37
+ ['Space Adventure', 'Based on the real Wow! Signal of 1977, a modern radio astronomer detects the same 72-second sequence repeating from a different location in space...'],
38
+ ['Psychological Mystery', 'A renowned memory researcher developing a treatment for Alzheimer\'s realizes her patients are all remembering the same event that hasn\'t happened yet...'],
39
+ ['Environmental Thriller', 'Deep in the Arctic permafrost, scientists studying climate change uncover a perfectly preserved prehistoric creature that begins to thaw...'],
40
+ ['Tech Noir', 'When a pioneering AI researcher disappears, the only clue is a series of impossibly old photographs showing her throughout history...'],
41
+ ['Maritime Mystery', 'Inspired by the Bermuda Triangle incidents, a marine archaeologist finds a modern submarine in a 200-year-old shipwreck...'],
42
+ ['Cultural Adventure', 'While documenting the uncontacted tribes of the Amazon, an anthropologist discovers ancient cave paintings depicting modern technology...'],
43
+ ['Medical Drama', 'During a routine genome sequencing study, a geneticist identifies a DNA pattern that seems to predict exactly when people will have life-changing moments...']
44
+
45
+ ]
46
+
47
+ # Initialize story starters with added comedy section
48
+ STORY_STARTERS_ORIGINAL_RECIPE = [
49
  ['Adventure', 'In a hidden temple deep in the Amazon...'],
50
  ['Mystery', 'The detective found an unusual note...'],
51
  ['Romance', 'Two strangers meet on a rainy evening...'],
 
254
  headers=["Timestamp", "Preview", "Story Path", "Audio Path"],
255
  interactive=False
256
  )
257
+
258
+ gr.Markdown("""
259
+
260
+ ## Understanding Mixtral's Expert Layers Per Claude 3.5 Sonnet
261
+
262
+ ### What is Mixtral?
263
+ Imagine having 8 different expert tutors for each topic you're learning. Instead of consulting all of them every time, you pick the 2 best experts for each specific question. That's basically how Mixtral works!
264
+
265
+ ### Key Concepts Broken Down
266
+
267
+ #### 1. The Expert System
268
+ - Total Experts: 8 specialists per layer
269
+ - Active Experts: 2 chosen per task
270
+ - Total Layers: 32 levels of processing
271
+ - Selection Method: Uses a "router" to pick the best experts
272
+
273
+ #### 2. How It Works (Step by Step)
274
+
275
+ 1. **Input Stage**
276
+ - Text enters the system
277
+ - Gets broken down into tokens (like words or parts of words)
278
+
279
+ 2. **Router Selection**
280
+ - A "smart traffic director" (router) looks at each piece of input
281
+ - Chooses 2 out of 8 experts to handle it
282
+ - Makes selections based on what each expert is best at
283
+
284
+ 3. **Expert Processing**
285
+ - Chosen experts analyze the input
286
+ - Each expert contributes their specialty knowledge
287
+ - Results are combined using weighted averages
288
+
289
+ 4. **Pattern Analysis**
290
+ Layer 0 (Beginning):
291
+ - Acts almost randomly (~14% repeat choices)
292
+ - Like students still finding their preferred study partners
293
+
294
+ Layer 15 (Middle):
295
+ - Shows stronger patterns (~27% repeat choices)
296
+ - Experts develop clear specialties
297
+
298
+ Layer 31 (End):
299
+ - Maintains expertise patterns (~22% repeat choices)
300
+ - Balanced between specialization and flexibility
301
+
302
+ #### 3. Expert Choice Patterns (From Real Data)
303
+
304
+ | Location in Network | Expert Reuse Rate | What It Means |
305
+ |-------------------|-------------------|---------------|
306
+ | Early Layers | 12.5-14% | Nearly random selection |
307
+ | Middle Layers | 25-28% | Strong specialization |
308
+ | Final Layers | 20-25% | Balanced expertise |
309
+
310
+ #### 4. Why This Matters
311
+
312
+ - **Efficiency**: Only uses 2/8 experts at a time = faster processing
313
+ - **Specialization**: Experts become really good at specific tasks
314
+ - **Flexibility**: Different expert combinations = handles varied tasks well
315
+ - **Resource Smart**: Like having 8 teachers but only paying for 2 at a time!
316
+
317
+ ## Real-World Example
318
+ Think of it like a hospital:
319
+ - You have 8 specialists available
320
+ - For each patient, you consult the 2 most relevant doctors
321
+ - Your choices get better as you learn which doctors handle which cases best
322
+ - Sometimes you need the same doctors for related cases (explaining the repeat patterns)
323
+
324
+ *Note: The actual repeat rates vary by data type (math, code, text, etc.) showing how different experts specialize in different areas!*
325
+
326
+
327
+ ---
328
+
329
+
330
+ ## Explanation of the Eight-Layer Expert Weighting in Mixtral Per ChatGPT 4o Omni Model
331
+
332
+
333
+ Mixtral 8x7B is a sparse Mixture of Experts (MoE) model where each layer can choose from eight "experts" or sets of specialized parameters. For each token, Mixtral’s routing system selects two experts from these eight at every layer, reducing computational cost by using only part of its parameters per token. This selective process means that different experts are activated for different types of input, allowing for efficient and context-sensitive processing.
334
+
335
+ Key concepts:
336
+
337
+ Experts: Each expert is a set of parameters trained on specific types of data, like code or medical abstracts. These experts specialize, enhancing their ability to process particular kinds of input.
338
+ Layers and Repetition: Layers 15 and 31 show higher "expert assignment repetitions" (temporal locality), meaning certain experts are frequently reselected across consecutive tokens, likely due to stable contextual relevance at these stages.
339
+ First and Second Choices: The system tracks the first and second choice for each expert across layers, where layers 15 and 31 have distinct patterns of assignment compared to random, as evidenced by percentages surpassing expected random choice (12.5%).
340
+
341
+ # Mixtral 8x7B Layer and Expert Weighting Overview
342
+
343
+ The Mixtral 8x7B model is built on an efficient and scalable design where only a subset of its eight expert networks, or "experts," are activated at each layer. This selective routing allows Mixtral to use fewer parameters per token while maintaining high performance, making it faster and more efficient.
344
+
345
+ | **Layer** | **First Choice Repetition (%)** | **First or Second Choice Repetition (%)** | **Explanation** |
346
+ |-----------|----------------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------------------|
347
+ | Layer 0 | ~14.0 - 15.0% | ~46 - 50% | Initial layers have near-random expert selection, establishing basic token processing. |
348
+ | Layer 15 | 23.6 - 28.4% | 61.6 - 67.0% | This layer shows a peak in expert repetition, enhancing stable context for language understanding. |
349
+ | Layer 31 | 19.7 - 26.3% | 44.5 - 53.6% | Final layers focus on consolidating information, applying specific experts based on accumulated context. |
350
+
351
+ ### Method Steps
352
+ 1. **Token Processing**: Each token in a sequence is routed through a "layer," which selects two experts from eight possibilities to process the token.
353
+ 2. **Expert Selection**: At each layer, Mixtral uses a gating network to pick two experts. The choice is influenced by the token's properties and the layer's context.
354
+ 3. **Repetition and Efficiency**: Layers 15 and 31 have high expert repetition rates. This repetition is not random and suggests the model’s experts are increasingly stable, applying consistent expertise as it processes deeper into a sequence.
355
+ 4. **Interpretation**: High expert repetition means Mixtral is refining its processing. It returns to the same experts for similar content, building a coherent response across consecutive tokens.
356
+ 5. **Output Generation**: The experts chosen at each layer contribute to the final response, weighted by how frequently they’re selected across the layers.
357
+
358
+ By selecting only a subset of experts per token and layer, Mixtral achieves both computational efficiency and high contextual relevance across tokens in the input sequence.
359
+
360
+ ### Summary of Table Data
361
+ This Markdown table concisely summarizes Mixtral’s expert assignment behavior across layers and explains the significance of the repetition patterns observed.
362
+
363
+ This structure offers clarity on how Mixtral leverages expert assignments, especially in layers 15 and 31, for efficient processing while retaining contextual understanding!
364
+
365
+ """)
366
 
367
  # Event handlers
368
  def update_prompt(evt: gr.SelectData):