Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Add api reference for dspy.SIMBA (#8218)

TomuHirata1e64b4e61a31
diff --git a/docs/docs/api/optimizers/SIMBA.md b/docs/docs/api/optimizers/SIMBA.md
new file mode 100644
index 000000000..ac27d601e
--- /dev/null
+++ b/docs/docs/api/optimizers/SIMBA.md
@@ -0,0 +1,28 @@
+# dspy.SIMBA
+
+<!-- START_API_REF -->
+::: dspy.SIMBA
+ handler: python
+ options:
+ members:
+ - compile
+ - get_params
+ show_source: true
+ show_root_heading: true
+ heading_level: 2
+ docstring_style: google
+ show_root_full_path: true
+ show_object_full_path: false
+ separate_signature: false
+ inherited_members: true
+<!-- END_API_REF -->
+
+## Example Usage
+
+```python
+optimizer = dspy.SIMBA(metric=your_metric)
+optimized_program = optimizer.compile(your_program, trainset=your_trainset)
+
+# Save optimize program for future use
+optimized_program.save(f"optimized.json")
+```
diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml
index 9860e52c9..893221c79 100644
--- a/docs/mkdocs.yml
+++ b/docs/mkdocs.yml
@@ -104,6 +104,7 @@ nav:
- KNNFewShot: api/optimizers/KNNFewShot.md
- LabeledFewShot: api/optimizers/LabeledFewShot.md
- MIPROv2: api/optimizers/MIPROv2.md
+ - SIMBA: api/optimizers/SIMBA.md
- Primitives:
- Example: api/primitives/Example.md
- History: api/primitives/History.md
diff --git a/dspy/teleprompt/simba.py b/dspy/teleprompt/simba.py
index eb080521a..21461b84e 100644
--- a/dspy/teleprompt/simba.py
+++ b/dspy/teleprompt/simba.py
@@ -27,15 +27,25 @@ class SIMBA(Teleprompter):
temperature_for_candidates=0.2,
):
"""
- :param metric: A function (Example, prediction_dict) -> float
- :param bsize: mini-batch size
- :param num_candidates: how many new candidate programs to produce per iteration
- :param max_steps: how many optimization steps to run
- :param max_demos: how many demos we allow a predictor to hold before we must drop some
- :param demo_input_field_maxlen: how many characters of an input field to keep when building a new demo
- :param num_threads: how many threads for run_parallel
- :param temperature_for_sampling: temperature used for picking programs for the trajectory-sampling step
- :param temperature_for_candidates: temperature used for picking the source program for building new candidates
+ Initializes SIMBA.
+
+ Args:
+ metric (Callable): A function that takes an Example and a prediction_dict
+ as input and returns a float.
+ bsize (int, optional): Mini-batch size. Defaults to 32.
+ num_candidates (int, optional): Number of new candidate programs to produce
+ per iteration. Defaults to 6.
+ max_steps (int, optional): Number of optimization steps to run. Defaults to 8.
+ max_demos (int, optional): Maximum number of demos a predictor can hold
+ before dropping some. Defaults to 4.
+ demo_input_field_maxlen (int, optional): Maximum number of characters to keep
+ in an input field when building a new demo. Defaults to 100,000.
+ num_threads (int, optional): Number of threads for parallel execution.
+ Defaults to None.
+ temperature_for_sampling (float, optional): Temperature used for picking
+ programs during the trajectory-sampling step. Defaults to 0.2.
+ temperature_for_candidates (float, optional): Temperature used for picking
+ the source program for building new candidates. Defaults to 0.2.
"""
self.metric = metric
self.bsize = bsize