Update README.md
Browse files
README.md
CHANGED
|
@@ -161,6 +161,119 @@ outputs = model.generate(
|
|
| 161 |
|
| 162 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 163 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
---
|
| 165 |
|
| 166 |
## Training focus
|
|
|
|
| 161 |
|
| 162 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 163 |
```
|
| 164 |
+
|
| 165 |
+
---
|
| 166 |
+
|
| 167 |
+
## Conditional Generation
|
| 168 |
+
|
| 169 |
+
```python
|
| 170 |
+
!pip install git+https://github.com/tabularis-ai/guidegen.git
|
| 171 |
+
|
| 172 |
+
import sys
|
| 173 |
+
import os
|
| 174 |
+
import json
|
| 175 |
+
import time
|
| 176 |
+
|
| 177 |
+
import guidegen as gg
|
| 178 |
+
from pydantic import BaseModel, Field
|
| 179 |
+
from typing import Literal, List
|
| 180 |
+
|
| 181 |
+
# Hugging Face access token - set via environment variable or .env file
|
| 182 |
+
# You can set it with: export HUGGINGFACE_HUB_TOKEN=your_token_here
|
| 183 |
+
# Or create a .env file with: HUGGINGFACE_HUB_TOKEN=your_token_here
|
| 184 |
+
|
| 185 |
+
MODEL_NAME = "tabularisai/Faust-1"
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# --- Schema ---
|
| 189 |
+
class EmailSummary(BaseModel):
|
| 190 |
+
"""Structured summary of an email."""
|
| 191 |
+
Absender: str = Field(description="Der Name des Absenders.")
|
| 192 |
+
Betreff: str = Field(description="Worum geht es in der E-Mail? (max 5 Wörter)")
|
| 193 |
+
Zusammenfassung: str = Field(description="Kurze Zusammenfassung (max 2 Sätze).")
|
| 194 |
+
Prioritaet: Literal["hoch", "mittel", "niedrig"] = Field(description="Wie wichtig die E-Mail ist.")
|
| 195 |
+
# AntwortNoetig: bool = Field(description="Muss man auf die E-Mail antworten?")
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
# --- Input ---
|
| 199 |
+
email_text = """Hallo Jens,
|
| 200 |
+
|
| 201 |
+
wir hatten uns bei CampusFounders im Rahmen unserer Pre-Seed-Runde kennengelernt.
|
| 202 |
+
Seitdem haben wir große Fortschritte gemacht und bereiten aktuell unsere Seed-Runde vor.
|
| 203 |
+
|
| 204 |
+
Wir entwickeln eine Infrastruktur für hocheffiziente, lokal trainierbare KI-Modelle – vollständig ohne Cloud.
|
| 205 |
+
Sehr gern würden wir uns mit dir austauschen und prüfen, ob ein Intro zu US-VCs oder ein Gespräch mit Crestlight möglich wäre.
|
| 206 |
+
|
| 207 |
+
Anbei ein kurzer OnePager zur Weiterleitung.
|
| 208 |
+
|
| 209 |
+
Beste Grüße
|
| 210 |
+
Ricard"""
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
# --- Prompt ---
|
| 215 |
+
prompt = f"""
|
| 216 |
+
Du bist ein intelligenter Assistent, der E-Mails analysiert und als JSON zusammenfasst.
|
| 217 |
+
Halte die Zusammenfassung kurz (1-2 Sätze). Betreff maximal 5 Wörter.
|
| 218 |
+
|
| 219 |
+
--- Beispiel ---
|
| 220 |
+
E-Mail-Text:
|
| 221 |
+
Sehr geehrte Damen und Herren, ich wollte nur nachfragen, ob meine Bestellung #12345 schon versandt wurde. Vielen Dank, Max Mustermann
|
| 222 |
+
JSON-Antwort:
|
| 223 |
+
{{
|
| 224 |
+
"Absender": "Max Mustermann",
|
| 225 |
+
"Betreff": "Bestellstatus Anfrage",
|
| 226 |
+
"Zusammenfassung": "Anfrage zum Versandstatus der Bestellung #12345.",
|
| 227 |
+
"Prioritaet": "mittel",
|
| 228 |
+
}}
|
| 229 |
+
--- Ende Beispiel ---
|
| 230 |
+
|
| 231 |
+
Jetzt analysiere die folgende E-Mail und erstelle das JSON-Objekt.
|
| 232 |
+
|
| 233 |
+
E-Mail-Text:
|
| 234 |
+
{email_text}
|
| 235 |
+
"""
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def main():
|
| 239 |
+
print("=" * 60)
|
| 240 |
+
print("EMAIL SUMMARIZATION WITH GUIDEGEN")
|
| 241 |
+
print("=" * 60)
|
| 242 |
+
|
| 243 |
+
print(f"\nLoading model: {MODEL_NAME}")
|
| 244 |
+
load_start = time.time()
|
| 245 |
+
|
| 246 |
+
gen = gg.GuideGen(
|
| 247 |
+
MODEL_NAME,
|
| 248 |
+
verbose=True,
|
| 249 |
+
use_chat_template=True,
|
| 250 |
+
enable_thinking=False,
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
load_time = time.time() - load_start
|
| 254 |
+
print(f"Model loaded in {load_time:.2f}s")
|
| 255 |
+
|
| 256 |
+
# --- Generate ---
|
| 257 |
+
print("\nGenerating structured summary...")
|
| 258 |
+
gen_start = time.time()
|
| 259 |
+
|
| 260 |
+
options = gg.GuideGenOptions(
|
| 261 |
+
temperature=0.6,
|
| 262 |
+
max_tokens=400,
|
| 263 |
+
do_sample=False,
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
summary = gen.generate(prompt, EmailSummary, options=options)
|
| 267 |
+
|
| 268 |
+
gen_time = time.time() - gen_start
|
| 269 |
+
print(f"Generation complete in {gen_time:.2f}s")
|
| 270 |
+
|
| 271 |
+
# --- Output ---
|
| 272 |
+
print("\n--- Email Summary (JSON) ---")
|
| 273 |
+
print(json.dumps(summary.model_dump(), indent=2, ensure_ascii=False))
|
| 274 |
+
print(f"\n Model load: {load_time:.2f}s | Generation: {gen_time:.2f}s | Total: {load_time + gen_time:.2f}s")
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
---
|
| 278 |
|
| 279 |
## Training focus
|