# Quickstart

For this example will be used simple [**ExecutionSchema**](/structural-components/executionschema.md) with [**TokenSearcherNER**](/tasks/tokensearcherner.md) task. This program will extract entities with provided labels and threshold.

To create program follow this steps:

## 1. Install package

```
pip install -U utca
```

## 2. Import modules that will be used

```python
from utca.core import (
    AddData,
    RenameAttribute,
    Flush
)
from utca.implementation.predictors import (
    TokenSearcherPredictor, TokenSearcherPredictorConfig
)
from utca.implementation.tasks import (
    TokenSearcherNER,
    TokenSearcherNERPostprocessor,
)
```

## 3. Initialize components with desired configurations

### Predictor that will be used by NER task

```python
predictor = TokenSearcherPredictor(
    TokenSearcherPredictorConfig(
        device="cpu"
    )
)
```

### NER task

```python
ner_task = TokenSearcherNER(
    predictor=predictor,
    postprocess=TokenSearcherNERPostprocessor(
        threshold=0.5
    )
)
```

Here, we set up a task using the created predictor and define a postprocess chain with a predefined threshold.

Alternatively, we can create an NER task without describing the configuration or predictor by simply:

```
ner_task = TokenSearcherNER()
```

It will create a default task, which differs from the one described above only by the threshold value, which defaults to 0.

To learn more about default parameters, refer to:

{% content-ref url="/pages/vYIqUg2Hnk0cSSeIKuyA" %}
[TokenSearcherNER](/tasks/tokensearcherner.md)
{% endcontent-ref %}

## 4. Create ExecutionSchema

```python
pipeline = (        
    AddData({"labels": ["scientist", "university", "city"]})         
    | ner_task
    | Flush(keys=["labels"])
    | RenameAttribute("output", "entities")
)
```

Here we described pipeline that will:

1. Add **labels** to input data with values \["scientist", "university", "city"]
2. Execute NER task
3. Remove **labels** from results
4. Rename **output** to **entities**

## 5. Run created pipeline

{% code overflow="wrap" %}

```python
res = pipeline.run({
    "text": """Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, has recently published a paper in the prestigious journal "Nature Neuroscience". 
His research focuses on a rare genetic mutation, found in less than 0.01% of the population, that appears to prevent the development of Alzheimer's disease. Collaborating with researchers at the University of California, San Francisco, the team is now working to understand the mechanism by which this mutation confers its protective effect. 
Funded by the National Institutes of Health, their research could potentially open new avenues for Alzheimer's treatment."""
})
```

{% endcode %}

Here, we run pupline with input **text**.

{% hint style="info" %}
Note that **text** and **labels** keys are expected by TokenSearcherNER task described above. Refer to class description in [**Used components**](#used-components) section.
{% endhint %}

Result should look similar to:

{% code overflow="wrap" %}

```python
{
    "text": """Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, has recently published a paper in the prestigious journal "Nature Neuroscience". 
His research focuses on a rare genetic mutation, found in less than 0.01% of the population, that appears to prevent the development of Alzheimer's disease. Collaborating with researchers at the University of California, San Francisco, the team is now working to understand the mechanism by which this mutation confers its protective effect. 
Funded by the National Institutes of Health, their research could potentially open new avenues for Alzheimer's treatment.""", 
    "entities": [
        {
            "start": 4, 
            "end": 16, 
            "span": "Paul Hammond",
            "score": 0.5637074708938599, 
            "entity": "scientist"
        }, 
        {
            "start": 44, 
            "end": 68, 
            "span": "Johns Hopkins University", 
            "score": 0.8921091556549072, 
            "entity": "university"
        }, 
        {
            "start": 347, 
            "end": 371,
            "span": "University of California",
            "score": 0.7202138900756836, 
            "entity": "university"
        }, 
        {
            "start": 373, 
            "end": 386,
            "span": "San Francisco",
            "score": 0.7660449743270874, 
            "entity": "city"
        }
    ]
}
```

{% endcode %}

## Used components

{% content-ref url="/pages/oPEgoLxOvjGqw0yLD7eF" %}
[TokenSearcherPredictor](/predictors/tokensearcherpredictor.md)
{% endcontent-ref %}

{% content-ref url="/pages/vYIqUg2Hnk0cSSeIKuyA" %}
[TokenSearcherNER](/tasks/tokensearcherner.md)
{% endcontent-ref %}

{% content-ref url="/pages/8ozkNtdwB3wV9mNqPc9U" %}
[AddData](/base-actions/adddata.md)
{% endcontent-ref %}

{% content-ref url="/pages/FYd3Nv0nWxIn9NzOR6fT" %}
[Flush](/base-actions/flush.md)
{% endcontent-ref %}

{% content-ref url="/pages/9zqcDAhfye1DBLTz1dIo" %}
[RenameAttribute](/base-actions/renameattribute.md)
{% endcontent-ref %}

{% content-ref url="/pages/h4KTk0ZoGoSN53CyzrDK" %}
[ExecutionSchema](/structural-components/executionschema.md)
{% endcontent-ref %}

## What next

Explore more about components and concepts on the following pages, or jump to class descriptions and more advanced examples.

{% content-ref url="/pages/itM8zzuD3IEPsydOhnGP" %}
[Concepts](/concepts.md)
{% endcontent-ref %}

{% content-ref url="/pages/rMYihwaWoC6CylShtkTw" %}
[Examples](/examples.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://utca.knowledgator.com/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
