모델 적응으로 텍스트 변환 결과 개선

개요

Speech-to-Text가 특정 단어나 구문을 제안된 다른 단어나 구문보다 더 자주 인식하도록 하려면 모델 적응 기능을 사용하면 됩니다. 예를 들어 'weather'라는 단어가 자주 등장하는 오디오 데이터가 있고 Speech-to-Text가 단어 'weather'를 발견할 때 이 단어를 'whether'보다는 'weather'로 더 많이 변환하도록 하려고 합니다. 이 경우 모델 적응을 사용하여 Speech-to-Text가 'weather'를 편향되게 인식하도록 할 수 있습니다.

모델 적응은 특히 다음과 같은 사용 사례에 유용합니다.

  • 오디오 데이터에서 자주 나타나는 단어와 구문의 정확도를 향상시킵니다. 예를 들어 일반적으로 사용자가 말하는 음성 명령어를 인식 모델에 알릴 수 있습니다.

  • Speech-to-Text에서 인식되는 단어의 어휘를 확장합니다. Speech-to-Text에는 매우 많은 어휘가 포함되어 있습니다. 하지만 오디오 데이터에 일반적으로 사용되지 않는 단어(예: 고유 명사 또는 도메인 관련 단어)가 포함된 경우 모델 적응을 사용하여 이를 추가할 수 있습니다.

  • 제공된 오디오에 노이즈가 있거나 오디오가 그다지 선명하지 않을 때 음성 텍스트 변환의 정확도를 향상시킵니다.

사용 중인 언어로 모델 적응 기능을 사용할 수 있는지 확인하려면 언어 지원 페이지를 참조하세요.

단어 및 구문 인식 향상

Speech-to-Text가 오디오 데이터를 텍스트로 변환할 때 'weather'라는 단어가 인식될 확률을 높이려면 SpeechAdaptation 리소스의 PhraseSet객체에 이 단일어를 전달할 수 있습니다.

여러 단어로 구성된 구문을 제공하면 Speech-to-Text가 이러한 단어를 순서대로 인식할 가능성이 높아집니다. 구문을 제공하면 개별 단어를 포함하여 구문의 일부분이 인식될 수 있는 가능성도 높아집니다. 이러한 구문 수와 크기에 대한 한도는 콘텐츠 한도 페이지를 참조하세요.

원하는 경우 모델 적응 부스트 기능을 사용하여 모델 적응의 강도를 미세 조정할 수 있습니다.

클래스를 사용하여 인식 향상

클래스는 자연어에서 발생하는 화폐 단위 및 달력 날짜와 같은 일반적인 개념을 나타냅니다. 클래스를 사용하면 일반적인 개념으로 매핑되지만 항상 동일한 단어나 문구가 포함되지 않는 큰 단어 그룹의 텍스트 변환 정확도를 향상시킬 수 있습니다.

예를 들어 오디오 데이터에 사람들이 말한 자신의 상세 주소가 녹음되어 있다고 가정해 보겠습니다. 이 오디오에는 누군가 말한 "My house is 123 Main Street, the fourth house on the left."가 녹음되어 있을 수 있습니다. 이 경우 사용자는 Speech-to-Text가 첫 번째 숫자 시퀀스인 '123'을 서수 '123번째'가 아닌 주소로 인식하기를 원합니다. 하지만 모든 사람들이 '123 Main Street'에 거주하는 것은 아니기 때문에 가능한 모든 상세주소를 PhraseSet 리소스에 나열하는 것은 실행 불가능합니다. 대신 클래스를 사용하면 실제 숫자에 관계없이 번지 수로 인식되도록 할 수 있습니다. 이 예시에서 Speech-to-Text는 '123 Main Street' 및 '987 Grand Boulevard'와 같은 문구를 더 정확하게 텍스트로 변환할 수 있습니다. 숫자가 모두 번지 수로 인식되기 때문입니다.

클래스 토큰

모델 적응에 클래스를 사용하려면 PhraseSet 리소스의 phrases 필드에 클래스 토큰을 포함합니다. 사용 중인 언어에 사용 가능한 토큰을 확인하려면 지원되는 클래스 토큰 목록을 참조하세요. 예를 들어 소스 오디오에서 번지 수를 더욱 정확하게 텍스트로 변환하려면 SpeechContext 객체에 $ADDRESSNUM 값을 제공합니다.

