当前位置:网站首页>Machine learning service helps in application text language online and offline detection
Machine learning service helps in application text language online and offline detection
2022-06-13 12:15:00 【nginx】
When users need cross language communication or content translation , The application needs to be able to automatically detect the language of the text before translation .
HMS Core The language detection service of machine learning service provides online language detection and offline language detection , It supports the detection of monolingual text , It also supports detecting mixed language text , Covers Afrikaans 、 Arabic and other hundreds of languages . Access language detection service ,App Translation language detection can be easily realized 、 Web page language detection , Language detection in mixed language scenarios , help App Enhance user experience .
Language detection process
Input text , Machine learning service language automatically detects the language of the text , Then return the corresponding language code and the corresponding confidence , Or return an application encoded in the language with the highest confidence to the developer . Finally under development app The page presents the translated text .

Effect demonstration

1. The development of preparation
Before development, you need to configure HMS Core SDK Of Maven Warehouse address
2.1 Set the authentication information of the application
Asynchronous method sample code
Learn more >>
Visit the official website of Huawei developer alliance
Get development guidance document
Huawei mobile service open source warehouse address :GitHub、Gitee
Pay attention to our , The first time to understand HMS Core Latest technical information ~
HMS Core The language detection service of machine learning service provides online language detection and offline language detection , It supports the detection of monolingual text , It also supports detecting mixed language text , Covers Afrikaans 、 Arabic and other hundreds of languages . Access language detection service ,App Translation language detection can be easily realized 、 Web page language detection , Language detection in mixed language scenarios , help App Enhance user experience .
Language detection process
Input text , Machine learning service language automatically detects the language of the text , Then return the corresponding language code and the corresponding confidence , Or return an application encoded in the language with the highest confidence to the developer . Finally under development app The page presents the translated text .

Effect demonstration

