Lang-detect
At a glance
The lang-detect
model identifies the language of the input text.
Class definition |
---|
watson_nlp.blocks.lang_detect.izumo.Izumo |
For language support, see Supported languages.
Pretrained models
Model names are listed below.
Model ID | Container Image |
---|---|
lang-detect_izumo_lang_multi_stock | cp.icr.io/cp/ai/watson-nlp_lang-detect_izumo_lang_multi_stock:1.4.1 |
The language detection model has been trained with data from Wikipedia in various languages. The implementation analyzes the first 2000 characters of the input text and outputs the most probable language.
Running models
The Lang-detect model request accepts the following fields:
Field | Type | Required Optional Repeated |
Description |
---|---|---|---|
raw_document |
watson_core_data_model.nlp.RawDocument |
required | The input document on which to perform language detection |
The Lang-detect model returns LANG_
plus a three-character ISO 639-3 code. For example, German is returned as LANG_DEU
.
Example requests
REST API
curl -s \
"http://localhost:8080/v1/watson.runtime.nlp.v1/NlpService/LangDetectPredict" \
-H "accept: application/json" \
-H "content-type: application/json" \
-H "Grpc-Metadata-mm-model-id: lang-detect_izumo_lang_multi_stock" \
-d '{ "raw_document": { "text": "Hola, me llamo Javier. Me gusta dormir mucho pero no me gusta trabajar." } }'
Response
{"langCode":"LANG_SPA", "producerId":{"name":"Izumo Lang Detect", "version":"0.0.1"}}
Python
import grpc
from watson_nlp_runtime_client import (
common_service_pb2,
common_service_pb2_grpc,
syntax_types_pb2,
)
channel = grpc.insecure_channel("localhost:8085")
stub = common_service_pb2_grpc.NlpServiceStub(channel)
request = common_service_pb2.LangDetectRequest(
raw_document=syntax_types_pb2.RawDocument(text="Hola, me llamo Javier. Me gusta dormir mucho pero no me gusta trabajar."),
)
response = stub.LangDetectPredict(
request, metadata=[("mm-model-id", "lang-detect_izumo_lang_multi_stock")]
)
print(response)
Response
lang_code: LANG_SPA
producer_id {
name: "Izumo Lang Detect"
version: "0.0.1"
}