'머신러닝'에 해당되는 글 3건

  1. 2020.01.01 Bixby's hello world (3)
  2. 2019.12.17 Bixby's hello world (2)
  3. 2019.12.10 Bixby's hello world

Bixby's hello world (3)

Personal Computer/Linux 2020. 1. 1. 00:46 posted by tolkien

오늘은 입력을 받아서 처리하도록 바꾸어보자.

 say "hello"라고 하면 Bixby는 HELLO, WORLD 라고 답을 하고,

 say "foo"라고 하면 Bixby는 FOO, BAR라고 답을 한다.

( Bixby Studio를 7.8.1-r19x.13460로 upgrade하면 나오는 warning에 대한 처리.

더보기

그전에 Bixby Studio를 7.8.1-r19x.13460로 upgrade하면 이전에 있는 예제 code에서 warning이 나온다.
나오는 위치는 capsule.bxb로 아래와 같은 경고이다.

Line 8:3DEPRECATED: `runtime-flags` is deprecated, move to `runtime-version`
[This deprecation will prevent new submissions in 20A] [deprecation 6797]View Deprecation Guide

그러면 capsule.bxb에 있는 runtime-flags { ... } 부분을 지우고 아래 code로 대체하면 그 경고는 사라진다.

  runtime-version (2) {
    overrides {
      concepts-inherit-super-type-features (true)
    }

)

 

먼저 helloWorld.js에서 입력을 받아서 처리하도록 해보자. 함수를 다음과 같이 바꾼다.

module.exports.function = function helloWorld (what) {
  if (what == "foo")
    return "foo, bar"
  return "hello, world"
 }

그러면 Bixby Studio는 바로 아래와 같은 경고를 내보낸다.

there is a warning:
The parameters [what] defined in the function 'null' are not listed in the 'accepted-inputs' []

accepted-inputs에 [what] parameter가 없다. accepted-input은 어디에 있는 것인지...

stack overflow나 bixby developer center에서 찾아보면 endpoints.bxb에서 사용하는 keyword.

즉, what이라는 변수를 Bixby에서 처리할 수 있도록 pipeline을 만들어 주어야 할 것같습니다.

 

먼저, what을 instance로 하는 hello type을  models/concepts/hello.model.bxb 에 만들어 준다.
 ( New -> Model -> template:text, name: models/concepts/hello.model.bxb )

 

그리고, action doHelloWorld에 input parameter가 있다는 것을 알려준다.

 아래 내용을 action(doHelloWorld) 안에 넣는다.

  collect {
    input (what) {
      type (hello)
      min (Required)
      max (One)
    }
  }

그리고, doHelloWorld action과 javascript을 연결하는 endpoint에 accepted-input keyword를 써서 입력이 있음을 알려준다. action-endpoint (doHelloWorld) 안에 한줄 추가

      accepted-inputs (what)

여기까지 하면 warning은 사라지지만, Bixby emulator를 실행시켜보면 뭐라고 말하던 HELLO, WORLD만 외친다.

training에 say "foo"를 학습시켜야 한다. resources/en-US/training에 가서 click하면 학습된 say it이라는 문장이 보인다. 여기서 it을 hello type의 input이라고 알려주어야 한다. 아래와 같이 수정하자.

Save한 다음에 "Compile NL Model"을 click해주면 된다.

Bixby Emulator를 띄워서 say foo라고 치면 "foo, bar"라고 답할 것이다.

여기까지 내용은 제 개인 github에 올라가 있습니다.

 

마지막으로, Bixby가 이 일련의 과정을 어떻게 처리하는지 제가 이해한 바는 다음과 같습니다.

단말에서 say "foo"라고 하면

 1. Bixby는 이 말을 say + parameter:foo로 분해해서
 2. resources/en-US/training에 있는 NL Model에 넣는다.
 3. NL Model에서 say + parameter pattern을 찾으면 출력이 text:world이다.
 4. 출력이 text:world인 action인 doHelloWorld.model.bxb를 찾고,
 5. action-endpoint(doHelloWorld)에서 helloWorld.js를 얻은 다음
 6. helloWorld(parameter:foo)를 호출하여 return값으로 text:"foo, bar"를 얻는다.
 7. 출력은 en-US/dialogs/helloVoice.dialog.bxb내 dialog(Result)에서 처리하는데,
 8. text:"foo, bar"이면 "foo, bar"라고 소리를 낸다.

Bixby's hello world (2)

Personal Computer/Linux 2019. 12. 17. 23:02 posted by tolkien

지난번에 이어 오늘은 Bixby로 하여금 말을 하게 해보자.

 

아직 result-view로 output을 design하는 것을 잘 알지 못하겠고,

Dialog를 써서 소리를 내는 것만 할 수 있을 것같다. (Dialog 재정의 하기)

Dialog event중에서 Result에 대한 dialog를 재정의해서 출력시 소리가 나오게 한다.

 

1. resources/en-US/dialogs/helloVoice.dialog.bxb

 * resources/en-US/dialogs에서 오른쪽 click -> New... -> Dialog 선택한 다음 helloVoice를 생성하고 아래 내용으로 채운다.

dialog (Result) {
  match: world (txt) {
    from-output: doHelloWorld ()
  }

  if (txt == 'hello, world') {
    template("HELLO, WORLD") {
      speech ("hello, world")
    }
  } else-if (txt == 'foo, bar') {
    template ("FOO, BAR") {
      speech ("foo, bar")
    }
  }
}

 * match: {} 부분을 설명하자면 (파악하는데, 시간이 걸렸다.)

    doHelloWorld action에서 나오는 결과값중에서 변수 타입이 world인 txt 변수에 대해서 처리한다.

 * 그리고나서 txt 내용에 따라서 출력할 내용을 정한다.

   speech() 함수를 이용해서 소리내서 말하게 하는데, SSML이라는 문법을 사용한다고 한다.

   (Bixby에서 사용되는 SSML 설명)

 * 참고로 javascript 함수인 HelloWorld()에서 return 값이 "foo, bar"로 return하면 "foo, bar"로 발음한다.

 

예제 파일은 https://github.com/tolkien/playground.helloworld 에서 받을 수 있습니다.

다음할 일 : 입력을 say hello로 받으면 hello, world를, say foo를 받으면 foo, bar를 말하게 하기

Bixby's hello world

Personal Computer/Linux 2019. 12. 10. 02:49 posted by tolkien

컴퓨터 언어를 새로 접하면 항상 해보는 것이 "hello, world" 문자열찍는 예제이다.

빅스비에서 hello, world에 해당되는 것이 capsule-sample-dice, 이른바 주사위 던지기.이다.

 

심지어 Bixby Developer Center에 들어가면 Quick Start Guide로 제시하고 있다.

처음부터 생성하는 것이 아니라 예제를 download받고 그 내용을 설명하는 것으로 되어 있다.

빅스비의 개념을 익히는데, 상당히 힘들뿐 아니라 실행도 전혀 빅스비답지 않다.

그래서, 만들어봤다.

 

0. Bixby Studio를 깔고 실행하면 제일 먼저 login 화면이 나온다.

    삼성 Bixby 개발자로 등록하지 않으면 Bixby 맛도 볼 수 없다. 돈 드는 것 아니니, 등록하자.

    여기서 사용한 Bixby Studio Version은 7.8.0-r19w.13177 (2019/12/10일 기준) 이다.

 

1. Capsule 만들기. 빅스비에서는 실행파일 == Capsule이다.

- File메뉴에서 New Capsule 선택하고, Capsule ID는 playground.helloworld .

* 참고로 playground.라는 prefix를 주지 않으면 Bixby IDE에서 생성하지 않는다. 그리고, Capsule ID는 영어 소문자로 시작해야 한다. 이런저런 이름에 대한 제한은 Capsule 생성 dialog에 있는 link를 찍어서 내용을 확인할 것.

 

생성하면 뭔가 기본 파일들을 만들어 주는데, error 3개, warning 7개가 뜬다. 시작부터 난감.

일단 이 error부터 잡으면서 시작하는 것이 정신건강상 좋은 것같다.

 

2. 해당 Capsule을 확장하면 보이는 capsule.bxb 를 열고 아래 내용을 추가한다.

  store-sections{
    section (GamesAndFun)
  }

  store-countries{
   // all
   only{
      allow (KR)
    }
  }

그리고, runtime-flags { .. } 안에 다음을 추가한다.

 // add below for error correction
no-filtering-with-validation
modern-default-view-behavior
use-input-views-for-selection-list-detail

 

3. 그 다음으로 resource/en-US/capsule-info.bxb 을 열어서 다음을 추가한다.

  dispatch-name (helloworld)
  search-keywords {
    keyword (hello)
  }

그럼 warning 하나 빼고 capsule.bxb에서 나오는 error는 사라진다.

(남은 하나는 icon file이 없다고 징징대는 것인데, 없어도 실행하는데 지장없다.)

 

4. 그리고, resources/en-US/hints.bxb 파일을 열어서 hint(...) 부분을 지우고 다음을 추가.

    hint (ask helloworld to say it)
    hint (ask helloworld to say world)
    hint (ask helloworld to say something)

여기에 좀 지저분한 것이 있는데, 보고 싶으시면

더보기
The current en-US dispatch patterns are the following:

 

"with %dispatch-name% ..."

"in %dispatch-name% ..."

"ask %dispatch-name% ..."

"ask %dispatch-name% for ..."

"ask %dispatch-name% to ..."

 

The current ko-KR dispatch pattern is the following:

 

%dispatch-name% 에서 ...

 

for detail, see https://stackoverflow.com/questions/57241026/invoke-specific-action-when-bixby-capsule-launched

 

이제 warning 하나만 남았으니 뭔가 compile해서 실행할 수 있을 것같다.

여기서 왼쪽 하단의 휴대폰 모양 icon을 click하면 Bixby emulator가 뜨는데,

왼쪽에  어떤 글자를 입력한 다음에 "Run NL"을 실행해도 "I didn't understand that"이라는 말만 한다.

그럼 이제 뭔가를 타이핑하거나 말하면 hello, world라는 글자가 출력되게 하자.

 

5. models/concepts/world.model.bxb 생성

 * Bixby에서 Concept은 C나 java에서 변수와 같은 개념이다. 변수가 100개면 Concept 파일이 100개~

 * 왼쪽 helloworld Capsule browser에서

  . models를 click해서 확장시키고

  . concepts 위에서 마우스 오른쪽 click 하면

  . Context Menu가 뜨고, 거기서 New -> Model 선택하면 Dialog가 뜬다.

    여기서 File Type: Model, Template : Text 선택해주고, filename은 world.model.bxb

 

  -> 이러면, world라는 text 변수가 하나 생성되었다.

 

6. code/helloWorld.js 생성

 * 그 다음에는 world라는 text 변수에 "hello, world"를 넣도록 javaScript을 작성하자.

 * helloworld Capsule browser에서

  . code 위에서 마우스 오른쪽 click해서 New -> Action JavaScript 선택

  . 파일명은 code/helloWorld.js 으로 만들어 주고, 아래 내용으로 바꾸어 넣자

module.exports.function = function helloWorld () {
  return "hello, world"
}

 

7. models/actions/doHelloWorldᅟ.model.bxb 생성

 * 이제 doHelloWorld라는 ᅟAction을 생성한다. 일종의 trigger라고 생각하면 된다.

 * helloworld Capsule browser에서

  . models -> concepts 위에서 마우스 오른쪽 click해서 New -> Model 선택

  . File Type: Model, Template : Action, filename은 doHelloWorld.model.bxb

  . 그리고, 아래 내용으로 바꾸어 넣자

action (doHelloWorld) {

  output (world)
  type (Calculation)
}

 

8. resources/base/views/helloWorld.view.bxb 생성

 * 출력 형태를 결정하는 것인데, 그냥 빈파일로 냅두자. (생성하지 않아도 됨)

 * helloworld Capsule browser에서

  . resources -> base -> views 위에서 마우스 오른쪽 click해서 -> New -> View

 

 

9. endpoints 설정하기.

 * endpoint란 input -> action -> output 을 연결해주는 역활은 한다.

 * resources/base/endpoints.bxb 의 내용을 아래 내용으로 바꾼다. 입력이 없으므로 따로 정의하지 않는다.

endpoints {
  // action과 그에 맞는 자바스크립트를 매핑
  action-endpoints {
    action-endpoint (doHelloWorld) {
      local-endpoint ("helloWorld.js")
    }
  }
}

 

 

10. 이제 빅스비를 훈련시켜서 hello, world 문자열을 출력하게 하자.

 * resources/en-US/training 열면 다음과 같은 화면이 나온다.

 

"Enter natural language training"이라고 써 있는 곳에 say it 이라고 입력하고 Add를 click하면

GOAL을 입력하라고 나온다. 여기에 정의해두었던 Concept인 world 을 입력하고 저장한다.

그리고, "Compile NL Model"을 click하면 hello, world 문자열을 볼 준비는 다 끝난 것이다.

 

11. 이제 hello, world 예제를 실행해보자.

 * 왼쪽 하단의 휴대폰 Icon을 click에서 emulator를 실행하고,

왼쪽에 say it이라고 입력한 다음에 "Run NL"을 실행하면 hello, world 문자열을 볼 수 있다.

 

마지막으로, 한가지 고백하자면 입력창에 어떤 내용을 넣어도, 어떤 말을 해도 위 화면만 나오게 된다.

왜냐하면 Bixby Emulator에서는 helloWorld Capsule만 동작하고 있고, 입력과 상관없이 무조건 hello, world 를 출력하게 했기 때문이다.

 

예제 파일은 https://github.com/tolkien/playground.helloworld 에서 받을 수 있습니다.

 

개선할 점. hello, world을 음성으로 들을 수 있도록 해보자.