1. The development of preparation
Before development, you need to configure HMS Core SDK Of Maven Warehouse address
Integrated online language detection service SDK, The sample code is as follows
repositories {maven {url'https://cmc.centralrepo.rnd.huawei.com/artifactory/product_maven/' }}
2. Edit project integration
dependencies{implementation 'com.huawei.hms:ml-computer-language-detection:3.4.0.301'}
2.1 Set the authentication information of the application
2.2 Create a language detector
Can pass api_key perhaps Access Token To set the application authentication information .adopt setAccessToken Method setting Access Token, You can initialize the settings once when the application starts , There is no need to set it more than once .MLApplication.getInstance().setAccessToken("your access token");adopt setApiKey Method setting api_key, You can initialize the settings once when the application starts , There is no need to set it more than once .MLApplication.getInstance().setApiKey("your ApiKey");
2.3 Conduct language detection
// Mode one : Create a language detector using the default parameter configuration .MLRemoteLangDetector mlRemoteLangDetector = MLLangDetectorFactory.getInstance().getRemoteLangDetector();// Mode two : Create a language detector using a custom parameter configuration .MLRemoteLangDetectorSetting setting = new MLRemoteLangDetectorSetting.Factory()// Set the minimum confidence threshold for language detection ..setTrustedThreshold(0.01f).create();MLRemoteLangDetector mlRemoteLangDetector = MLLangDetectorFactory.getInstance().getRemoteLangDetector(setting);
Asynchronous method sample code
Synchronization method sample code
// Mode one : Returns the detection results of multiple languages , Including language coding and confidence ,sourceText Represents the text to be detected , Length should be less than 5000 Characters .Task<List<MLDetectedLang>> probabilityDetectTask = mlRemoteLangDetector.probabilityDetect(sourceText);probabilityDetectTask.addOnSuccessListener(new OnSuccessListener<List<MLDetectedLang>>() {@Overridepublic void onSuccess(List<MLDetectedLang> result) {// Successful processing logic .}}).addOnFailureListener(new OnFailureListener() {@Overridepublic void onFailure(Exception e) {// Failed processing logic .// Recognition failure.try {MLException mlException = (MLException)e;// Get error code , Developers can handle error codes , According to the error code for differentiated page prompt .int errorCode = mlException.getErrCode();// Get error information , Developers can combine error codes , Fast location problem .String errorMessage = mlException.getMessage();} catch (Exception error) {// Conversion error handling .}}});// Mode two : Returns the language code with the highest confidence ,sourceText Represents the text to be detected , Length should be less than 5000 Characters .Task<String> firstBestDetectTask = mlRemoteLangDetector.firstBestDetect(sourceText);firstBestDetectTask.addOnSuccessListener(new OnSuccessListener<String>() {@Overridepublic void onSuccess(String s) {// Successful processing logic .}}).addOnFailureListener(new OnFailureListener() {@Overridepublic void onFailure(Exception e) {// Failed processing logic .// Recognition failure.try {MLException mlException = (MLException)e;// Get error code , Developers can handle error codes , According to the error code for differentiated page prompt .int errorCode = mlException.getErrCode();// Get error information , Developers can combine error codes , Fast location problem .String errorMessage = mlException.getMessage();} catch (Exception error) {// Conversion error handling .}}});
2.4 After the test , Release resources .
// Mode one : Returns the detection results of multiple languages , Including language coding and confidence ,sourceText Represents the text to be detected , Length should be less than 5000 Characters .try {List<MLDetectedLang> result= mlRemoteLangDetector.syncProbabilityDetect(sourceText);} catch (MLException mlException) {// Failed processing logic .// Get error code , Developers can handle error codes , According to the error code for differentiated page prompt .int errorCode = mlException.getErrCode();// Get error information , Developers can combine error codes , Fast location problem .String errorMessage = mlException.getMessage();}// Mode two : Returns the language code with the highest confidence ,sourceText Represents the text to be detected , Length should be less than 5000 Characters .try {String language = mlRemoteLangDetector.syncFirstBestDetect(sourceText);} catch (MLException mlException) {// Failed processing logic .// Get error code , Developers can handle error codes , According to the error code for differentiated page prompt .int errorCode = mlException.getErrCode();// Get error information , Developers can combine error codes , Fast location problem .String errorMessage = mlException.getMessage();}
The language detection function includes the end side and cloud side , The above examples are only cloud side functions .
if (mlRemoteLangDetector != null) {mlRemoteLangDetector.stop();}
Learn more >>
Visit the official website of Huawei developer alliance
Get development guidance document
Huawei mobile service open source warehouse address :GitHub、Gitee
Pay attention to our , The first time to understand HMS Core Latest technical information ~
边栏推荐
- The most complete network, including interview questions + Answers
- SMS sending + serial port printing based on stm32f103-sim900a
- 云安全服务的选择
- 一文说清楚ToB SaaS系统的权限管理的设计
- Pointnet: deep learning on point sets for 3D classification and segmentation
- 如何以最小成本将传统应用快速SaaS化
- OpenCV学习笔记(二):读取mnist数据集
- Committed to R & D and manufacturing of ultra surface photonic chip products, Shanhe optoelectronics completed a round of pre-A financing of tens of millions of yuan
- flutter 插件 Pluto表格使用所遇问题
- Pulsar consumer
猜你喜欢
随机推荐
[benefits] in minutes
8. Deepfm introduction
web开发项目,web单页开发
【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(二)
机器学习(一)—线性回归理论与代码详解
Pulsar consumer
构建一个安全的云平台
业务上云的方法论
基于三维GIS技术的行业发展及研究现状
[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching
Lightweight real-time semantic segmentation: eNet & erfnet
7.5.4:Spire Office for . NET New Version
书籍+视频+学习笔记+技能提升资源库,面试必问
智能客服系统框架rasa
5 LockSupport与线程中断
10、DCN 介绍
机器学习服务助应用内文本语种在线和离线检测
Details of fitfi sports money making chain game system development mode
Selenium3 automatic test practice (5)
浅谈常见的web攻击以及如何防范

![[benefits] in minutes](/img/e0/217fe575c1a31b04a9b0699ec44f25.png)







