@@ -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.
111113pipeline = Pipeline(task)
@@ -115,13 +117,16 @@ doc = Doc(text="The new telescope captures images of distant galaxies.")
115117
116118# Run pipeline and print results.
117119docs = 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**
0 commit comments