Skip to content

Commit

Permalink
Update readme for 0.5.0 (#284)
Browse files Browse the repository at this point in the history
* set temperature to 0.0 in examples

* fix link

* include python example in readme

* keep temperature in config file
  • Loading branch information
svlandeg authored Sep 7, 2023
1 parent 7c608e7 commit 406a4c3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,31 @@ models like Falcon, Dolly or LLaMA), ensure to that your API keys are set as env

Create a new API key from openai.com or fetch an existing one, and ensure the
keys are set as environmental variables. For more background information, see
the [OpenAI](/api/large-language-models#gpt-3-5) section.
the documentation around setting [API keys](https://spacy.io/api/large-language-models#api-keys).

Create a config file `config.cfg` containing at least the following (or see the
### In Python code

To do some quick experiments, from 0.5.0 onwards you can run:

```python
import spacy

nlp = spacy.blank("en")
llm = nlp.add_pipe("llm_textcat")
llm.add_label("INSULT")
llm.add_label("COMPLIMENT")
doc = nlp("You look gorgeous!")
print(doc.cats)
# {"COMPLIMENT": 1.0, "INSULT": 0.0}
```

By using the `llm_textcat` factory, the latest version of the built-in textcat task is used,
as well as the default GPT-3-5 model from OpenAI.

### Using a config file

To get more control over the various parameters of the `llm` pipeline,
create a config file `config.cfg` containing at least the following (or see the
full example
[here](https://github.com/explosion/spacy-llm/tree/main/usage_examples/textcat_openai)):

Expand All @@ -82,7 +104,7 @@ pipeline = ["llm"]
factory = "llm"

[components.llm.task]
@llm_tasks = "spacy.TextCat.v2"
@llm_tasks = "spacy.TextCat.v3"
labels = ["COMPLIMENT", "INSULT"]

[components.llm.model]
Expand Down
2 changes: 2 additions & 0 deletions usage_examples/multitask_openai/fewshot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ path = ${paths.examples}
[components.llm_ner.model]
@llm_models = "spacy.Text-Davinci.v2"
name = "text-davinci-003"
config = {"temperature": 0.0}

[components.llm_textcat]
factory = "llm"
Expand All @@ -37,3 +38,4 @@ path = ${paths.examples}
[components.llm_textcat.model]
@llm_models = "spacy.Text-Davinci.v2"
name = "text-davinci-003"
config = {"temperature": 0.0}
3 changes: 2 additions & 1 deletion usage_examples/multitask_openai/zeroshot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ labels = SIZE,TYPE,TOPPING,PRODUCT
[components.llm_ner.model]
@llm_models = "spacy.Text-Davinci.v2"
name = "text-davinci-003"
config = {"temperature": 0.0}

[components.llm_textcat]
factory = "llm"

[components.llm_textcat.task]
@llm_tasks = "spacy.TextCat.v2"
@llm_tasks = "spacy.TextCat.v3"
labels = INFORMATION,ORDER
exclusive_classes=True

Expand Down
4 changes: 2 additions & 2 deletions usage_examples/streamlit/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
[components.llm.backend]
@llm_models = "spacy.REST.v1"
api = "OpenAI"
config = {"model": "gpt-3.5-turbo", "temperature": 0.3}
config = {"model": "gpt-3.5-turbo", "temperature": 0.0}
[components.llm.task]
@llm_tasks = "spacy.NER.v2"
Expand All @@ -47,7 +47,7 @@
[components.llm.backend]
@llm_models = "spacy.REST.v1"
api = "OpenAI"
config = {"model": "gpt-3.5-turbo", "temperature": 0.3}
config = {"model": "gpt-3.5-turbo", "temperature": 0.0}
[components.llm.task]
@llm_tasks = "spacy.TextCat.v2"
Expand Down
1 change: 1 addition & 0 deletions usage_examples/textcat_openai/fewshot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ factory = "llm"

[components.llm.model]
@llm_models = "spacy.GPT-3-5.v2"
config = {"temperature": 0.0}

[components.llm.task]
@llm_tasks = "spacy.TextCat.v2"
Expand Down
1 change: 1 addition & 0 deletions usage_examples/textcat_openai/zeroshot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ factory = "llm"

[components.llm.model]
@llm_models = "spacy.GPT-3-5.v2"
config = {"temperature": 0.0}

[components.llm.task]
@llm_tasks = "spacy.TextCat.v2"
Expand Down

0 comments on commit 406a4c3

Please sign in to comment.