You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`labels`|`Union[List[str], str]`|| List of labels or str of comma-separated list of labels. |
618
+
|`label_definitions`|`Optional[Dict[str, str]]`|`None`| Dictionary of label definitions. Included in the prompt, if set. |
619
+
|`template`|`str`|[`textcat.jinja`](./spacy_llm/tasks/templates/textcat.jinja)| Custom prompt template to send to LLM backend. Default templates for each task are located in the `spacy_llm/tasks/templates` directory. |
620
+
|`examples`|`Optional[Callable[[], Iterable[Any]]]`|`None`| Optional function that generates examples for few-shot learning. |
621
+
|`normalizer`|`Optional[Callable[[str], str]]`|`None`| Function that normalizes the labels as returned by the LLM. If `None`, falls back to `spacy.LowercaseNormalizer.v1`. |
622
+
|`exclusive_classes`|`bool`|`False`| If set to `True`, only one label per document should be valid. If set to `False`, one document can have multiple labels. |
623
+
|`allow_none`|`bool`|`True`| When set to `True`, allows the LLM to not return any of the given label. The resulting dict in `doc.cats` will have `0.0` scores for all labels. |
624
+
|`verbose`|`bool`|`False`| If set to `True`, warnings will be generated when the LLM returns invalid responses. |
625
+
626
+
To perform few-shot learning, you can write down a few examples in a separate file, and provide these to be injected into the prompt to the LLM.
627
+
The default reader `spacy.FewShotReader.v1` supports `.yml`, `.yaml`, `.json` and `.jsonl`.
628
+
629
+
```json
630
+
[
631
+
{
632
+
"text": "You look great!",
633
+
"answer": "Compliment"
634
+
},
635
+
{
636
+
"text": "You are not very clever at all.",
637
+
"answer": "Insult"
638
+
}
639
+
]
640
+
```
641
+
642
+
```ini
643
+
[components.llm.task]
644
+
@llm_tasks = "spacy.TextCat.v3"
645
+
labels = ["COMPLIMENT", "INSULT"]
646
+
label_definitions = {
647
+
"COMPLIMENT": "a polite expression of praise or admiration.",
648
+
"INSULT": "a disrespectful or scornfully abusive remark or act."
649
+
}
650
+
[components.llm.task.examples]
651
+
@misc = "spacy.FewShotReader.v1"
652
+
path = "textcat_examples.json"
653
+
```
654
+
599
655
#### spacy.TextCat.v2
600
656
601
-
The built-in TextCat task supports both zero-shot and few-shot prompting.
657
+
Version 2 of the built-in TextCat task supports both zero-shot and few-shot prompting and includes an improved prompt
0 commit comments