Labeler
Labeler (class)
Base class for labeling operations using an LLM.
Parameters (constructor)
llm_model
(str): Name of the LLM model to use (e.g.,"openai::gpt-4o-mini"
).unknown_label
(str, optional): Label for unclear classifications (default:"unclear"
).temperature
(float, optional): Temperature for the LLM model (default:0
).
Key Methods
_deserialize_label_responses(responses)
: Deserialize LLM responses into a DataFrame._run_labeling_prompts(prompts, system_prompt, max_workers=100)
: Run prompts concurrently and collect LLM responses.
Example
get_prompts_for_labeler
Generate a list of user messages for each text to be labelled by the labeling system.
Parameters
texts
(List[str]): Texts to get the labels from.textsconfig
(Optional[List[Dict]], optional): Optional fields for the prompts in addition to the text.
Returns
List[str]
: List of prompts for the labeling system.
Example
parse_labeling_response
Parse the response from the LLM model used for labeling.
Parameters
response
(str): The response from the LLM model as a raw string.
Returns
dict
: Parsed dictionary with keys:motivation
label
Example
NarrativeLabeler (class)
LLM-powered labeler for narrative labeling.
Parameters (constructor)
llm_model
(str): Name of the LLM model to use.label_prompt
(str, optional): Custom prompt for labeling (default: uses system prompt).unknown_label
(str, optional): Label for unclear classifications (default:"unclear"
).temperature
(float, optional): Temperature for the LLM model (default:0
).
Key Methods
get_labels(theme_labels, texts, max_workers=50)
: Label a list of texts with the provided theme labels.post_process_dataframe(df)
: Post-process the labeled DataFrame for export.
Example
get_prompts_for_labeler
Generate a list of user messages for each text to be labelled by the labeling system.
Parameters
texts
(List[str]): Texts to get the labels from.textsconfig
(Optional[List[Dict]], optional): Optional fields for the prompts in addition to the text.
Returns
List[str]
: List of prompts for the labeling system.
Example
parse_labeling_response
Parse the response from the LLM model used for labeling.
Parameters
response
(str): The response from the LLM model as a raw string.
Returns
dict
: Parsed dictionary with keys:motivation
label
Example
ScreenerLabeler (class)
LLM-powered labeler for thematic screener labeling.
Parameters (constructor)
llm_model
(str): Name of the LLM model to use.label_prompt
(str, optional): Custom prompt for labeling (default: uses system prompt).unknown_label
(str, optional): Label for unclear classifications (default:"unclear"
).temperature
(float, optional): Temperature for the LLM model (default:0
).
Key Methods
get_labels(main_theme, labels, texts, max_workers=50)
: Label a list of texts with the provided main theme and labels.post_process_dataframe(df)
: Post-process the labeled DataFrame for export, including company/entity columns and placeholder replacement.
Example
get_prompts_for_labeler
Generate a list of user messages for each text to be labelled by the labeling system.
Parameters
texts
(List[str]): Texts to get the labels from.textsconfig
(Optional[List[Dict]], optional): Optional fields for the prompts in addition to the text.
Returns
List[str]
: List of prompts for the labeling system.
Example
parse_labeling_response
Parse the response from the LLM model used for labeling.
Parameters
response
(str): The response from the LLM model as a raw string.
Returns
dict
: Parsed dictionary with keys:motivation
label
Example