oberbics commited on
Commit
746b711
·
verified ·
1 Parent(s): cf4340c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +196 -69
app.py CHANGED
@@ -299,81 +299,208 @@ h2 {
299
 
300
  with gr.Blocks(css=custom_css, title="Daten Strukturieren und Analysieren") as demo:
301
  gr.HTML("""
302
- <div style="text-align: center; margin-bottom: 1rem">
303
- <h1>Daten Strukturieren und Analysieren</h1>
304
- <p style="font-size: 1.1rem; margin-top: -10px;">Dies ist eine Demoversion für die Extrahierung und Visualisierung von Daten</p>
305
- </div>
306
- <div style="font-family: 'Source Sans Pro', sans-serif; max-width: 800px; margin: 0 auto; color: #333; line-height: 1.6;">
307
-
308
- <p style="font-size: 1.2rem; margin-bottom: 1.5rem; color: #2c3e50; font-weight: 400;">
309
- In dieser Unterrichtseinheit befassen wir uns mit einer Methode zur Strukturierung unstrukturierter historischer Texte.
310
- Im Kern verbindet unsere Anwendung die systematische Strukturierung von Daten mit einem spezialisierten Sprachmodell,
311
- das auf der Question-Answering-Methode basiert.
312
- </p>
313
-
314
- <div style="background: #f8f9fa; padding: 1.5rem; border-radius: 8px; margin-bottom: 2rem; border-left: 4px solid #3498db;">
315
- <h3 style="margin-top: 0; color: #2c3e50; border-bottom: 1px solid #eee; padding-bottom: 0.5rem;">
316
- Methodik: Vom unstrukturierten Text zur strukturierten Information
317
- </h3>
318
-
319
- <p style="margin-bottom: 1.5rem;">
320
- Die grundlegende Herausforderung bei der Arbeit mit historischen Quellen ist, dass relevante Informationen in langen
321
- Fließtexten eingebettet sind und manuell mühsam extrahiert werden müssen. Unser Ansatz automatisiert diesen Prozess.
322
- </p>
323
 
324
- <h4 style="color: #2980b9; margin-top: 1.5rem;">Wie funktioniert die Informationsextraktion?</h4>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
326
- <ol style="padding-left: 1.5rem;">
327
- <li style="margin-bottom: 1rem;">
328
- <strong style="color: #2c3e50;">Template-Definition</strong>: Sie definieren ein JSON-Template mit den Informationstypen, die Sie extrahieren möchten:
329
- <pre style="background: #f5f5f5; padding: 1rem; border-radius: 4px; overflow-x: auto; margin: 0.5rem 0 1rem;"><code>{"earthquake location": "", "dateline location": ""}</code></pre>
330
- </li>
331
-
332
- <li style="margin-bottom: 1rem;">
333
- <strong style="color: #2c3e50;">Question-Answering-Methode</strong>: Das Sprachmodell interpretiert jedes leere Feld als implizite Frage:
334
- <ul style="margin-top: 0.5rem; padding-left: 1.5rem;">
335
- <li><code style="background: #f0f0f0; padding: 0.2rem 0.4rem; border-radius: 3px;">"earthquake location": ""</code> → "Wo ist das Erdbeben passiert?"</li>
336
- <li><code style="background: #f0f0f0; padding: 0.2rem 0.4rem; border-radius: 3px;">"dateline location": ""</code> → "Von wo wird berichtet?"</li>
337
  </ul>
338
- </li>
339
-
340
- <li style="margin-bottom: 1rem;">
341
- <strong style="color: #2c3e50;">Sprachmodell-Verarbeitung</strong>: Das NuExtract-1.5 Modell (ein Sequence-to-Sequence Transformer) analysiert den Text vollständig und identifiziert die relevanten Informationen für jedes Template-Feld.
342
- </li>
343
-
344
- <li style="margin-bottom: 1rem;">
345
- <strong style="color: #2c3e50;">Strukturierte Ausgabe</strong>: Das Modell füllt das Template mit den extrahierten Informationen:
346
- <pre style="background: #f5f5f5; padding: 1rem; border-radius: 4px; overflow-x: auto; margin: 0.5rem 0 1rem;"><code>{"earthquake location": "Japan, Yokohama", "dateline location": "Tokio"}</code></pre>
347
- </li>
348
- </ol>
349
- </div>
350
-
351
- <div style="background: #f8f9fa; padding: 1.5rem; border-radius: 8px; border-left: 4px solid #9b59b6;">
352
- <h4 style="color: #2980b9; margin-top: 0;">Technische Funktionsweise des Sprachmodells</h4>
353
-
354
- <p>Das Modell verarbeitet den Input in diesem Format:</p>
355
 
356
- <pre style="background: #f5f5f5; padding: 1rem; border-radius: 4px; overflow-x: auto;"><code>&lt;|input|&gt;
357
- ### Template:
358
- {"earthquake location": "", "dateline location": ""}
359
- ### Text:
360
- Neues Erdbeben in Japan. Aus Tokio wird berichtet, daß in Yokohama bei einem Erdbeben sechs Personen getötet...
361
- &lt;|output|&gt;</code></pre>
362
 
363
- <p style="margin-top: 1.5rem;">Intern erfolgt die Verarbeitung in mehreren Schritten:</p>
364
-
365
- <ol style="padding-left: 1.5rem;">
366
- <li style="margin-bottom: 0.5rem;"><strong style="color: #2c3e50;">Tokenisierung</strong>: Der Text wird in bearbeitbare Einheiten zerlegt.</li>
367
- <li style="margin-bottom: 0.5rem;"><strong style="color: #2c3e50;">Kontextuelle Analyse</strong>: Der Transformer-Mechanismus ermöglicht die Analyse von Beziehungen zwischen allen Textteilen gleichzeitig.</li>
368
- <li style="margin-bottom: 0.5rem;"><strong style="color: #2c3e50;">Selektive Aufmerksamkeit</strong>: Das Modell fokussiert sich auf Textpassagen, die Antworten auf die impliziten Fragen enthalten könnten.</li>
369
- <li style="margin-bottom: 0.5rem;"><strong style="color: #2c3e50;">Generierung</strong>: Die erkannten Informationen werden in das vorgegebene Template eingefügt.</li>
370
- </ol>
371
- </div>
372
-
373
- <div style="margin-top: 2rem; padding: 1rem; background: #e8f4fd; border-radius: 8px; text-align: center; font-size: 0.9rem;">
374
- <p style="margin: 0;">Diese Methode ermöglicht die effiziente Extraktion historischer Daten aus unstrukturierten Quellen.</p>
375
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
 
 
377
  </div>
378
  """)
379
 
 
299
 
300
  with gr.Blocks(css=custom_css, title="Daten Strukturieren und Analysieren") as demo:
301
  gr.HTML("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
 
303
+ <style>
304
+ @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Source+Sans+Pro:wght@300;400;600&display=swap');
305
+
306
+ .methodology-container {
307
+ max-width: 100%;
308
+ padding: 30px;
309
+ background: linear-gradient(to right, #f8f9fa, #ffffff);
310
+ border-radius: 12px;
311
+ box-shadow: 0 5px 15px rgba(0,0,0,0.05);
312
+ color: #2d3748;
313
+ font-family: 'Source Sans Pro', sans-serif;
314
+ line-height: 1.6;
315
+ }
316
+
317
+ .methodology-container h2 {
318
+ font-family: 'Playfair Display', serif;
319
+ color: #2c5282;
320
+ font-size: 2.2rem;
321
+ margin-bottom: 20px;
322
+ border-bottom: 2px solid #4299e1;
323
+ padding-bottom: 10px;
324
+ }
325
+
326
+ .methodology-container h3 {
327
+ font-family: 'Playfair Display', serif;
328
+ color: #2b6cb0;
329
+ font-size: 1.8rem;
330
+ margin-top: 30px;
331
+ margin-bottom: 15px;
332
+ }
333
+
334
+ .methodology-container h4 {
335
+ font-family: 'Source Sans Pro', sans-serif;
336
+ color: #3182ce;
337
+ font-size: 1.3rem;
338
+ font-weight: 600;
339
+ margin-top: 25px;
340
+ margin-bottom: 12px;
341
+ }
342
+
343
+ .methodology-container p {
344
+ font-size: 1.1rem;
345
+ margin-bottom: 15px;
346
+ text-align: justify;
347
+ }
348
+
349
+ .methodology-container .intro {
350
+ font-size: 1.2rem;
351
+ color: #4a5568;
352
+ line-height: 1.7;
353
+ border-left: 4px solid #4299e1;
354
+ padding-left: 15px;
355
+ margin: 20px 0;
356
+ }
357
+
358
+ .methodology-container ol, .methodology-container ul {
359
+ padding-left: 20px;
360
+ margin-bottom: 20px;
361
+ }
362
+
363
+ .methodology-container li {
364
+ margin-bottom: 12px;
365
+ }
366
+
367
+ .methodology-container strong {
368
+ color: #2c5282;
369
+ font-weight: 600;
370
+ }
371
+
372
+ .methodology-container code {
373
+ background-color: #edf2f7;
374
+ border-radius: 3px;
375
+ font-family: monospace;
376
+ padding: 3px 5px;
377
+ color: #2d3748;
378
+ }
379
+
380
+ .methodology-container pre {
381
+ background-color: #f7fafc;
382
+ border-radius: 6px;
383
+ padding: 15px;
384
+ margin: 15px 0;
385
+ overflow: auto;
386
+ border-left: 3px solid #4299e1;
387
+ }
388
+
389
+ .methodology-container pre code {
390
+ background-color: transparent;
391
+ padding: 0;
392
+ color: #2d3748;
393
+ }
394
+
395
+ .process-step {
396
+ background-color: #ebf8ff;
397
+ border-radius: 8px;
398
+ padding: 15px 15px 15px 20px;
399
+ margin-bottom: 15px;
400
+ border-left: 5px solid #4299e1;
401
+ transition: transform 0.2s ease-in-out;
402
+ }
403
+
404
+ .process-step:hover {
405
+ transform: translateX(5px);
406
+ box-shadow: 0 4px 6px rgba(0,0,0,0.05);
407
+ }
408
+
409
+ .section-divider {
410
+ height: 3px;
411
+ background: linear-gradient(to right, #4299e1, transparent);
412
+ margin: 30px 0;
413
+ }
414
+
415
+ .highlight-box {
416
+ background-color: #e6fffa;
417
+ border-radius: 8px;
418
+ padding: 20px;
419
+ margin: 20px 0;
420
+ border-left: 5px solid #38b2ac;
421
+ }
422
+ </style>
423
+ <div class="methodology-container">
424
+ <h2>Historische Textanalyse und Kartierung</h2>
425
+ <p class="intro">In dieser Unterrichtseinheit befassen wir uns mit einer Methode zur Strukturierung unstrukturierter historischer Texte. Im Kern verbindet unsere Anwendung die systematische Strukturierung von Daten mit einem auf Informationsextrahierung trainiertes Sprachmodell, das auf der Question-Answering-Methode basiert. Diese Methode extrahiert Text auf der Basis von Fragen, wie etwa „Wo fand das Erdbeben statt"? Dies ermöglicht die Extrahierung des Erdbebenortes, auch wenn im Text selbst noch andere Orte genannt werden.</p>
426
+
427
+ <div class="section-divider"></div>
428
+
429
+ <h3>Methodik: Vom unstrukturierten Text zur strukturierten Information</h3>
430
+
431
+ <p>Die grundlegende Herausforderung bei der Arbeit mit historischen Quellen ist, dass relevante Informationen in langen Fließtexten eingebettet sind und manuell mühsam extrahiert werden müssen. Dieser Ansatz automatisiert diesen Prozess.</p>
432
+
433
+ <h4>Wie funktioniert die Informationsextraktion?</h4>
434
+
435
+ <ol>
436
+ <li class="process-step">
437
+ <strong>Template-Definition</strong>: Sie definieren ein JSON-Template mit den Informationstypen, die Sie extrahieren möchten:
438
+ <pre><code>{"earthquake location": "", "dateline location": ""}</code></pre>
439
+ </li>
440
 
441
+ <li class="process-step">
442
+ <strong>Question-Answering-Methode</strong>: Das Sprachmodell interpretiert jedes leere Feld als implizite Frage:
443
+ <ul>
444
+ <li><code>"earthquake location": ""</code> "Wo ist das Erdbeben passiert?"</li>
445
+ <li><code>"dateline location": ""</code> → "Von wo wird berichtet?"</li>
 
 
 
 
 
 
446
  </ul>
447
+ </li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
 
449
+ <li class="process-step">
450
+ <strong>Sprachmodell-Verarbeitung</strong>: Das NuExtract-1.5 Modell (ein Sequence-to-Sequence Transformer) analysiert den Text vollständig und identifiziert die relevanten Informationen für jedes Template-Feld.
451
+ </li>
 
 
 
452
 
453
+ <li class="process-step">
454
+ <strong>Strukturierte Ausgabe</strong>: Das Modell füllt das Template mit den extrahierten Informationen:
455
+ <pre><code>{"earthquake location": "Japan, Yokohama", "dateline location": "Tokio"}</code></pre>
456
+ </li>
457
+ </ol>
458
+
459
+ <div class="section-divider"></div>
460
+
461
+ <h4>Technische Funktionsweise des Sprachmodells</h4>
462
+
463
+ <p>Intern erfolgt die Verarbeitung in mehreren Schritten:</p>
464
+
465
+ <ol>
466
+ <li class="process-step">
467
+ <strong>Tokenisierung</strong>: Der Text wird in bearbeitbare Einheiten zerlegt.
468
+ </li>
469
+ <li class="process-step">
470
+ <strong>Kontextuelle Analyse</strong>: Der Transformer-Mechanismus ermöglicht die Analyse von Beziehungen zwischen allen Textteilen gleichzeitig.
471
+ </li>
472
+ <li class="process-step">
473
+ <strong>Selektive Aufmerksamkeit</strong>: Das Modell fokussiert sich auf Textpassagen, die Antworten auf die impliziten Fragen enthalten könnten.
474
+ </li>
475
+ <li class="process-step">
476
+ <strong>Generierung</strong>: Die erkannten Informationen werden in das vorgegebene Template eingefügt.
477
+ </li>
478
+ </ol>
479
+
480
+ <div class="section-divider"></div>
481
+
482
+ <h3>Die Kartierungsfunktion</h3>
483
+
484
+ <div class="highlight-box">
485
+ <p>Nach der Extraktion der Ortsangaben ermöglicht unsere Anwendung die automatische Visualisierung dieser Daten auf einer interaktiven Karte:</p>
486
+ </div>
487
+
488
+ <ol>
489
+ <li class="process-step">
490
+ <strong>Geokodierung</strong>: Die extrahierten Ortsnamen werden mittels eines geografischen Dienstes in geografische Koordinaten (Längen- und Breitengrade) umgewandelt.
491
+ </li>
492
+ <li class="process-step">
493
+ <strong>Kartenerstellung</strong>: Die Koordinaten werden auf einer interaktiven Karte platziert, wobei jeder Ort durch einen Marker dargestellt wird.
494
+ </li>
495
+ <li class="process-step">
496
+ <strong>Kontextinformationen</strong>: Beim Klick auf einen Marker werden zusätzliche Informationen aus dem Originaltext angezeigt.
497
+ </li>
498
+ <li class="process-step">
499
+ <strong>Räumliche Analyse</strong>: Die Karte ermöglicht die visuelle Analyse der räumlichen Verteilung historischer Ereignisse.
500
+ </li>
501
+ </ol>
502
 
503
+ <p>Dieser kombinierte Ansatz aus Textextraktion und geografischer Visualisierung eröffnet neue Möglichkeiten für die räumliche Analyse historischer Quellen und erlaubt es, geografische Muster zu erkennen, die in den reinen Textdaten nicht unmittelbar sichtbar wären.</p>
504
  </div>
505
  """)
506