- "markdown": "---\ntitle: LLMVec\n---\n\n\n\n```python\nLLMVec(backend='', model='', _cache='_mall_cache', **kwargs)\n```\n\nClass that adds ability to use an LLM to run batch predictions\n\n\n::: {#8b084029 .cell execution_count=1}\n``` {.python .cell-code}\nfrom chatlas import ChatOllama\nfrom mall import LLMVec\n\nchat = ChatOllama(model = \"llama3.2\")\n\nllm = LLMVec(chat) \n```\n:::\n\n\n## Methods\n\n| Name | Description |\n| --- | --- |\n| [classify](#mall.LLMVec.classify) | Classify text into specific categories. |\n| [custom](#mall.LLMVec.custom) | Provide the full prompt that the LLM will process. |\n| [extract](#mall.LLMVec.extract) | Pull a specific label from the text. |\n| [sentiment](#mall.LLMVec.sentiment) | Use an LLM to run a sentiment analysis |\n| [summarize](#mall.LLMVec.summarize) | Summarize the text down to a specific number of words. |\n| [translate](#mall.LLMVec.translate) | Translate text into another language. |\n| [verify](#mall.LLMVec.verify) | Check to see if something is true about the text. |\n\n### classify { #mall.LLMVec.classify }\n\n```python\nLLMVec.classify(x, labels='', additional='')\n```\n\nClassify text into specific categories.\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|------------|--------|-------------------------------------------------------------------------------------------------------------------------|------------|\n| x | list | A list of texts | _required_ |\n| labels | list | A list or a DICT object that defines the categories to classify the text as. It will return one of the provided labels. | `''` |\n| additional | str | Inserts this text into the prompt sent to the LLM | `''` |\n\n#### Examples {.doc-section .doc-section-examples}\n\n::: {#1cda03a7 .cell execution_count=2}\n``` {.python .cell-code}\nllm.classify(['this is important!', 'there is no rush'], ['urgent', 'not urgent'])\n```\n\n::: {.cell-output .cell-output-display execution_count=2}\n```\n['urgent', None]\n```\n:::\n:::\n\n\n### custom { #mall.LLMVec.custom }\n\n```python\nLLMVec.custom(x, prompt='', valid_resps='')\n```\n\nProvide the full prompt that the LLM will process.\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|--------|--------|----------------------------------------------------|------------|\n| x | list | A list of texts | _required_ |\n| prompt | str | The prompt to send to the LLM along with the `col` | `''` |\n\n### extract { #mall.LLMVec.extract }\n\n```python\nLLMVec.extract(x, labels='', additional='')\n```\n\nPull a specific label from the text.\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|------------|--------|--------------------------------------------------------------------------------|------------|\n| x | list | A list of texts | _required_ |\n| labels | list | A list or a DICT object that defines tells the LLM what to look for and return | `''` |\n| additional | str | Inserts this text into the prompt sent to the LLM | `''` |\n\n#### Examples {.doc-section .doc-section-examples}\n\n::: {#ad9d5754 .cell execution_count=3}\n``` {.python .cell-code}\nllm.extract(['bob smith, 123 3rd street'], labels=['name', 'address'])\n```\n\n::: {.cell-output .cell-output-display execution_count=3}\n```\n['bob smith | 123 3rd street']\n```\n:::\n:::\n\n\n### sentiment { #mall.LLMVec.sentiment }\n\n```python\nLLMVec.sentiment(x, options=['positive', 'negative', 'neutral'], additional='')\n```\n\nUse an LLM to run a sentiment analysis\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|------------|--------------|----------------------------------------------------------------|---------------------------------------|\n| x | list | A list of texts | _required_ |\n| options | list or dict | A list of the sentiment options to use, or a named DICT object | `['positive', 'negative', 'neutral']` |\n| additional | str | Inserts this text into the prompt sent to the LLM | `''` |\n\n#### Examples {.doc-section .doc-section-examples}\n\n::: {#40fabaef .cell execution_count=4}\n``` {.python .cell-code}\nllm.sentiment(['I am happy', 'I am sad'])\n```\n\n::: {.cell-output .cell-output-display execution_count=4}\n```\n['positive', 'negative']\n```\n:::\n:::\n\n\n### summarize { #mall.LLMVec.summarize }\n\n```python\nLLMVec.summarize(x, max_words=10, additional='')\n```\n\nSummarize the text down to a specific number of words.\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|------------|--------|---------------------------------------------------|------------|\n| x | list | A list of texts | _required_ |\n| max_words | int | Maximum number of words to use for the summary | `10` |\n| additional | str | Inserts this text into the prompt sent to the LLM | `''` |\n\n#### Examples {.doc-section .doc-section-examples}\n\n::: {#60841322 .cell execution_count=5}\n``` {.python .cell-code}\nllm.summarize(['This has been the best TV Ive ever used. Great screen, and sound.'], max_words = 5)\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n```\n['best tv purchase experience ever']\n```\n:::\n:::\n\n\n### translate { #mall.LLMVec.translate }\n\n```python\nLLMVec.translate(x, language='', additional='')\n```\n\nTranslate text into another language.\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|------------|--------|------------------------------------------------------------|------------|\n| x | list | A list of texts | _required_ |\n| language | str | The target language to translate to. For example 'French'. | `''` |\n| additional | str | Inserts this text into the prompt sent to the LLM | `''` |\n\n#### Examples {.doc-section .doc-section-examples}\n\n::: {#7df35455 .cell execution_count=6}\n``` {.python .cell-code}\nllm.translate(['This has been the best TV Ive ever used. Great screen, and sound.'], language = 'spanish')\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n```\n['Esta ha sido la mejor TV que he tenido, pantalla maravillosa y sonido increíble.']\n```\n:::\n:::\n\n\n### verify { #mall.LLMVec.verify }\n\n```python\nLLMVec.verify(x, what='', yes_no=[1, 0], additional='')\n```\n\nCheck to see if something is true about the text.\n\n#### Parameters {.doc-section .doc-section-parameters}\n\n| Name | Type | Description | Default |\n|------------|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|\n| x | list | A list of texts | _required_ |\n| what | str | The statement or question that needs to be verified against the provided text | `''` |\n| yes_no | list | A positional list of size 2, which contains the values to return if true and false. The first position will be used as the 'true' value, and the second as the 'false' value | `[1, 0]` |\n| additional | str | Inserts this text into the prompt sent to the LLM | `''` |\n\n",
0 commit comments