클래스를 phrases 배열에서 독립형 항목으로 사용하거나 클래스 토큰 한 개 이상을 여러 단어로 구성된 긴 구문에 삽입할 수 있습니다. 예를 들어 클래스 토큰을 ["my address is $ADDRESSNUM"] 문자열에 포함하면 더 긴 구문에 번지 수를 표시할 수 있습니다. 하지만 오디오에 'I am at 123 Main Street'와 같이 비슷하지만 동일하지 않은 문구가 포함된 경우에는 이 문구가 도움이 되지 않습니다. 비슷한 구문을 인식하려면 ["my address is $ADDRESSNUM", "$ADDRESSNUM"]과 같이 클래스 토큰 자체를 추가해야 합니다. 형식이 잘못되었거나 유효하지 않은 클래스 토큰을 사용하면 Speech-to-Text는 오류를 트리거하지 않고 토큰을 무시하지만 구문의 나머지 부분을 컨텍스트에 계속 사용합니다.

커스텀 클래스

또한 자체 CustomClass를 만들 수도 있습니다. 이는 관련된 항목이나 값의 맞춤 목록으로 구성된 클래스입니다. 예를 들어 수백 개의 지역별 음식점 이름 중에서 어느 한 개가 포함되었을 가능성이 있는 오디오 데이터를 텍스트로 변환하려고 합니다. 일반 발화에서 음식점 이름이 나오는 것은 상대적으로 드물기 때문에 인식 모델에서 '올바른' 답변으로 선택될 가능성은 낮습니다. 커스텀 클래스를 사용하면 오디오에서 이름이 나타날 때 이러한 이름이 올바르게 식별되도록 인식 모델을 편향되게 할 수 있습니다.

커스텀 클래스를 사용하려면 각 음식점 이름이 ClassItem으로 포함된 CustomClass 리소스를 만듭니다. 커스텀 클래스는 사전 빌드된 클래스 토큰과 동일한 방식으로 작동합니다. phrase에는 사전 빌드된 클래스 토큰 및 커스텀 클래스가 모두 포함될 수 있습니다.

ABNF 문법

또한 증강된 Backus–Naur 양식(ABNF)의 문법을 사용하여 단어 패턴을 지정할 수 있습니다. 요청의 모델 적응에 ABNF 문법을 포함하면 Speech-to-Text가 지정된 문법과 일치하는 모든 단어를 인식할 가능성이 높아집니다.

이 기능을 사용하려면 요청의 SpeechAdaptation 필드에 ABNF grammar 객체를 포함합니다. ABNF 문법은 또한 CustomClassPhraseSet 리소스에 대한 참조를 포함할 수 있습니다. 이 필드의 구문에 대해 자세히 알아보려면 Speech Recognition Grammar Specification과 아래의 code sample을 참조하세요.

부스트를 사용하여 변환 결과 미세 조정

기본적으로 모델 적응은 대부분의 경우 이미 충분한 효과를 제공해야 합니다. 모델 적응 부스트 기능을 사용하면 일부 구문에 다른 구문보다 더 많은 가중치를 할당하여 인식 모델 편향을 높일 수 있습니다. 1) 모델 적응을 이미 구현했고 2) 변환 결과에서 모델 적응 효과의 강도를 더욱 조정하려는 경우에만 부스트를 구현하는 것이 좋습니다.

예를 들어 사람들이 'fare to get into the county fair'에 대해 묻는 녹음이 많이 있고 단어 'fare'보다 'fair'가 더 자주 나타난다고 가정해 보겠습니다. 이 경우 모델 적응을 사용하여 모델이 PhraseSet 리소스에서 phrases을 추가하여 'fair'와 'fare'를 모두 인식하도록 할 수 있습니다. 그러면 예를 들어 Speech-to-Text가 'hare' 또는 'lair'보다 'fair' 및 'fare'를 더 자주 인식합니다.

