> For the complete documentation index, see [llms.txt](https://doc.verteego.com/verteego-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.verteego.com/verteego-doc/pipelines/forecasting-pipelines/calculators/machine-learning/words_similarity.md).

# words\_similarity

Computes a similarity score of the words in the input column with the context words.

## Usage

{% hint style="info" %}
Calculate the **similarity** between each of the **given words**, and the **words in the input column**, using the sentence transformer library. Several languages are supported
{% endhint %}

This calculator can be used with the following method:

<mark style="color:red;">**`words_similarity`**</mark>

Examples:

* Establish connections between various products. For instance, consider *<mark style="color:purple;">chicken soup</mark>* and *<mark style="color:purple;">chicken salad</mark>*. Both contain chicken.
* Generate an artificial referential data in cases where the client's reference system is inadequate/incomplete.

***

## Main Parameters

{% hint style="success" %}
**The bold options** represent the default values when the parameters are optional.
{% endhint %}

* *<mark style="color:blue;">input\_columns</mark>* \
  Column to use to extract values which will be used to compute similarity of rows with context words.
* *<mark style="color:blue;">output\_columns</mark>* \
  Context words to use, each word will become a new column containing the computed similarity for the given row’s input column value.
* *<mark style="color:blue;">global</mark>* *(true, **false)*** \
  Should this calculator be performed before data splitting during training for cross-validation
* *<mark style="color:blue;">steps</mark>* \[optionnal] *(**training, prediction**, postprocessing*)\
  List of steps in a pipeline where columns from this calculator are added to the data. Note that when the training option is listed, the calculator is actually added during preprocessing.
* *<mark style="color:blue;">store\_in\_model</mark>* \[optionnal] *(true, **false)*** \
  Please indicate whether the "calculated" columns by the calculator should be stored in the model or not to avoid recalculating them during prediction. This is only relevant if the calculated columns are added to both training and prediction. Without this parameter, the values will not be stored in the model. The following parameters only make sense if this parameter is set to *true*.
* *<mark style="color:blue;">stored\_columns</mark>* \[required if *<mark style="color:blue;">store\_in\_model</mark> is true*] \
  List indicating the columns to be stored among the *<mark style="color:blue;">output\_columns</mark>*.
* *<mark style="color:blue;">stored\_keys</mark>* \[required if *<mark style="color:blue;">store\_in\_model</mark> is true*] \
  List indicating the columns to use for identifying the correct values to join on the data for prediction among the stored values (logically, they are to be chosen from the *<mark style="color:blue;">input\_columns</mark>*).

***

## Specific Parameters

* *<mark style="color:blue;">None</mark>*

***

## Examples

1. Extract the product label and compute the similarity of the product labels with the following context words: *<mark style="color:purple;">sushi, thon, saumon, poulet, crevette, california, rice</mark>*

```yaml
calculated_cols:
  words_similarity_features:
    method: words_similarity
    input_columns:
    - item_label
    output_columns:
    - sushi
    - thon
    - saumon
    - poulet
    - crevette
    - california
    - rice
```

<table><thead><tr><th width="393">item_label</th><th>sushi</th><th>thon</th><th>saumon</th><th>poulet</th><th>crevette</th><th>california</th><th>rice</th></tr></thead><tbody><tr><td>CALIFORNIA SAUMON &#x26; MAKI MIXTE OLD</td><td>0.3629</td><td>0.4061</td><td><mark style="background-color:blue;">0.5522</mark></td><td>0.4031</td><td>0.3929</td><td><mark style="background-color:blue;">0.6712</mark></td><td>0.2669</td></tr><tr><td>SPICY CALIFORNIA SAUMON 9</td><td>0.3282</td><td>0.3701</td><td><mark style="background-color:blue;">0.5271</mark></td><td>0.3991</td><td>0.4742</td><td><mark style="background-color:blue;">0.7747</mark></td><td>0.2398</td></tr><tr><td>SUSHI &#x26; CALIFORNIA MIXTE 9 PIECES</td><td>0.7504</td><td>0.1815</td><td>0.3481</td><td>0.2771</td><td>0.3925</td><td>0.4621</td><td>0.291</td></tr><tr><td>RICE SANDWICH 8 PIECES</td><td>0.4985</td><td>0.1364</td><td>0.2212</td><td>0.3222</td><td>0.3785</td><td>0.2191</td><td><mark style="background-color:blue;">0.6828</mark></td></tr><tr><td>CALIFORNIA SAUMON 8 PIECES</td><td>0.4618</td><td>0.3349</td><td><mark style="background-color:blue;">0.5578</mark></td><td>0.4458</td><td>0.5171</td><td><mark style="background-color:blue;">0.6868</mark></td><td>0.2998</td></tr></tbody></table>
