Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

2

Omar Khattabf7fd96353ebe
diff --git a/docs/building-blocks/2-modules.md b/docs/building-blocks/2-modules.md
index 0eacef9fe..c06615d83 100644
--- a/docs/building-blocks/2-modules.md
+++ b/docs/building-blocks/2-modules.md
@@ -3,3 +3,37 @@ sidebar_position: 3
---
# Modules
+
+A **DSPy module** is a building block for programs that use LMs.
+
+- Each built-in module abstracts a **prompting technique** (like chain of thought or ReAct). Crucially, they are generalized to handle any [DSPy Signature]().
+
+- A DSPy module has **learnable parameters** (i.e., the little pieces comprising the prompt and the LM weights) and can be invoked (called) to process inputs and return outputs.
+
+- Multiple modules can be composed into bigger modules (programs). DSPy modules are inspired directly by NN modules in PyTorch, but applied to LM programs.
+
+
+## How do I use a built-in module, like `dspy.Predict` or `dspy.ChainOfThought`?
+
+Let's start with the most fundamental module, `dspy.Predict`. Internally, all other DSPy modules are just built using `dspy.Predict`.
+
+We'll assume you are already at least a little familiar with [DSPy signatures], which are declarative specs for defining the behavior of any module we use in DSPy.
+
+To use a module, we first **declare** it by giving it a signature. Then we **call** the module with the input arguments, and extract the output fields!
+
+```python
+sentence = "it's a charming and often affecting journey." # example from the SST-2 dataset.
+
+# 1) Declare with a signature.
+classify = dspy.Predict('sentence -> sentiment')
+
+# 2) Call with input argument(s).
+response = classify(sentence=sentence)
+
+# 3) Access the output.
+print(response.sentiment)
+```
+**Output:**
+```text
+Positive
+```