하지만 'fair'가 오디오에 더 자주 등장하므로 'fare'보다 더 자주 인식되어야 합니다. Speech-to-Text API를 사용하여 오디오를 이미 텍스트 변환한 후 올바른 단어('fair')를 인식하는 데 많은 오류가 발생한 것으로 확인되었을 수 있습니다. 이 경우 부스트가 포함된 구문을 추가로 사용하여 'fare'보다 'fair에 더 높은 부스트 값을 할당할 수 있습니다. 'fair'에 할당되는 가중치 값이 높을수록 Speech-to-Text API가 'fare'보다는 'fair'를 선택할 가능성이 높아집니다. 부스트 값이 없으면 인식 모델이 'fair'와 'fare'를 인식할 확률은 동일합니다.

부스트 기본사항

부스트를 사용하면 PhraseSet 리소스의 phrase 항목에 가중치 값이 할당됩니다. Speech-to-Text는 오디오 데이터의 단어에 가능한 변환 텍스트를 선택할 때 이 가중치를 참조합니다. 이 값이 높을수록 Speech-to-Text가 가능한 대체 변환 텍스트 중에서 해당 구문을 선택할 확률이 높아집니다.

예를 들어 'My favorite exhibit at the American Museum of Natural History is the blue whale'이라는 문구에 무스트 값을 할당할 수 있습니다. 이 문구를 phrase 객체에 추가하고 부스트 값을 할당하면 인식 모델이 문구 전체를 단어 대 단어로 인식할 가능성이 높아집니다.

여러 단어 문구를 부스트하여 원하는 결과를 얻지 못한 경우에는 문구를 추가 phrase 항목으로 만들고 각 항목에 부스트 값을 할당하는 모든 바이그램(순서대로 2단어)을 추가하는 것이 좋습니다. 위 예시에 이어서 'my favorite', 'my favorite exhibit', 'favorite exhibit', 'my favorite exhibit at the American Museum of Natural History', 'American Museum of Natural History', 'blue whale' 등으로 바이그램 및 N-그램(2단어 초과)을 추가하여 조사해볼 수 있습니다. 그러면 Speech-to-Text 인식 모델이 원래 부스트된 문구의 일부를 포함하지만 단어 대 단어로 완전히 일치하지는 않는 관련 문구를 오디오에서 인식할 가능성이 더 높아집니다.

부스트 값 설정

부스트 값은 0보다 큰 부동 소수점 값이어야 합니다. 부스트 값의 실제 최대 한도는 20입니다. 최상의 결과를 얻으려면 정확한 텍스트 변환 결과를 얻을 때까지 부스트 값을 늘리거나 줄여서 텍스트 변환 결과를 실험합니다.

부스트 값이 높을수록 오디오에 포함된 단어나 구문이 Speech-to-Text에서 올바르게 인식되지 않는 거짓음성이 발생할 확률이 낮아집니다. 그러나 부스트는 오디오에 포함되지 않은 단어나 구문이 변환 텍스트에 나타나는 거짓양성을 증가시킬 수도 있습니다.

시간 초과 알림 받기

Speech-to-Text 응답에는 인식 중 모델 적응 동작에 대한 정보를 제공하는 SpeechAdaptationInfo 필드가 포함되어 있습니다. 모델 적응과 관련된 시간 초과가 발생하면 adaptationTimeouttrue가 되고 timeoutMessage가 시간 초과를 일으킨 적응 구성을 지정합니다. 시간 초과가 발생하면 반환된 스크립트에 모델 적응이 영향을 주지 않습니다.

모델 적응 사용 사례의 예시

다음 예시는 모델 적응을 사용하여 'call me fionity and oh my gosh what do we have here ionity'라고 말하는 사람의 오디오 녹음 파일을 텍스트로 변환하는 과정을 안내합니다. 이 경우 모델이 'fionity'와 'ionity'를 올바르게 식별하는 것이 중요합니다.

다음 명령어는 모델 적응 없이 오디오 인식을 수행합니다. 그 결과로 나온 텍스트 변환이 잘못되었습니다. 'call me Fiona tea and oh my gosh what do we have here I own a day'라고 되어 있습니다.

   curl -H "Authorization: Bearer $(gcloud auth
   --impersonate-service-account=$SA_EMAIL print-access-token)" -H
   "Content-Type: application/json; charset=utf-8"
   "https://speech.googleapis.com/v1p1beta1/speech:recognize" -d '{"config":
   {"languageCode": "en-US"}, "audio":
   {"uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"}}'
   

