simplify Python example

This commit is contained in:
svlandeg 2023-09-07 14:53:18 +02:00
parent 6161591889
commit ecc017bbbc

View File

@ -169,25 +169,17 @@ to be `"databricks/dolly-v2-12b"` for better performance.
### Example 3: Create the component directly in Python {id="example-3"} ### Example 3: Create the component directly in Python {id="example-3"}
The `llm` component behaves as any other component does, so adding it to an The `llm` component behaves as any other component does, and there are
existing pipeline follows the same pattern: [task-specific components](/api/large-language-models#implementation) defined to
help you hit the ground running with a reasonable built-in task implementation.
```python ```python
import spacy import spacy
nlp = spacy.blank("en") nlp = spacy.blank("en")
nlp.add_pipe( llm_ner = nlp.add_pipe("llm_ner")
"llm", llm_ner.add_label("PERSON")
config={ llm_ner.add_label("LOCATION")
"task": {
"@llm_tasks": "spacy.NER.v2",
"labels": ["PERSON", "ORGANISATION", "LOCATION"]
},
"model": {
"@llm_models": "spacy.GPT-3-5.v1",
},
},
)
nlp.initialize() nlp.initialize()
doc = nlp("Jack and Jill rode up the hill in Les Deux Alpes") doc = nlp("Jack and Jill rode up the hill in Les Deux Alpes")
print([(ent.text, ent.label_) for ent in doc.ents]) print([(ent.text, ent.label_) for ent in doc.ents])
@ -314,7 +306,7 @@ COMPLIMENT
## API {id="api"} ## API {id="api"}
`spacy-llm` exposes a `llm` factory with `spacy-llm` exposes an `llm` factory with
[configurable settings](/api/large-language-models#config). [configurable settings](/api/large-language-models#config).
An `llm` component is defined by two main settings: An `llm` component is defined by two main settings: