> For the complete documentation index, see [llms.txt](https://utca.knowledgator.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utca.knowledgator.com/tasks/tokensearcherrelationextraction.md).

# TokenSearcherRelationExtraction

Relation extraction task

This task uses[ **TokenSearcherPredictor**](/predictors/tokensearcherpredictor.md)[ ](/predictors/comprehenditpredictor.md)by default. For more details, see:

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

Subclass of [**Task**](/tasks/task.md)**.**&#x20;

## Module: [implementation](/framework-structure.md#implementation).tasks

## Methods and properties

Main methods and properties

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**predictor**</mark>**&#x20;(**[**Predictor**](/predictors/predictor.md)**\[Any, Any], optional):** Predictor that will be used in task. If equals to None, default [**TokenSearcherPredictor**](/predictors/tokensearcherpredictor.md) will be used. Defaults to None.
* <mark style="color:orange;">**preprocess**</mark>**&#x20;(Optional\[**[**Component**](/core/component.md)**], optional):** Component executed before predictor.&#x20;

  If equals to None, default component will be used. Defaults to None.\
  \
  Default component: \
  [**TokenSearcherRelationExtractionPreprocessor**](#tokensearcherrelationextractionpreprocessor)
* <mark style="color:orange;">**postprocess**</mark>**&#x20;(Optional\[**[**Component**](/core/component.md)**], optional):** Component executed after predictor.&#x20;

  If equals to None, default component will be used. Defaults to None.\
  \
  Default component: \
  [**TokenSearcherRelationExtractionPostprocessor**](#tokensearcherrelationextractionpostprocessor)
* <mark style="color:orange;">**input\_class**</mark>**&#x20;(Type\[**[**Input**](/core/schemas.md#input)**], optional):** Class for input validation. Defaults to [**RelationExtractionInput**](/tasks/relation-extraction-tasks-utilities.md#relationextractioninput)**.**
* <mark style="color:orange;">**output\_class**</mark>**&#x20;(Type\[**[**Output**](/core/schemas.md#output)**], optional):** Class for output validation. Defaults to [**RelationExtractionOutput**](/tasks/relation-extraction-tasks-utilities.md#relationextractionoutput)**.**
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

***

***

## <mark style="color:green;">TokenSearcherRelationExtractionPreprocessor</mark>

Create prompt with providied text. Subclass of [**Action**](/core/action.md). Type of \
[**Action**](/core/action.md)**\[Dict\[str, Any], Dict\[str, Any]].**

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):** \
  Expected keys:
  * <mark style="color:red;">**"text"**</mark>**&#x20;(str):** Text to process;
  * <mark style="color:red;">**"relations"**</mark>**&#x20;(List\[**[**Relation**](/tasks/relation-extraction-tasks-utilities.md#relation)**]):** Relations parameters;
  * <mark style="color:red;">**"entities"**</mark>**&#x20;(List\[**[**ClassifiedEntity**](/tasks/objects.md#classifiedentity)**]):** Entities to use;

#### Returns:

* **Dict\[str, Any]:** \
  Expected keys:
  * <mark style="color:red;">**"source\_entities"**</mark>**&#x20;(List\[**[**ClassifiedEntity**](/tasks/objects.md#classifiedentity)**]):** Source entities to use;
  * <mark style="color:red;">**"relations\_labels"**</mark>**&#x20;(List\[str]):** Corresponding relations labels;
  * <mark style="color:red;">**"inputs"**</mark>**&#x20;(List\[str]):** Model inputs;
  * <mark style="color:red;">**"prompt\_lengths"**</mark>**&#x20;(List\[int]):** Prompt lenghts. Used by postprocessor;

***

***

***

## <mark style="color:green;">TokenSearcherRelationExtractionPostprocessor</mark>

Format output. Subclass of [**Action**](/core/action.md). Type of [**Action**](/core/action.md)**\[Dict\[str, Any], Dict\[str, Any]].**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**threshold**</mark>**&#x20;(float):** Relations threshold score. Defaults to 0.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):** \
  Expected keys:
  * <mark style="color:red;">**"text"**</mark>**&#x20;(str):** Processed text;
  * <mark style="color:red;">**"output"**</mark>**&#x20;(List\[List\[Dict\[str, Any]]]):** Model output;&#x20;
  * <mark style="color:red;">**"relations"**</mark>**&#x20;(List\[**[**Relation**](/tasks/relation-extraction-tasks-utilities.md#relation)**]):** Relations parameters;
  * <mark style="color:red;">**"source\_entities"**</mark>**&#x20;(List\[**[**ClassifiedEntity**](/tasks/objects.md#classifiedentity)**]):** Used source entities;
  * <mark style="color:red;">**"relations\_labels"**</mark>**&#x20;(List\[str]):** Corresponding relations labels;
  * <mark style="color:red;">**"entities"**</mark>**&#x20;(List\[**[**ClassifiedEntity**](/tasks/objects.md#classifiedentity)**]):** Entities to use;
  * <mark style="color:red;">**"prompt\_lengths"**</mark>**&#x20;(List\[int]):** Prompt lenghts;

#### Returns:

* **Dict\[str, Any]:** \
  Expected keys:
  * <mark style="color:red;">**"output"**</mark>**&#x20;(List\[**[**Triplets**](/tasks/relation-extraction-tasks-utilities.md#triplet)**]):** Extracted relations;

***

***
