pysparky.functions.ai.llm
Functions
| Name | Description |
|---|---|
build_text_generation_udf | Creates a Spark UDF for text generation using a Hugging Face model and tokenizer. |
build_text_generation_udffunction#
def build_text_generation_udf(model_bc: Broadcast, tokenizer_bc: Broadcast, system_prompt: str) -> UserDefinedFunctionCreates a Spark UDF for text generation using a Hugging Face model and tokenizer.
This function sets up a user-defined function (UDF) that can be used in Spark DataFrames to perform text generation. It uses a broadcasted Hugging Face model and tokenizer to ensure efficient distribution across Spark workers.
Parameters
| Name | Type | Description |
|---|---|---|
model_bc | Broadcast | Broadcasted Hugging Face model. |
tokenizer_bc | Broadcast | Broadcasted Hugging Face tokenizer. |
system_prompt | str | Prompt to prepend to each input string before generation. |
Returns
functionUserDefinedFunction- A Spark UDF that takes a string input and returns the generated text.
Raises
TypeError- If
model_bcortokenizer_bcis not a Broadcast instance.