You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# optimize=False by default - enables faster startup
34
34
```
35
35
36
36
## When You Have Training Data
@@ -74,8 +74,19 @@ Optimization can significantly improve accuracy on real-world tasks:
74
74
75
75
## Persisting Results
76
76
77
-
Saving/loading an optimized extractor is not yet implemented.
78
-
For now, re-run `optimize()` when you start up, or persist your training data and configuration.
77
+
Save and load optimized extractors to reuse them without re-running optimization:
78
+
79
+
```python
80
+
# Save after optimization
81
+
extractor.save("./my_extractor")
82
+
83
+
# Load later
84
+
from langstruct import LangStruct
85
+
loaded = LangStruct.load("./my_extractor")
86
+
87
+
# Use immediately - optimization is preserved
88
+
result = loaded.extract("new text")
89
+
```
79
90
80
91
## Advanced (If You Need It)
81
92
@@ -86,7 +97,6 @@ Most users don't need this, but if you want more control:
86
97
extractor.optimize(
87
98
texts=training_texts,
88
99
expected_results=good_results,
89
-
num_trials=50, # More trials = better results (takes longer)
90
100
validation_split=0.3# Use 30% for testing improvements
91
101
)
92
102
```
@@ -110,26 +120,26 @@ extractor.optimize(
110
120
111
121
## Common Questions
112
122
113
-
**Q: Do I always need training data?**
114
-
A: No! Optimization can work without training data, but providing examples improves results significantly.
123
+
**Q: Do I always need training data?**
124
+
A: You need example texts, but not necessarily expected outputs. If you don't provide `expected_results`, LangStruct uses the LLM's confidence ratings to optimize. Providing expected outputs significantly improves accuracy.
115
125
116
-
**Q: How long does optimization take?**
126
+
**Q: How long does optimization take?**
117
127
A: Usually 1-5 minutes for typical datasets (10-100 examples).
118
128
119
-
**Q: Can I optimize an already optimized extractor?**
120
-
A: Yes! You can keep optimizing with new data as you get it.
129
+
**Q: Can I optimize an already optimized extractor?**
130
+
A: Yes, you can continue optimizing with new data as you collect it.
121
131
122
-
**Q: Will this make my extractions slower?**
123
-
A: No - optimization happens once during training. Production extraction speed is the same.
132
+
**Q: Will this make my extractions slower?**
133
+
A: No - optimization happens once during training. Production extraction speed is unchanged.
124
134
125
-
**Q: What happens when I switch models?**
126
-
A: Just change the model and re-optimize! Same training data, same accuracy - zero prompt rewriting needed.
135
+
**Q: What happens when I switch models?**
136
+
A: Change the model and re-optimize with the same training data. No prompt rewriting needed.
127
137
128
138
## Next Steps
129
139
130
140
<CardGrid>
131
141
<Cardtitle="Try It Now"icon="laptop">
132
-
Create a LangStruct extractor and enable optimization when you need accuracy!
142
+
Create a LangStruct extractor and enable optimization when you need accuracy.
133
143
</Card>
134
144
<Cardtitle="Source Grounding"icon="document">
135
145
[Track where information comes from](/source-grounding/)
0 commit comments