요청 예시:

     {
       "config":{
       "languageCode":"en-US"
       },
       "audio":{
          "uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"
       }
     }
   

PhraseSet를 사용하여 텍스트 변환 개선

  1. PhraseSet를 만듭니다.

    curl -X POST -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/phraseSets"
    -d '{"phraseSetId": "test-phrase-set-1"}'
    

    요청 예시:

    {
       "phraseSetId":"test-phrase-set-1"
    }
    
  2. PhraseSet를 가져옵니다.

    curl -X GET -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id>/locations/global/phraseSets/test-phrase-set-1"\
    
  3. PhraseSet에 'fionity'와 'ionity' 문구를 추가하고 각각에 boost 값 10을 할당합니다.

    curl -X PATCH -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/phraseSets/test-phrase-set-1?updateMask=phrases"\
    -d '{"phrases": [{"value": "ionity", "boost": 10}, {"value": "fionity", "boost": 10}]}'
    

    PhraseSet가 이제 다음으로 업데이트되었습니다.

    {
      "phrases":[
         {
              "value":"ionity",
              "boost":10
           },
           {
              "value":"fionity",
              "boost":10
           }
        ]
     }
    
  4. 모델 적응 및 이전에 만든 PhraseSet를 사용하여 오디오를 다시 인식합니다. 텍스트 변환 결과가 이제 정확합니다. 'call me fionity and oh my gosh what do we have here ionity'라고 되어 있습니다.

    curl -H "Authorization: Bearer $(gcloud auth --impersonate-service-account=$SA_EMAIL print-access-token)"
    -H "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/speech:recognize" -d '{"config":
    {"adaptation": {"phrase_set_references": ["projects/project_id/locations/global/phraseSets/test-phrase-set-1"]},
    "languageCode": "en-US"}, "audio": {"uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"}}'
    

    요청 예시:

    {
       "config":{
          "adaptation":{
             "phrase_set_references":[
                "projects/project_id/locations/global/phraseSets/test-phrase-set-1"
             ]
          },
          "languageCode":"en-US"
       },
       "audio":{
          "uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"
       }
    }
    

CustomClass를 사용하여 텍스트 변환 결과 개선

  1. CustomClass를 만듭니다.

    curl -X POST -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/customClasses"
    -d '{"customClassId": "test-custom-class-1"}'
    

    요청 예시:

    {
       "customClassId": "test-custom-class-1"
    }
    
  2. CustomClass를 가져옵니다.

     curl -X GET -H "Authorization: Bearer $(gcloud auth
     --impersonate-service-account=$SA_EMAIL print-access-token)" -H
     "Content-Type: application/json; charset=utf-8"
     "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/customClasses/test-custom-class-1"
     

  3. 테스트 오디오 클립을 인식합니다. CustomClass가 비어 있으므로, 반환된 스크립트는 여전히 잘못된 상태입니다. 'call me Fiona tea and oh my gosh what do we have here I own a day':

    curl -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/speech:recognize" -d '{"config":
    {"adaptation": {"phraseSets": [{"phrases": [{"value":
    "${projects/project_idlocations/global/customClasses/test-custom-class-1}",
    "boost": "10"}]}]}, "languageCode": "en-US"}, "audio":
    {"uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"}}'
    

    요청 예시:

      {
       "config":{
          "adaptation":{
             "phraseSets":[
                {
                   "phrases":[
                      {
                         "value":"${projects/project_id/locations/global/customClasses/test-custom-class-1}",
                         "boost":"10"
                      }
                   ]
                }
             ]
          },
          "languageCode":"en-US"
       },
       "audio":{
          "uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"
       }
     }
    
  4. 커스텀 클래스에 'fionity'와 'ionity' 구문을 추가합니다.

    curl -X PATCH -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/customClasses/test-custom-class-1?updateMask=items"
    -d '{"items": [{"value": "ionity"}, {"value": "fionity"}]}'
    

    이렇게 하면 커스텀 클래스가 다음과 같이 업데이트됩니다.

    {
       "items":[
          {
             "value":"ionity"
          },
          {
             "value":"fionity"
          }
       ]
    }
    
  5. 다시 샘플 오디오를 인식합니다. 이번에는 CustomClass에 'fionity' 및 'ionity'를 사용합니다. 이제 스크립트가 올바릅니다. 'call me fionity and oh my gosh what do we have here ionity'.

    curl -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/speech:recognize" -d '{"config":
    {"adaptation": {"phraseSets": [{"phrases": [{"value":
    "${projects/project_id/locations/global/customClasses/test-custom-class-1}",
    "boost": "10"}]}]}, "languageCode": "en-US"}, "audio":
    {"uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"}}'
    

    요청 예시:

    {
       "config":{
          "adaptation":{
             "phraseSets":[
                {
                   "phrases":[
                      {
    "value":"${projects/project_id/locations/global/customClasses/test-custom-class-1}",
                         "boost":"10"
                      }
                   ]
                }
             ]
          },
          "languageCode":"en-US"
       },
       "audio":{
          "uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"
       }
    }
    

