In my previous article " elasticsearch: Ingest Language Processor ." In that article, we use a plug-in community to complete this work. In Elastic Stack release 7.6, we are pleased to tell you: in Elastic Stack, we integrated a speech recognition processor.
Hands
First of all, we need to install the latest release of Elastic Stack 7.6. We enter the following command in Kibana in:
PUT _ingest/pipeline/my-pipeline-id
{
"description": "describe pipeline",
"processors": [
{
"inference": {
"model_id": "lang_ident_model_1",
"inference_config": {
"classification": {
"num_top_classes": 1
}
},
"field_mappings": {}
}
}
]
}
In the above we create a pipeline called my-pipeline-id's. So when we put the document into Elasticsearch, we can refer to this pipeline:
POST test/_doc/1?pipeline=my-pipeline-id
{
"text": "我爱北京天安门"
}
In the above we have " I Love Beijing Tiananmen " is written to Elasticsearch in. We can check the information written by the following command:
GET test/_doc/1/
We can see a response as follows:
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"text" : "我爱北京天安门",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "zh",
"class_probability" : 0.9999770918986735,
"class_score" : 0.9999770918986735
}
],
"predicted_value" : "zh",
"model_id" : "lang_ident_model_1"
}
}
}
}
In the above, we can see a field called ml.inference.predicated_value, it shows the language zh, is Chinese.
Similarly, we can do an experiment to other languages, such as Japanese:
POST test/_doc/2?pipeline=my-pipeline-id
{
"text": "これはフリーテキストです。"
}
So let's check the document input by the following command:
GET test/_doc/2/
Returned results above are:
{
"_index" : "test",
"_type" : "_doc",
"_id" : "2",
"_version" : 2,
"_seq_no" : 3,
"_primary_term" : 1,
"found" : true,
"_source" : {
"text" : "これはフリーテキストです。",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "ja",
"class_probability" : 0.999997979528696,
"class_score" : 0.999997979528696
}
],
"predicted_value" : "ja",
"model_id" : "lang_ident_model_1"
}
}
}
}
Shown in the above ml.inference.predicted_value is "ja", which is Japanese.
If we want to use _simulate pipeline to test, then we can use the following command:
POST _ingest/pipeline/_simulate
{
"pipeline": {
"processors": [
{
"inference": {
"model_id": "lang_ident_model_1",
"inference_config": {
"classification": {
"num_top_classes": 1
}
},
"field_mappings": {
}
}
}
]
},
"docs": [
{"_source": {"text": "this is some free text."}},
{"_source": {"text": "c'est du texte libre."}},
{"_source": {"text": "Dies ist ein Freitext."}},
{"_source": {"text": "これはフリーテキストです。"}},
{"_source": {"text": "یہ کچھ مفت متن ہے۔"}},
{"_source": {"text": "我爱北京天安门"}}
]
}
The results show that:
{
"docs" : [
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"text" : "this is some free text.",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "en",
"class_probability" : 0.9999832919481261,
"class_score" : 0.9999832919481261
}
],
"predicted_value" : "en",
"model_id" : "lang_ident_model_1"
}
}
},
"_ingest" : {
"timestamp" : "2020-03-04T05:51:26.380985Z"
}
}
},
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"text" : "c'est du texte libre.",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "fr",
"class_probability" : 0.996991483545992,
"class_score" : 0.996991483545992
}
],
"predicted_value" : "fr",
"model_id" : "lang_ident_model_1"
}
}
},
"_ingest" : {
"timestamp" : "2020-03-04T05:51:26.380988Z"
}
}
},
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"text" : "Dies ist ein Freitext.",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "de",
"class_probability" : 0.9999995801281829,
"class_score" : 0.9999995801281829
}
],
"predicted_value" : "de",
"model_id" : "lang_ident_model_1"
}
}
},
"_ingest" : {
"timestamp" : "2020-03-04T05:51:26.38099Z"
}
}
},
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"text" : "これはフリーテキストです。",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "ja",
"class_probability" : 0.999997979528696,
"class_score" : 0.999997979528696
}
],
"predicted_value" : "ja",
"model_id" : "lang_ident_model_1"
}
}
},
"_ingest" : {
"timestamp" : "2020-03-04T05:51:26.380992Z"
}
}
},
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"text" : "یہ کچھ مفت متن ہے۔",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "ur",
"class_probability" : 0.9999762917090316,
"class_score" : 0.9999762917090316
}
],
"predicted_value" : "ur",
"model_id" : "lang_ident_model_1"
}
}
},
"_ingest" : {
"timestamp" : "2020-03-04T05:51:26.380994Z"
}
}
},
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"text" : "我爱北京天安门",
"ml" : {
"inference" : {
"top_classes" : [
{
"class_name" : "zh",
"class_probability" : 0.9999770918986735,
"class_score" : 0.9999770918986735
}
],
"predicted_value" : "zh",
"model_id" : "lang_ident_model_1"
}
}
},
"_ingest" : {
"timestamp" : "2020-03-04T05:51:26.380995Z"
}
}
}
]
}