---
type: api
title: Create a trained model vocabulary
description: This API is supported only for natural language processing (NLP) models.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-ml-put-trained-model-vocabulary
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-ml-put-trained-model-vocabulary
products:
  - Elasticsearch
---

# Create a trained model vocabulary

Availability: 8.0+

## Paths

- `PUT` `/_ml/trained_models/{model_id}/vocabulary`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#bearerauth)

#### Path Parameters

- `model_id` (string Id)
  The unique identifier of the trained model.

## Description

This API is supported only for natural language processing (NLP) models.
The vocabulary is stored in the index as described in `inference_config.*.vocabulary` of the trained model definition.

## Required authorization

* Cluster privileges: `manage_ml`

## Request Body

`application/json`

- `vocabulary` ([] string) — required
  The model vocabulary, which must not be empty.
- `merges` ([] string) — optional
  The optional model merges if required by the tokenizer.
- `scores` ([] number) — optional
  The optional vocabulary value scores if required by the tokenizer.

## Response

`application/json`

- `acknowledged` (boolean)
  For a successful response, this value is always true. On failure, an exception is returned instead.
## Code Examples

#### Console

```console
PUT _ml/trained_models/elastic__distilbert-base-uncased-finetuned-conll03-english/vocabulary
{
  "vocabulary": [
    "[PAD]",
    "[unused0]",
  ]
}
```

#### JavaScript

```javascript
const response = await client.ml.putTrainedModelVocabulary({
  model_id: "elastic__distilbert-base-uncased-finetuned-conll03-english",
  vocabulary: ["[PAD]", "[unused0]"],
});
```

#### Python

```python
resp = client.ml.put_trained_model_vocabulary(
    model_id="elastic__distilbert-base-uncased-finetuned-conll03-english",
    vocabulary=[
        "[PAD]",
        "[unused0]"
    ],
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_ml/trained_models/elastic__distilbert-base-uncased-finetuned-conll03-english/vocabulary" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "vocabulary": [
      "[PAD]",
      "[unused0]"
    ]
  }'
```

#### Java

```java
client.ml().putTrainedModelVocabulary(p -> p
    .modelId("elastic__distilbert-base-uncased-finetuned-conll03-english")
    .vocabulary(List.of("[PAD]","[unused0]"))
);
```

#### C#

```c#
var response = await client.MachineLearning
    .PutTrainedModelVocabularyAsync(modelId: "elastic__distilbert-base-uncased-finetuned-conll03-english", d1 => d1
        .Vocabulary("[PAD]", "[unused0]")
    );
```

#### PHP

```php
$resp = $client->ml()->putTrainedModelVocabulary([
    "model_id" => "elastic__distilbert-base-uncased-finetuned-conll03-english",
    "body" => [
        "vocabulary" => array(
            "[PAD]",
            "[unused0]",
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.ml.put_trained_model_vocabulary(
  model_id: "elastic__distilbert-base-uncased-finetuned-conll03-english",
  body: {
    "vocabulary": [
      "[PAD]",
      "[unused0]"
    ]
  }
)
```