PhraseSetCustomClass 참조

  1. 이전에 만든 PhraseSet 리소스를 업데이트하여 CustomClass를 참조합니다.

    curl -X PATCH -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/phraseSets/test-phrase-set-1?updateMask=phrases"
    -d '{"phrases": [{"value": "${projects/project_id/locations/global/customClasses/test-custom-class-1}", "boost": 10}]}'
    

    요청 예시:

    {
       "config":{
          "adaptation":{
             "phraseSets":[
                {
                   "phrases":[
                      {
                         "value":"${projects/project_id/locations/global/customClasses/test-custom-class-1}",
                         "boost":"10"
                      }
                   ]
                }
             ]
          },
          "languageCode":"en-US"
       },
       "audio":{
          "uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"
       }
    }
    
  2. PhraseSet 리소스(CustomClass 참조)를 사용하여 오디오를 인식합니다. 스크립트는 정확합니다. 'call me fionity and oh my gosh what do we have here ionity'라고 되어 있습니다.

    curl -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/speech:recognize" -d '{"config":
    {"adaptation": {"phrase_set_references":
    ["projects/project_id/locations/global/phraseSets/test-phrase-set-1"]},
    "languageCode": "en-US"}, "audio":
    {"uri":"gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav"}}'
    

    요청 예시:

    {
       "phrases":[
          {
             "value":"${projects/project_id/locations/global/customClasses/test-custom-class-1}",
             "boost":10
          }
       ]
    }
    

CustomClassPhraseSet 삭제

  1. PhraseSet를 삭제합니다.

    curl -X DELETE -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/phraseSets/test-phrase-set-1"
    
  2. CustomClass을 삭제합니다.

    curl -X DELETE -H "Authorization: Bearer $(gcloud auth
    --impersonate-service-account=$SA_EMAIL print-access-token)" -H
    "Content-Type: application/json; charset=utf-8"
    "https://speech.googleapis.com/v1p1beta1/projects/project_id/locations/global/customClasses/test-custom-class-1"
    

ABNF Grammar를 사용하여 텍스트 변환 결과 개선

  1. abnf_grammar를 사용하여 오디오를 인식합니다. 이 예시에서는 CustomClass 리소스: projects/project_id/locations/global/customClasses/test-custom-class-1, 인라인 CustomClass: test-custom-class-2, class token: ADDRESSNUM, PhraseSet 리소스: projects/project_id/locations/global/phraseSets/test-phrase-set-1을 참조합니다. 문자열의 첫 번째 규칙(외부 선언 뒤)은 루트로 처리됩니다.

    요청 예시:

    {
       "config":{
          "adaptation":{
             "abnf_grammar":{
                "abnf_strings": [
                  "external ${projects/project_id/locations/global/phraseSets/test-phrase-set-1}" ,
                  "external ${projects/project_id/locations/global/customClasses/test-custom-class-1}" ,
                  "external ${test-custom-class-2}" ,
                  "external $ADDRESSNUM" ,
                  "$root = $test-phrase-set-1 $name lives in $ADDRESSNUM;" ,
                  "$name = $title $test-custom-class-1 $test-custom-class-2" ,
                  "$title = Mr | Mrs | Miss | Dr | Prof ;"
                ]
             }
          }
       }
    }
    

다음 단계