Skip to content

Commit 3e4043a

Browse files
author
Raphael Mitsch
committed
chore: Update readme example.
1 parent 9c2c492 commit 3e4043a

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ model = outlines.models.from_transformers(
105105
)
106106

107107
# Define task.
108-
task = tasks.Classification(labels=["science", "politics"], model=model)
108+
task = tasks.Classification(
109+
labels=["science", "politics"], mode='single', model=model
110+
)
109111

110112
# Define pipeline with the classification task.
111113
pipeline = Pipeline(task)
@@ -115,13 +117,16 @@ doc = Doc(text="The new telescope captures images of distant galaxies.")
115117

116118
# Run pipeline and print results.
117119
docs = list(pipeline([doc]))
120+
118121
# The `results` field contains the structured task output as a unified Pydantic model.
119-
print(docs[0].results["Classification"]) # ResultMultiLabel(label_scores=[('science', 1.0), ('politics', 0.0)])
122+
print(docs[0].results["Classification"])
123+
# -> ResultSingleLabel(label='science', score=1.0)
120124
# The `meta` field contains more information helpful for observability and debugging, such as raw model output and token count information.
121-
print(docs[0].meta) # {'Classification': {
122-
# 'raw': ['{ "science": 1.0, "politics": 0 }'],
123-
# 'usage': {'input_tokens': 2, 'output_tokens': 2, 'chunks': [{'input_tokens': 2, 'output_tokens': 2}]}}, 'usage': {'input_tokens': 2, 'output_tokens': 2}
124-
# }
125+
print(docs[0].meta)
126+
# -> {'Classification': {
127+
# 'raw': ['{ "label": "science" }'], 'usage': {'input_tokens': 83, 'output_tokens': 8, 'chunks': [{'input_tokens': 83, 'output_tokens': 8}]}}, 'usage': {'input_tokens': 83, 'output_tokens': 8},
128+
# 'cached': False
129+
# }
125130
```
126131

127132
**3. Advanced: End-to-end document AI with a hosted LLM**

sieves/tests/docs/test_readme.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def test_simple_example() -> None:
1111
)
1212

1313
# Define task.
14-
task = tasks.Classification(labels=["science", "politics"], model=model)
14+
task = tasks.Classification(
15+
labels=["science", "politics"], mode='single', model=model
16+
)
1517

1618
# Define pipeline with the classification task.
1719
pipeline = Pipeline(task)
@@ -21,13 +23,16 @@ def test_simple_example() -> None:
2123

2224
# Run pipeline and print results.
2325
docs = list(pipeline([doc]))
26+
2427
# The `results` field contains the structured task output as a unified Pydantic model.
25-
print(docs[0].results["Classification"]) # ResultMultiLabel(label_scores=[('science', 1.0), ('politics', 0.0)])
28+
print(docs[0].results["Classification"])
29+
# -> ResultSingleLabel(label='science', score=1.0)
2630
# The `meta` field contains more information helpful for observability and debugging, such as raw model output and token count information.
27-
print(docs[0].meta) # {'Classification': {
28-
# 'raw': ['{ "science": 1.0, "politics": 0 }'],
29-
# 'usage': {'input_tokens': 2, 'output_tokens': 2, 'chunks': [{'input_tokens': 2, 'output_tokens': 2}]}}, 'usage': {'input_tokens': 2, 'output_tokens': 2}
30-
# }
31+
print(docs[0].meta)
32+
# -> {'Classification': {
33+
# 'raw': ['{ "label": "science" }'], 'usage': {'input_tokens': 83, 'output_tokens': 8, 'chunks': [{'input_tokens': 83, 'output_tokens': 8}]}}, 'usage': {'input_tokens': 83, 'output_tokens': 8},
34+
# 'cached': False
35+
# }
3136

3237
def test_advanced_example() -> None:
3338
import dspy

0 commit comments

Comments
 (0)