You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
IoT-For-Beginners/translations/my/6-consumer/lessons/2-language-understanding/README.md

469 lines
43 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!--
CO_OP_TRANSLATOR_METADATA:
{
"original_hash": "6f4ba69d77f16c4a5110623a96a215c3",
"translation_date": "2025-08-28T16:14:58+00:00",
"source_file": "6-consumer/lessons/2-language-understanding/README.md",
"language_code": "my"
}
-->
# ဘာသာစကားကိုနားလည်ခြင်း
![ဒီသင်ခန်းစာ၏အကျဉ်းချုပ်ကို Sketchnote](../../../../../translated_images/lesson-22.6148ea28500d9e00c396aaa2649935fb6641362c8f03d8e5e90a676977ab01dd.my.jpg)
> Sketchnote ကို [Nitya Narasimhan](https://github.com/nitya) မှရေးသားထားသည်။ ပုံကိုနှိပ်ပြီး ပိုကြီးမားသောဗားရှင်းကိုကြည့်ပါ။
## သင်ခန်းစာမတိုင်မီမေးခွန်း
[သင်ခန်းစာမတိုင်မီမေးခွန်း](https://black-meadow-040d15503.1.azurestaticapps.net/quiz/43)
## အကျဉ်းချုပ်
ပြီးခဲ့သင်ခန်းစာတွင် သင်သည် စကားပြောကို စာသားအဖြစ်ပြောင်းလဲခဲ့သည်။ ဒါကို စမတ်တိုင်မာကို အစီအစဉ်ရေးဆွဲရန်အသုံးပြုနိုင်ရန် သင်၏ကုဒ်သည် ပြောဆိုခဲ့သောအရာကို နားလည်နိုင်ရန်လိုအပ်ပါသည်။ သုံးစွဲသူသည် "၃ မိနစ်တိုင်မာကို သတ်မှတ်ပါ" ဆိုသော စကားစုကို ပြောမည်ဟု သင်ယူနိုင်သော်လည်း၊ ထိုစကားစုကို အနက်ဖွင့်ပြီး တိုင်မာကြာချိန်ကို ရယူနိုင်သည်။ သို့သော်၊ ဒါဟာ သုံးစွဲသူအတွက် အဆင်မပြေပါ။ သုံးစွဲသူက "၃ မိနစ်အတွက် တိုင်မာကို သတ်မှတ်ပါ" ဆိုပါက သင်နှင့် ကျွန်ုပ်တို့သည် သူတို့၏အနက်ကို နားလည်နိုင်သော်လည်း၊ သင်၏ကုဒ်သည် သတ်မှတ်ထားသော စကားစုကို မျှော်လင့်နေမည်ဖြစ်သည်။
ဒီနေရာမှာ ဘာသာစကားနားလည်မှု (Language Understanding) က အရေးပါလာပြီး၊ AI မော်ဒယ်များကို အသုံးပြု၍ စာသားကို အနက်ဖွင့်ပြီး လိုအပ်သောအသေးစိတ်ကို ပြန်ပေးနိုင်သည်။ ဥပမာအားဖြင့် "Set a 3 minute timer" နှင့် "Set a timer for 3 minutes" နှစ်ခုလုံးကို နားလည်ပြီး ၃ မိနစ်အတွက် တိုင်မာတစ်ခုလိုအပ်သည်ဟု သိနိုင်သည်။
ဒီသင်ခန်းစာတွင် သင်သည် ဘာသာစကားနားလည်မှုမော်ဒယ်များ၊ မော်ဒယ်များကို ဖန်တီးခြင်း၊ လေ့ကျင့်ခြင်းနှင့် သင်၏ကုဒ်မှ အသုံးပြုခြင်းကို လေ့လာမည်ဖြစ်သည်။
ဒီသင်ခန်းစာတွင် ကျွန်ုပ်တို့ဖော်ပြမည့်အကြောင်းအရာများမှာ -
* [ဘာသာစကားနားလည်မှု](../../../../../6-consumer/lessons/2-language-understanding)
* [ဘာသာစကားနားလည်မှုမော်ဒယ်တစ်ခုဖန်တီးခြင်း](../../../../../6-consumer/lessons/2-language-understanding)
* [ရည်ရွယ်ချက်များနှင့် အရာဝတ္ထုများ](../../../../../6-consumer/lessons/2-language-understanding)
* [ဘာသာစကားနားလည်မှုမော်ဒယ်ကို အသုံးပြုခြင်း](../../../../../6-consumer/lessons/2-language-understanding)
## ဘာသာစကားနားလည်မှု
လူသားများသည် နှစ်ပေါင်းရာနှင့်ချီသောအချိန်အတွင်း ဘာသာစကားကို အသုံးပြု၍ ဆက်သွယ်ခဲ့ကြသည်။ ကျွန်ုပ်တို့သည် စကားလုံးများ၊ အသံများ သို့မဟုတ် လှုပ်ရှားမှုများကို အသုံးပြု၍ ဆက်သွယ်ပြီး၊ ပြောဆိုခဲ့သောအရာကို နားလည်သည်။ စကားလုံးများ၊ အသံများ သို့မဟုတ် လှုပ်ရှားမှုများ၏ အနက်ကို နားလည်သလို၊ ၎င်းတို့၏ အခြေအနေကိုလည်း နားလည်သည်။ ကျွန်ုပ်တို့သည် အရိုးရှင်းမှုနှင့် ရီမောကို နားလည်နိုင်ပြီး၊ အသံထွက်ပုံစံအပေါ်မူတည်၍ တူညီသော စကားလုံးများကို အနက်အမျိုးမျိုးရှိစေသည်။
✅ မကြာသေးမီက သင်ပြောခဲ့သော စကားဝိုင်းများအချို့ကို စဉ်းစားပါ။ ကွန်ပျူတာအတွက် အခက်အခဲဖြစ်နိုင်သော စကားဝိုင်း၏ အပိုင်းများကို အခြေအနေလိုအပ်သောကြောင့် နားလည်ရန် ခက်ခဲမည်ဟု သင်ထင်ပါသလား။
ဘာသာစကားနားလည်မှု (Language Understanding) သို့မဟုတ် သဘာဝဘာသာစကားနားလည်မှု (Natural Language Understanding) သည် သဘာဝဘာသာစကားလုပ်ငန်းဆောင်တာ (Natural Language Processing - NLP) ဟုခေါ်သော အတုအမြှောက်အတတ်ပညာ (AI) ရှိ အခန်းကဏ္ဍတစ်ခုဖြစ်ပြီး၊ စာဖတ်နားလည်မှုနှင့် စကားလုံးများ သို့မဟုတ် စာကြောင်းများ၏ အသေးစိတ်ကို နားလည်ရန် ကြိုးစားသည်။ သင်သည် Alexa သို့မဟုတ် Siri ကဲ့သို့သော အသံအကူအညီပေးစနစ်ကို အသုံးပြုခဲ့ပါက ဘာသာစကားနားလည်မှုဝန်ဆောင်မှုများကို အသုံးပြုခဲ့သည်။ ၎င်းတို့သည် "Alexa, play the latest album by Taylor Swift" ကို AI ဝန်ဆောင်မှုများမှ ပြောင်းလဲပြီး ကျွန်ုပ်၏သမီးသည် သူမနှစ်သက်သော သီချင်းများကို နားထောင်ရင်း အိမ်ထဲတွင်踊ကြွနေသည်။
> 💁 ကွန်ပျူတာများသည် တိုးတက်မှုများစွာရှိသော်လည်း စာသားကို တကယ့်အနက်နားလည်ရန် အလွန်ဝေးကွာနေဆဲဖြစ်သည်။ ကွန်ပျူတာများနှင့် ဘာသာစကားနားလည်မှုကို ရည်ညွှန်းသောအခါ၊ လူသားဆက်သွယ်မှုကဲ့သို့ အဆင့်မြင့်သောအရာကို မဆိုလိုပါဘဲ၊ စကားလုံးအချို့ကို ယူပြီး အရေးပါသောအသေးစိတ်ကို ထုတ်ယူခြင်းကိုသာ ဆိုလိုသည်။
လူသားများအနေဖြင့် ဘာသာစကားကို အလွယ်တကူ နားလည်နိုင်သည်။ ကျွန်ုပ်သည် တစ်ဦးတစ်ယောက်ကို "Taylor Swift ရဲ့ နောက်ဆုံးထွက်အယ်လ်ဘမ်ကို ဖွင့်ပါ" ဟု ပြောပါက သူတို့သည် ကျွန်ုပ်၏အနက်ကို အလိုအလျောက် သိနိုင်သည်။ ကွန်ပျူတာအတွက်တော့ ဒါဟာ ပိုခက်ခဲသည်။ ၎င်းသည် စကားလုံးများကို အသံမှ စာသားအဖြစ် ပြောင်းပြီး၊ အောက်ပါအချက်များကို ရှာဖွေရန်လိုအပ်သည် -
* သီချင်းဖွင့်ရန်လိုအပ်သည်။
* သီချင်းသည် Taylor Swift ဆိုသော အနုပညာရှင်၏ သီချင်းဖြစ်သည်။
* သီချင်းသည် အယ်လ်ဘမ်တစ်ခုဖြစ်ပြီး၊ သီချင်းများစွာကို အစီအစဉ်တကျ ဖွင့်ရန်လိုအပ်သည်။
* Taylor Swift ၏ အယ်လ်ဘမ်များစွာရှိပြီး၊ အချိန်လိုက်စဉ်စီပြီး နောက်ဆုံးထွက်သည်ကို ရွေးရန်လိုအပ်သည်။
✅ သင်ကော်ဖီမှာခြင်း သို့မဟုတ် မိသားစုဝင်တစ်ဦးကို အရာတစ်ခုခုကို ပေးရန် တောင်းဆိုခြင်းကဲ့သို့သော တောင်းဆိုမှုများကို ပြောခဲ့သော စကားစုများကို စဉ်းစားပါ။ ကွန်ပျူတာသည် စကားစုကို နားလည်ရန် လိုအပ်သော အသေးစိတ်အချက်များကို ခွဲခြမ်းကြည့်ရန် ကြိုးစားပါ။
ဘာသာစကားနားလည်မှုမော်ဒယ်များသည် ဘာသာစကားမှ အသေးစိတ်အချက်များကို ထုတ်ယူရန် လေ့ကျင့်ထားသော AI မော်ဒယ်များဖြစ်ပြီး၊ သင်သည် Custom Vision မော်ဒယ်ကို ပုံများအနည်းငယ်ကို အသုံးပြု၍ လေ့ကျင့်သည့်နည်းလမ်းတူတူ၊ သတ်မှတ်ထားသောအလုပ်များအတွက် လေ့ကျင့်ထားသည်။
## ဘာသာစကားနားလည်မှုမော်ဒယ်တစ်ခုဖန်တီးခြင်း
![LUIS လိုဂို](../../../../../translated_images/luis-logo.5cb4f3e88c020ee6df4f614e8831f4a4b6809a7247bf52085fb48d629ef9be52.my.png)
Microsoft ၏ Cognitive Services ၏ အစိတ်အပိုင်းတစ်ခုဖြစ်သော LUIS ကို အသုံးပြု၍ ဘာသာစကားနားလည်မှုမော်ဒယ်များကို ဖန်တီးနိုင်သည်။
### Task - Authoring Resource တစ်ခုဖန်တီးပါ
LUIS ကို အသုံးပြုရန် Authoring Resource တစ်ခုဖန်တီးရန်လိုအပ်သည်။
1. `smart-timer` resource group တွင် Authoring Resource တစ်ခုဖန်တီးရန် အောက်ပါ command ကို အသုံးပြုပါ -
```python
az cognitiveservices account create --name smart-timer-luis-authoring \
--resource-group smart-timer \
--kind LUIS.Authoring \
--sku F0 \
--yes \
--location <location>
```
`<location>` ကို Resource Group ဖန်တီးခဲ့သောနေရာဖြင့် အစားထိုးပါ။
> ⚠️ LUIS သည် တချို့သောဒေသများတွင် မရရှိနိုင်ပါ၊ ထို့ကြောင့် အောက်ပါအမှားကို ရရှိပါက -
>
> ```output
> InvalidApiSetId: The account type 'LUIS.Authoring' is either invalid or unavailable in given region.
> ```
>
> အခြားဒေသတစ်ခုကို ရွေးပါ။
ဒါဟာ အခမဲ့-tier LUIS Authoring Resource တစ်ခုကို ဖန်တီးပါမည်။
### Task - ဘာသာစကားနားလည်မှု App တစ်ခုဖန်တီးပါ
1. [luis.ai](https://luis.ai?WT.mc_id=academic-17441-jabenn) တွင် LUIS portal ကို browser မှာဖွင့်ပြီး၊ Azure အကောင့်တူတူဖြင့် ဝင်ပါ။
1. Dialog မှာ သင့် Azure subscription ကို ရွေးပြီး၊ သင်ဖန်တီးထားသော `smart-timer-luis-authoring` resource ကို ရွေးပါ။
1. *Conversation apps* စာရင်းမှ **New app** ခလုတ်ကို ရွေးပြီး၊ application အသစ်တစ်ခုကို ဖန်တီးပါ။ အသစ်ဖန်တီးသော app ကို `smart-timer` ဟု အမည်ပေးပြီး၊ *Culture* ကို သင့်ဘာသာစကားအဖြစ် သတ်မှတ်ပါ။
> 💁 Prediction resource အတွက် field တစ်ခုရှိသည်။ Prediction အတွက် resource အသစ်တစ်ခုကို ဖန်တီးနိုင်သော်လည်း၊ အခမဲ့ Authoring Resource သည် တစ်လလျှင် ၁, prediction များကို ခွင့်ပြုသည်။ ဒါဟာ development အတွက် လုံလောက်သောကြောင့်၊ ၎င်းကို အလွတ်ထားနိုင်သည်။
1. App ကို ဖန်တီးပြီးနောက် ပေါ်လာသော လမ်းညွှန်ကို ဖတ်ပြီး ဘာသာစကားနားလည်မှုမော်ဒယ်ကို လေ့ကျင့်ရန် လိုအပ်သောအဆင့်များကို နားလည်ပါ။ လမ်းညွှန်ကို ဖတ်ပြီးနောက် ပိတ်ပါ။
## ရည်ရွယ်ချက်များနှင့် အရာဝတ္ထုများ
ဘာသာစကားနားလည်မှုသည် *ရည်ရွယ်ချက်များ* နှင့် *အရာဝတ္ထုများ* အပေါ် အခြေခံထားသည်။
1. *Azure Resources* အပိုင်းမှ *Authoring Resource* ကိုရွေးချယ်ပြီး *Primary Key* နှင့် *Endpoint URL* ကိုကူးယူပါ။
1. သင့် Command Prompt သို့မဟုတ် Terminal တွင် အောက်ပါ curl command ကို run လုပ်ပါ-
```sh
curl "<endpoint url>/luis/prediction/v3.0/apps/<app id>/slots/staging/predict" \
--request GET \
--get \
--data "subscription-key=<primary key>" \
--data "verbose=false" \
--data "show-all-intents=true" \
--data-urlencode "query=<sentence>"
```
`<endpoint url>` ကို *Azure Resources* အပိုင်းမှ Endpoint URL ဖြင့် အစားထိုးပါ။
`<app id>` ကို *Settings* အပိုင်းမှ App ID ဖြင့် အစားထိုးပါ။
`<primary key>` ကို *Azure Resources* အပိုင်းမှ Primary Key ဖြင့် အစားထိုးပါ။
`<sentence>` ကို သင်စမ်းသပ်လိုသော စာကြောင်းဖြင့် အစားထိုးပါ။
1. ဒီ command ရဲ့ output က JSON ဖိုင်တစ်ခုဖြစ်ပြီး၊ အဲဒီမှာ query, top intent, နဲ့ type အလိုက် ခွဲထားတဲ့ entities များကို ဖော်ပြထားပါမည်။
```JSON
{
"query": "set a timer for 45 minutes and 12 seconds",
"prediction": {
"topIntent": "set timer",
"intents": {
"set timer": {
"score": 0.97031575
},
"None": {
"score": 0.02205793
}
},
"entities": {
"number": [
45,
12
],
"time-unit": [
[
"minute"
],
[
"second"
]
]
}
}
}
```
အထက်ပါ JSON ကို `set a timer for 45 minutes and 12 seconds` ဟု query လုပ်ပြီးရရှိခဲ့သည်-
* `set timer` ဟာ 97% အနီးကပ်ဖြစ်မှုဖြင့် top intent ဖြစ်ခဲ့သည်။
* *number* entity နှစ်ခု `45` နဲ့ `12` ကို ရှာတွေ့ခဲ့သည်။
* *time-unit* entity နှစ်ခု `minute` နဲ့ `second` ကို ရှာတွေ့ခဲ့သည်။
## ဘာသာစကားနားလည်မှု မော်ဒယ်ကို အသုံးပြုပါ
LUIS မော်ဒယ်ကို publish လုပ်ပြီးနောက်၊ code မှတစ်ဆင့် ခေါ်ယူနိုင်ပါသည်။ ယခင်သင်ခန်းစာများတွင် IoT Hub ကို အသုံးပြု၍ cloud services နှင့် ဆက်သွယ်မှုကို စီမံခန့်ခွဲခဲ့ပြီး၊ telemetry ပေးပို့ခြင်းနှင့် command များကို နားထောင်ခဲ့သည်။ ဒါဟာ asynchronous ဖြစ်ပြီး၊ telemetry ပေးပို့ပြီးနောက် သင့် code က ပြန်လည်တုံ့ပြန်မှုကို မစောင့်ဘဲ၊ cloud service ပျက်ကွက်နေပါက သတိမပေးနိုင်ပါ။
Smart timer အတွက်တော့၊ timer set လုပ်ပြီးကြောင်း သုံးစွဲသူကို ပြောနိုင်ရန် သို့မဟုတ် cloud services မရရှိနိုင်ကြောင်း သတိပေးနိုင်ရန်၊ ချက်ချင်းတုံ့ပြန်မှုလိုအပ်ပါသည်။ ဒါကြောင့် IoT device က IoT Hub ကို မူတည်မထားဘဲ၊ web endpoint ကို တိုက်ရိုက်ခေါ်ယူပါမည်။
IoT device မှ LUIS ကို တိုက်ရိုက်ခေါ်မည်မဟုတ်ဘဲ၊ HTTP trigger တစ်ခုဖြင့် serverless code ကို အသုံးပြုနိုင်ပါသည်။ ဒီလိုလုပ်ခြင်းဖြင့် function app က REST request များကို နားထောင်ပြီး၊ တုံ့ပြန်မှုများပေးနိုင်ပါသည်။ ဒီ function က သင့် device က ခေါ်နိုင်တဲ့ REST endpoint ဖြစ်ပါမည်။
> 💁 IoT device မှ LUIS ကို တိုက်ရိုက်ခေါ်နိုင်သော်လည်း၊ serverless code ကဲ့သို့သော အရာကို အသုံးပြုသင့်သည်။ ဥပမာအားဖြင့် သင်ပိုမိုကောင်းမွန်သော မော်ဒယ်ကို သင်ကြားလိုက်ပါက သို့မဟုတ် မတူညီသော ဘာသာစကားတွင် မော်ဒယ်ကို သင်ကြားလိုက်ပါက၊ cloud code ကိုသာ update လုပ်ရမည်ဖြစ်ပြီး၊ IoT device အထောင်ပေါင်းများစွာ သို့မဟုတ် သန်းပေါင်းများစွာကို ပြန်လည် deploy လုပ်ရန် မလိုအပ်တော့ပါ။
### Task - serverless functions app တစ်ခု ဖန်တီးပါ
1. `smart-timer-trigger` ဟု အမည်ပေးထားသော Azure Functions app တစ်ခု ဖန်တီးပြီး၊ VS Code တွင် ဖွင့်ပါ။
1. VS Code terminal အတွင်းမှ အောက်ပါ command ကို အသုံးပြု၍ `speech-trigger` ဟု အမည်ပေးထားသော HTTP trigger တစ်ခု ထည့်ပါ-
```sh
func new --name text-to-timer --template "HTTP trigger"
```
ဒီလိုလုပ်ခြင်းဖြင့် `text-to-timer` ဟု အမည်ပေးထားသော HTTP trigger တစ်ခု ဖန်တီးပါမည်။
1. Functions app ကို run လုပ်ပြီး HTTP trigger ကို စမ်းသပ်ပါ။ Run လုပ်သောအခါ output တွင် endpoint ကို ဖော်ပြထားမည်ဖြစ်သည်-
```output
Functions:
text-to-timer: [GET,POST] http://localhost:7071/api/text-to-timer
```
သင့် browser တွင် [http://localhost:7071/api/text-to-timer](http://localhost:7071/api/text-to-timer) URL ကို load လုပ်၍ စမ်းသပ်ပါ။
```output
This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.
```
### Task - ဘာသာစကားနားလည်မှု မော်ဒယ်ကို အသုံးပြုပါ
1. LUIS အတွက် SDK ကို Pip package မှတစ်ဆင့် ရရှိနိုင်ပါသည်။ `requirements.txt` ဖိုင်တွင် အောက်ပါလိုင်းကို ထည့်ပါ-
```sh
azure-cognitiveservices-language-luis
```
1. VS Code terminal တွင် virtual environment ကို activate လုပ်ထားပြီး၊ အောက်ပါ command ကို run လုပ်ပါ-
```sh
pip install -r requirements.txt
```
> 💁 Error များရရှိပါက၊ အောက်ပါ command ဖြင့် pip ကို upgrade လုပ်ရန် လိုအပ်နိုင်ပါသည်-
>
> ```sh
> pip install --upgrade pip
> ```
1. LUIS portal ၏ **MANAGE** tab မှ LUIS API Key, Endpoint URL, နှင့် App ID အတွက် `local.settings.json` ဖိုင်တွင် entries အသစ်များ ထည့်ပါ-
```JSON
"LUIS_KEY": "<primary key>",
"LUIS_ENDPOINT_URL": "<endpoint url>",
"LUIS_APP_ID": "<app id>"
```
`<endpoint url>` ကို **MANAGE** tab ၏ *Azure Resources* အပိုင်းမှ Endpoint URL ဖြင့် အစားထိုးပါ။ ဥပမာအားဖြင့် `https://<location>.api.cognitive.microsoft.com/` ဖြစ်သည်။
`<app id>` ကို **MANAGE** tab ၏ *Settings* အပိုင်းမှ App ID ဖြင့် အစားထိုးပါ။
`<primary key>` ကို **MANAGE** tab ၏ *Azure Resources* အပိုင်းမှ Primary Key ဖြင့် အစားထိုးပါ။
1. `__init__.py` ဖိုင်တွင် အောက်ပါ imports များကို ထည့်ပါ-
```python
import json
import os
from azure.cognitiveservices.language.luis.runtime import LUISRuntimeClient
from msrest.authentication import CognitiveServicesCredentials
```
ဒီလိုလုပ်ခြင်းဖြင့် system libraries အချို့နှင့် LUIS နှင့် ဆက်သွယ်ရန်လိုအပ်သော libraries များကို import လုပ်ပါမည်။
1. `main` method ၏ content များကို ဖျက်ပြီး၊ အောက်ပါ code ကို ထည့်ပါ-
```python
luis_key = os.environ['LUIS_KEY']
endpoint_url = os.environ['LUIS_ENDPOINT_URL']
app_id = os.environ['LUIS_APP_ID']
credentials = CognitiveServicesCredentials(luis_key)
client = LUISRuntimeClient(endpoint=endpoint_url, credentials=credentials)
```
ဒီ code က သင့် LUIS app အတွက် `local.settings.json` ဖိုင်တွင် ထည့်ထားသော values များကို load လုပ်ပြီး၊ API key ဖြင့် credentials object တစ်ခု ဖန်တီးကာ၊ LUIS app နှင့် ဆက်သွယ်ရန် LUIS client object တစ်ခု ဖန်တီးပါမည်။
1. HTTP trigger ကို JSON အနေဖြင့် နားလည်ရန်လိုသော text ကို `text` ဟု အမည်ပေးထားသော property အဖြစ် ပေးပို့ပါမည်။ HTTP request ၏ body မှ value ကို extract လုပ်ပြီး၊ console တွင် log လုပ်ရန် အောက်ပါ code ကို `main` function တွင် ထည့်ပါ-
```python
req_body = req.get_json()
text = req_body['text']
logging.info(f'Request - {text}')
```
1. LUIS သို့ prediction request ပေးပို့ရန် JSON document တစ်ခု ဖန်တီးပါ-
```python
prediction_request = { 'query' : text }
```
1. Staging slot သို့ publish လုပ်ထားသော app ကို အသုံးပြု၍ LUIS သို့ request ပေးပို့ပါ-
```python
prediction_response = client.prediction.get_slot_prediction(app_id, 'Staging', prediction_request)
```
1. Prediction response တွင် top intent (အမြင့်ဆုံး prediction score ရရှိသော intent) နှင့် entities များ ပါဝင်သည်။ Top intent သည် `set timer` ဖြစ်ပါက၊ entities များမှ timer အတွက် လိုအပ်သော အချိန်ကို ဖတ်နိုင်ပါသည်-
```python
if prediction_response.prediction.top_intent == 'set timer':
numbers = prediction_response.prediction.entities['number']
time_units = prediction_response.prediction.entities['time unit']
total_seconds = 0
```
*number* entities သည် number များပါဝင်သော array ဖြစ်သည်။ ဥပမာအားဖြင့် *"Set a four minute 17 second timer."* ဟု ပြောပါက၊ `number` array တွင် 4 နှင့် 17 တို့ပါဝင်မည်။
*time unit* entities သည် string များပါဝင်သော array များဖြင့် ဖွဲ့စည်းထားသည်။ ဥပမာအားဖြင့် *"Set a four minute 17 second timer."* ဟု ပြောပါက၊ `time unit` array တွင် `['minute']` နှင့် `['second']` တို့ပါဝင်မည်။
*"Set a four minute 17 second timer."* အတွက် entities များ၏ JSON version သည်-
```json
{
"number": [4, 17],
"time unit": [
["minute"],
["second"]
]
}
```
Timer အတွက် စုစုပေါင်း အချိန်ကို seconds ဖြင့်တွက်ရန် count တစ်ခုကို ဒီ code တွင် သတ်မှတ်ထားပါသည်။
1. Entities များသည် ချိတ်ဆက်ထားခြင်းမရှိသော်လည်း၊ အချို့သော သတ်မှတ်ချက်များကို သုံးနိုင်ပါသည်။ Entities များသည် ပြောဆိုသည့် အစဉ်အတိုင်း ရှိမည်ဖြစ်ပြီး၊ array တွင်ရှိသော အနေအထားကို အသုံးပြု၍ number နှင့် time unit တို့ကို ချိတ်ဆက်နိုင်သည်။
```python
for i in range(0, len(numbers)):
number = numbers[i]
time_unit = time_units[i][0]
```
*"Set a four minute 17 second timer."* အတွက် loop နှစ်ကြိမ် လည်ပြီး၊ အောက်ပါ value များကို ရရှိမည်-
| loop count | `number` | `time_unit` |
| ---------: | -------: | ----------- |
| 0 | 4 | minute |
| 1 | 17 | second |
1. Loop အတွင်းတွင် number နှင့် time unit ကို အသုံးပြု၍ timer အတွက် စုစုပေါင်း အချိန်ကို တွက်ချက်ပါ-
```python
if time_unit == 'minute':
total_seconds += number * 60
else:
total_seconds += number
```
1. Entities များကို loop လုပ်ပြီးနောက်၊ timer အတွက် စုစုပေါင်း အချိန်ကို log လုပ်ပါ-
```python
logging.info(f'Timer required for {total_seconds} seconds')
```
1. Seconds အရေအတွက်ကို HTTP response အဖြစ် function မှ ပြန်ပေးရန်လိုအပ်သည်။ `if` block ၏ အဆုံးတွင် အောက်ပါ code ကို ထည့်ပါ-
```python
payload = {
'seconds': total_seconds
}
return func.HttpResponse(json.dumps(payload), status_code=200)
```
ဒီ code က timer အတွက် စုစုပေါင်း seconds ပါဝင်သော payload တစ်ခု ဖန်တီးပြီး၊ JSON string အဖြစ် ပြောင်းလဲကာ၊ HTTP result အနေဖြင့် status code 200 (အောင်မြင်မှု) ဖြင့် ပြန်ပေးပါမည်။
1. `if` block အပြင်တွင် intent ကို မသိရှိနိုင်ပါက error code ပြန်ပေးရန် handle လုပ်ပါ-
```python
return func.HttpResponse(status_code=404)
```
404 သည် *not found* အတွက် status code ဖြစ်သည်။
1. Function app ကို run လုပ်ပြီး curl ဖြင့် စမ်းသပ်ပါ-
```sh
curl --request POST 'http://localhost:7071/api/text-to-timer' \
--header 'Content-Type: application/json' \
--include \
--data '{"text":"<text>"}'
```
`<text>` ကို သင့် request ၏ text ဖြင့် အစားထိုးပါ၊ ဥပမာအားဖြင့် `set a 2 minutes 27 second timer`
Functions app မှ အောက်ပါ output ကို မြင်ရမည်-
```output
Functions:
text-to-timer: [GET,POST] http://localhost:7071/api/text-to-timer
For detailed output, run func with --verbose flag.
[2021-06-26T19:45:14.502Z] Worker process started and initialized.
[2021-06-26T19:45:19.338Z] Host lock lease acquired by instance ID '000000000000000000000000951CAE4E'.
[2021-06-26T19:45:52.059Z] Executing 'Functions.text-to-timer' (Reason='This function was programmatically called via the host APIs.', Id=f68bfb90-30e4-47a5-99da-126b66218e81)
[2021-06-26T19:45:53.577Z] Timer required for 147 seconds
[2021-06-26T19:45:53.746Z] Executed 'Functions.text-to-timer' (Succeeded, Id=f68bfb90-30e4-47a5-99da-126b66218e81, Duration=1750ms)
```
Curl မှ အောက်ပါ output ကို ပြန်ပေးမည်-
```output
HTTP/1.1 200 OK
Date: Tue, 29 Jun 2021 01:14:11 GMT
Content-Type: text/plain; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked
{"seconds": 147}
```
Timer အတွက် seconds အရေအတွက်ကို `"seconds"` value တွင် တွေ့နိုင်ပါသည်။
> 💁 ဒီ code ကို [code/functions](../../../../../6-consumer/lessons/2-language-understanding/code/functions) folder တွင် ရှာနိုင်ပါသည်။
### Task - သင့် IoT device အတွက် function ကို ရရှိနိုင်အောင်လုပ်ပါ
1. IoT device က REST endpoint ကို ခေါ်ရန် URL ကို သိရှိရန်လိုအပ်သည်။ အရင်က သင် `localhost` ကို အသုံးပြုခဲ့ပြီး၊ ဒါဟာ သင့် local machine တွင် REST endpoint များကို access လုပ်ရန် shortcut ဖြစ်သည်။ IoT device ကို access လုပ်ခွင့်ပေးရန်၊ cloud သို့ publish လုပ်ရန် သို့မဟုတ် သင့် IP address ကို အသုံးပြု၍ locally access လုပ်နိုင်သည်။
> ⚠️ Wio Terminal ကို အသုံးပြုပါက၊ function app ကို local တွင် run လုပ်ရလွယ်ကူသည်၊ library များအပေါ် မူတည်မှုကြောင့် function app ကို ယခင်ကဲ့သို့ deploy လုပ်၍ မရနိုင်ပါ။ Function app ကို local တွင် run လုပ်ပြီး၊ သင့် computer ၏ IP address ဖြင့် access လုပ်ပါ။ Cloud သို့ deploy လုပ်ရန် သတင်းအချက်အလက်များကို နောက်ဆုံးသင်ခန်းစာတွင် ပေးမည်။
* Functions app ကို publish လုပ်ပါ - Functions app ကို cloud သို့ publish လုပ်ရန် ယခင်သင်ခန်းစာများတွင် ပေးထားသော လမ်းညွှန်ချက်များကို လိုက်နာပါ။ Publish လုပ်ပြီးနောက်၊ URL သည် `https://<APP_NAME>.azurewebsites.net/api/text-to-timer` ဖြစ်မည်၊ `<APP_NAME>` သည် functions app ၏ အမည်ဖြစ်သည်။ Local settings ကိုလည်း publish လုပ်ပါ။
HTTP trigger များကို default အနေဖြင့် function app key ဖြင့် secured လုပ်ထားသည်။ ဒီ key ကို ရယူရန် အောက်ပါ command ကို run လုပ်ပါ-
```sh
az functionapp keys list --resource-group smart-timer \
--name <APP_NAME>
```
`functionKeys` အပိုင်းမှ `default` entry ၏ value ကို ကူးယူပါ-
```output
{
"functionKeys": {
"default": "sQO1LQaeK9N1qYD6SXeb/TctCmwQEkToLJU6Dw8TthNeUH8VA45hlA=="
},
"masterKey": "RSKOAIlyvvQEQt9dfpabJT018scaLpQu9p1poHIMCxx5LYrIQZyQ/g==",
"systemKeys": {}
}
```
ဒီ key ကို URL တွင် query parameter အဖြစ် ထည့်ရန်လိုအပ်သည်၊ ထို့ကြောင့် URL သည် `https://<APP_NAME>.azurewebsites.net/api/text-to-timer?code=<FUNCTION_KEY>` ဖြစ်မည်၊ `<APP_NAME>` သည် functions app ၏ အမည်ဖြစ်ပြီး `<FUNCTION_KEY>` သည် default function key ဖြစ်သည်။
> 💁 HTTP trigger ၏ authorization အမျိုးအစားကို `function.json` ဖိုင်တွင် `authlevel` setting ဖြင့် ပြောင်းလဲနိုင်သည်။ Microsoft docs တွင် [Azure Functions HTTP trigger documentation](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?WT.mc_id=academic-17441-jabenn&tabs=python#configuration) ၏ configuration အပိုင်းတွင် ပိုမိုသိရှိနိုင်ပါသည်။
* Functions app ကို local တွင် run လုပ်ပြီး၊ IP address ကို အသုံးပြု၍ access လုပ်ပါ - သင့် computer ၏ local network တွင်ရှိသော IP address ကို ရယူပြီး၊ URL ကို ဖန်တီးနိုင်သည်။
သင့် IP address ကို ရှာပါ-
* Windows 10 တွင် [find your IP address guide](https://support.microsoft.com/windows/find-your-ip-address-f21a9bbc-c582-55cd-35e0-73431160a1b9?WT.mc_id=academic-17441-jabenn) ကို လိုက်နာပါ။
* macOS တွင် [how to find you IP address on a Mac guide](https://www.hellotech.com/guide/for/how-to-find-ip-address-on-mac) ကို လိုက်နာပါ။
* Linux တွင် [how to find your IP address in Linux guide](https://opensource.com/article/18/5/how-find-ip-address-linux) ၏ private IP address ရှာဖွေရန် အပိုင်းကို လိုက်နာပါ။
IP address ရရှိပြီးနောက်၊ function ကို `http://`
:7071/api/text-to-timer` တွင် `<IP_ADDRESS>` ကို သင့် IP လိပ်စာဖြင့် အစားထိုးပါ၊ ဥပမာ `http://192.168.1.10:7071/api/text-to-timer`
> 💁 ဒီမှာ port 7071 ကို အသုံးပြုထားတာမို့၊ IP လိပ်စာနောက်မှာ `:7071` ထည့်ပေးရပါမယ်။
> 💁 ဒါဟာ သင့် IoT စက်နှင့် ကွန်ပျူတာဟာ တူညီတဲ့ network ပေါ်မှာရှိရင်သာ အလုပ်လုပ်ပါမယ်။
1. curl ကို အသုံးပြုပြီး endpoint ကို စမ်းသပ်ကြည့်ပါ။
---
## 🚀 စိန်ခေါ်မှု
တစ်ခုတည်းသော အရာ (ဥပမာ - timer တစ်ခု သတ်မှတ်ခြင်း) ကို တောင်းဆိုဖို့ နည်းလမ်းအမျိုးမျိုး ရှိပါတယ်။ ဒီလို နည်းလမ်းအမျိုးမျိုးကို စဉ်းစားပြီး၊ သင့် LUIS app မှာ ဥပမာအဖြစ် ထည့်သွင်းပါ။ ဒီနည်းလမ်းတွေကို စမ်းသပ်ကြည့်ပြီး၊ timer တောင်းဆိုမှုအမျိုးမျိုးကို သင့်မော်ဒယ်က ဘယ်လို ရင်ဆိုင်နိုင်သလဲ စစ်ဆေးပါ။
## မျှဝေပြီးနောက် စမ်းမေးခွန်း
[မျှဝေပြီးနောက် စမ်းမေးခွန်း](https://black-meadow-040d15503.1.azurestaticapps.net/quiz/44)
## ပြန်လည်သုံးသပ်ခြင်းနှင့် ကိုယ်တိုင်လေ့လာမှု
* LUIS နှင့် ၎င်း၏ စွမ်းဆောင်ရည်များအကြောင်းကို [Microsoft docs တွင်ရှိသော Language Understanding (LUIS) documentation page](https://docs.microsoft.com/azure/cognitive-services/luis/?WT.mc_id=academic-17441-jabenn) မှာ ဖတ်ရှုပါ။
* ဘာသာစကားနားလည်မှုအကြောင်းကို [Wikipedia တွင်ရှိသော natural-language understanding page](https://wikipedia.org/wiki/Natural-language_understanding) မှာ ဖတ်ရှုပါ။
* HTTP triggers အကြောင်းကို [Microsoft docs တွင်ရှိသော Azure Functions HTTP trigger documentation](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?WT.mc_id=academic-17441-jabenn&tabs=python) မှာ ဖတ်ရှုပါ။
## လုပ်ငန်းတာဝန်
[Timer ကို ပယ်ဖျက်ပါ](assignment.md)
---
**အကြောင်းကြားချက်**:
ဤစာရွက်စာတမ်းကို AI ဘာသာပြန်ဝန်ဆောင်မှု [Co-op Translator](https://github.com/Azure/co-op-translator) ကို အသုံးပြု၍ ဘာသာပြန်ထားပါသည်။ ကျွန်ုပ်တို့သည် တိကျမှုအတွက် ကြိုးစားနေသော်လည်း၊ အလိုအလျောက် ဘာသာပြန်မှုများတွင် အမှားများ သို့မဟုတ် မမှန်ကန်မှုများ ပါဝင်နိုင်သည်ကို သတိပြုပါ။ မူရင်းဘာသာစကားဖြင့် ရေးသားထားသော စာရွက်စာတမ်းကို အာဏာတရ အရင်းအမြစ်အဖြစ် သတ်မှတ်သင့်ပါသည်။ အရေးကြီးသော အချက်အလက်များအတွက် လူက ဘာသာပြန်မှု ဝန်ဆောင်မှုကို အကြံပြုပါသည်။ ဤဘာသာပြန်မှုကို အသုံးပြုခြင်းမှ ဖြစ်ပေါ်လာသော အလွဲသုံးစားမှု သို့မဟုတ် အနားလွဲမှုများအတွက် ကျွန်ုပ်တို့သည် တာဝန်မယူပါ။