Skip to content

Commit 1d0b262

Browse files
authored
Merge pull request #203 from explosion/chore/sync-develop-with-master
Sync `develop` with `master`
2 parents f79e0a6 + cdfd538 commit 1d0b262

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,66 @@ Except for the `spans_key` parameter, the SpanCat task reuses the configuration
596596
from the NER task.
597597
Refer to [its documentation](#spacynerv1) for more insight.
598598

599+
#### spacy.TextCat.v3
600+
601+
Version 3 (the most recent) of the built-in TextCat task supports both zero-shot and few-shot prompting. It allows
602+
setting definitions of labels. Those definitions are included in the prompt.
603+
604+
```ini
605+
[components.llm.task]
606+
@llm_tasks = "spacy.TextCat.v3"
607+
labels = ["COMPLIMENT", "INSULT"]
608+
label_definitions = {
609+
"COMPLIMENT": "a polite expression of praise or admiration.",
610+
"INSULT": "a disrespectful or scornfully abusive remark or act."
611+
}
612+
examples = null
613+
```
614+
615+
| Argument | Type | Default | Description |
616+
| ------------------- | --------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
617+
| `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+
599655
#### spacy.TextCat.v2
600656

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
658+
template.
602659

603660
```ini
604661
[components.llm.task]
@@ -644,7 +701,7 @@ path = "textcat_examples.json"
644701

645702
#### spacy.TextCat.v1
646703

647-
The original version of the built-in TextCat task supports both zero-shot and few-shot prompting.
704+
Version 1 of the built-in TextCat task supports both zero-shot and few-shot prompting.
648705

649706
```ini
650707
[components.llm.task]

spacy_llm/models/rest/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def _call_api(attempt: int) -> Optional[requests.Response]:
141141
if _HTTPRetryErrorCodes.has(response.status_code):
142142
raise ConnectionError(
143143
f"API could not be reached after {(time.time() - start_time):.3f} seconds in total and attempting to "
144-
f"connect {self._max_tries} times. Check your network connection and the API's availability."
144+
f"connect {self._max_tries} times. Check your network connection and the API's availability.\n"
145+
f"{response.status_code}\t{response.reason}"
145146
)
146147

147148
return response

0 commit comments

Comments
 (0)