@@ -42,21 +42,55 @@ class IntentCategorization(BaseModel):
4242
4343
4444class LLMDescriptionScorer (BaseDescriptionScorer ):
45- """LLM-based description scorer that uses structured output to categorize intents .
45+ """LLM-based description scorer for zero-shot intent classification using structured output .
4646
47- This scorer uses a language model with structured output to categorize intent descriptions
48- into three categories based on their probability to correspond to a given text sample:
49- - Most probable (probability 1.0)
50- - Promising but not confident (probability 0.5)
51- - Unlikely (probability 0.0)
47+ This scorer uses a Large Language Model (LLM) with structured output to perform
48+ zero-shot intent classification. The LLM is prompted to categorize intent descriptions
49+ into three probability levels for each utterance:
50+ - Most probable (probability 1.0): Intents that are most likely to match the utterance
51+ - Promising (probability 0.5): Intents that are plausible but less confident
52+ - Unlikely (probability 0.0): All other intents (implicit)
53+
54+ This approach leverages the reasoning capabilities of LLMs to understand complex
55+ relationships between utterances and intent descriptions, potentially achieving
56+ high accuracy for nuanced classification tasks. However, it requires API access
57+ to LLM services and can be slower and more expensive than encoder-based methods.
5258
5359 Args:
54- generator_config: Configuration for the Generator instance
55- temperature: Temperature parameter for scaling classifier logits, defaults to 1.0
56- max_concurrent: Maximum number of concurrent async calls to LLM, defaults to 15
57- max_per_second: Maximum number of API calls per second, defaults to 10
58- max_retries: Maximum number of retry attempts for failed validations, defaults to 3
59- backend: Backend to use for structured output, either "openai" or "vllm", defaults to "openai"
60+ generator_config: Configuration for the Generator instance (LLM model settings)
61+ temperature: Temperature parameter for scaling classifier logits (default: 1.0)
62+ max_concurrent: Maximum number of concurrent async calls to LLM (default: 15)
63+ max_per_second: Maximum number of API calls per second for rate limiting (default: 10)
64+ max_retries: Maximum number of retry attempts for failed API calls (default: 3)
65+ multilabel: Flag indicating classification task type
66+
67+ Example:
68+ --------
69+ .. code-block::
70+
71+ from autointent.modules.scoring import LLMDescriptionScorer
72+
73+ # Initialize LLM scorer with OpenAI GPT
74+ scorer = LLMDescriptionScorer(
75+ temperature=1.0,
76+ max_concurrent=10,
77+ max_per_second=5,
78+ max_retries=2
79+ )
80+
81+ # Zero-shot classification with intent descriptions
82+ descriptions = [
83+ "User wants to book or reserve transportation like flights, trains, or hotels",
84+ "User wants to cancel an existing booking or reservation",
85+ "User asks about weather conditions or forecasts"
86+ ]
87+
88+ # Fit using descriptions only (zero-shot approach)
89+ scorer.fit([], [], descriptions)
90+
91+ # Make predictions on new utterances
92+ test_utterances = ["Reserve a hotel room", "Delete my booking"]
93+ probabilities = scorer.predict(test_utterances)
6094 """
6195
6296 name = "description_llm"
@@ -68,8 +102,9 @@ def __init__(
68102 max_concurrent : PositiveInt | None = 15 ,
69103 max_per_second : PositiveInt = 10 ,
70104 max_retries : PositiveInt = 3 ,
105+ multilabel : bool = False ,
71106 ) -> None :
72- super ().__init__ (temperature = temperature )
107+ super ().__init__ (temperature = temperature , multilabel = multilabel )
73108
74109 self .generator_config = generator_config or {}
75110 self .max_concurrent = max_concurrent
@@ -92,12 +127,13 @@ def from_context(
92127 max_concurrent = max_concurrent ,
93128 max_per_second = max_per_second ,
94129 max_retries = max_retries ,
130+ multilabel = context .is_multilabel (),
95131 )
96132
97133 def get_implicit_initialization_params (self ) -> dict [str , Any ]:
98- return {}
134+ return {"multilabel" : self . _multilabel }
99135
100- def _fit_implementation (self , utterances : list [ str ], descriptions : list [str ]) -> None :
136+ def _fit_implementation (self , descriptions : list [str ]) -> None :
101137 """Fit the LLM scorer by initializing the generator and storing descriptions.
102138
103139 Args:
0 commit comments