지난해 11월, 구글이 공개한 인공지능(AI) 언어모델 ‘BERT(이하 버트, Bidirectional Encoder Representations from Transformers)’는 일부 성능 평가에서 인간보다 더 높은 정확도를 보이며 2018년 말 현재, 자연 언어 처리(NLP) AI의 최첨단 딥러닝 모델이다.
또한 BERT는 언어표현 사전학습의 새로운 방법으로 그 의미는 '큰 텍스트 코퍼스(Wikipedia와 같은)'를 이용하여 범용목적의 '언어 이해'(language understanding)' 모델을 훈련시키는 것과 그 모델에 관심 있는 실제의 자연 언어 처리 태스크(질문·응답 등)에 적용하는 것이다.
특히 BERT는 종래보다 우수한 성능을 발휘한다. BERT는 자연언어 처리 태스크를 교육 없이 양방향으로 사전학습하는 첫 시스템이기 때문이다. 교육 없음이란 BERT가 보통의 텍스트 코퍼스만을 이용해 훈련되고 있다는 것을 의미한다. 이것은 웹(Web) 상에서 막대한 양의 보통 텍스트 데이터가 여러 언어로 이용 가능하기 때문에 중요한 특징으로 꼽는다.
사전학습을 마친 특징 표현은 문맥에 '의존하는 방법'와 '의존하지 않는 방법'의 어느 방법도 있을 수 있다. 또 문맥에 의존하는 특징적인 표현은 단방향인 경우와 혹은 양방향일 경우가 있다. word2vec나 GloVe와 같이 문맥에 의존하지 않는 모델에서는, 어휘에 포함되는 각 단어마다 '단어 삽입(word embedding)'이라는 특징 표현을 생성한다. 따라서, 'bank'라는 단어는 'bank deposit' 또는 'river bank'과 같은 특징으로 표현되며, 문맥에 의존하는 모델에서는 문장에 포함되는 다른 단어를 바탕으로 각 단어의 특징을 표현 생성한다.
BERT는 문맥에 의존하는 특징적인 표현의 전학습을 실시하는 대응을 바탕으로 구축되었다. 그러한 대응은 Semi-supervised Sequence Learning, Generative Pre-Training, ELMo, 및 ULMFit를 포함하며, 대응에 의한 모델은 모두 단방향 혹은 얕은 양방향이다. 각 단어는 단지 그 왼쪽(혹은 오른쪽)에 존재하는 단어에 의해서만 문맥의 고려가 되는 것을 의미한다.
예를 들어, I made a bank deposit라는 문장은 bank의 단방향 특징표현은 단지 I made a만에 의해 결정되며, deposit은 고려되지 않는다. 몇개의 이전의 대응에서는 분리한 좌문맥모델과 우문맥모델에 의한 특징표현을 조합하고 있었지만, 이것은 얕은 양방향 방법이다. BERT는 bank를 왼쪽과 오른쪽 양쪽의 문맥 I made a ... deposit을 딥 뉴럴 네트워크(Deposit)의 최하층에서 이용해 특징을 표현하기 때문에 BERT는 '딥 양방향(deeply bidirectional)'이다.
BERT는 간단한 접근법을 사용한다. 입력에서 단어의 15%를 숨기고 딥 양방향 Transformer encoder(관련 논문다운)를 통해 전체 시퀀스를 실행한 다음 마스크 된 단어만 예측한다. 예를 들어, 아래와 같이 문간의 관계를 학습하기 위해서는 임의의 단언어 코퍼스에서 생성 가능한 심플한 작업을 이용하여 학습한다. A와 B의 두 개의 글을 받았을 때 B가 A의 뒤에 오는 실제 문장인지, 코퍼스 안의 랜덤한 글인지를 판정하는 태스크이다.
또한 큰 모델(12층에서 24층의 Transformer)을 큰 코퍼스(Wikipedia + BookCorpus)로 긴 시간을 들여(100만 갱신 스텝) 훈련했다. 그것이 BERT이며, 이용은 '사전학습'과 '전이학습'의 2단계로 구분된다.
사전학습(pre-training)은 상당히 고가로 4에서 16개의 Cloud TPU로 4일(12 층의 Transformer 모델의 경우 4개의 TPU를 사용하여 4일, 24층 Transformer 모델의 경우 16개의 TPU를 사용하여 4일이라는 의미) 각 언어마다 1회만의 순서이다. 자연 언어 처리 개발자는 처음부터 자신의 모델을 사전 학습할 필요가 없다.
전이학습(Fine-tuning)은 저렴하며, 논문(아래 참조)과 똑같은 사전학습이 끝난 모델을 사용하여 하나의 Cloud TPU를 이용, 1시간 GPU를 사용하면 2, 3시간만에 재현할 수 있다. 예를 들면 SQuAD는 하나의 Cloud TPU를 이용 30분으로 하나의 시스템으로서는 최첨단(state-of-the-art)인 91.0%의 Dev F1을 달성할 수 있다.
이밖에 BERT의 또 다른 중요한 측면은 많은 종류의 자연 언어 처치 태스크로 인해 매우 쉽게 채택될 수 있다. 논문 중에서 문장 수준 (SST-2 등), 문장 쌍 수준(MultiNLI 등), 단어 수준(NER 등) 스팬 레벨 2 (SQuAD 등)의 태스크에 대해서 거의 태스크 특유의 변경을 실시하는 일 없이, 최첨단 결과를 얻을 수 있는 것을 나타내고 있다.
참고) 'BERT: 언어 이해를 위한 양방향 트랜스포머 사전 학습(BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding)' 논문(다운받기), BERT Google-research의 깃허브(GitHub) (바로가기)
Capture ideas at the speed of thought:MindMup has powerful keyboard shortcuts to speed up your work, and the interface is optimised for frictionless work and designed to get out of your way.
Access your ideas from anywhere:Your mind maps are stored in Google's cloud infrastructure, so you can use them from any device and any location. The user interface adjusts automatically to screen sizes and input devices, so it will work great both on your desktop and on your mobile devices.
Add images easily: Easily insert images from Google Drive albums. If your mobile phone is synchronised with Google Drive, just snap, click, and they are in your mind map.
Do more with mind maps, faster
Capture ideas at the speed of thought:MindMup has powerful keyboard shortcuts to speed up your work, and the interface is optimised for frictionless work and designed to get out of your way.
Make slideshows and articles: If you plan presentations or prepare for writing using mind maps, MindMup will help you take your thoughts into aslideshowor adocument outlinequickly.
Access your ideas from anywhere:Your mind maps are available everywhere, instantly, from the cloud.
Connect team documents visually: link to other project documents on Google Drive easily, and you'll be able to preview them in the map and use the mindmap as a central overview of your work.
Great for teams and classrooms
Work safely and securely: All the data is stored on Google Drive, directly from the browser. The access is completely controlled by Google Apps authentication, so you can easily control who can read or modify the map. MindMup does not have any third-party ads and does not send any private information to third parties.
Easy to administer: Administrators can easily enable or block MindMup similar to any other Google Apps for Domains/Education application. Google authentication is used throughout the application, so there are no separate accounts to manage. The entire domain can easily be authorised for MindMup Gold.
Get started easily: The user interface is simple and intuitive, and even young students will be able to use it on their own without much help.
May contain one or more recognition hypotheses (up to the maximum specified inmax_alternatives). These alternatives are ordered in terms of accuracy, with the top (first) alternative being the most probable, as ranked by the recognizer.
is_final
bool
Iffalse, thisStreamingRecognitionResultrepresents an interim result that may change. Iftrue, this is the final time the speech service will return this particularStreamingRecognitionResult, the recognizer will not return any further hypotheses for this portion of the transcript and corresponding audio.
stability
float
An estimate of the likelihood that the recognizer will not change its guess about this interim result. Values range from 0.0 (completely unstable) to 1.0 (completely stable). This field is only provided for interim results (is_final=false). The default of 0.0 is a sentinel value indicatingstabilitywas not set.
Time offset of the end of this result relative to the beginning of the audio.
channel_tag
int32
For multi-channel audio, this is the channel number corresponding to the recognized result for the audio from that channel. For audio_channel_count = N, its output values can range from '1' to 'N'.
Encoding of audio data sent in allRecognitionAudiomessages. This field is optional forFLACandWAVaudio files and required for all other audio formats. For details, seeAudioEncoding.
sample_rate_hertz
int32
Sample rate in Hertz of the audio data sent in allRecognitionAudiomessages. Valid values are: 8000-48000. 16000 is optimal. For best results, set the sampling rate of the audio source to 16000 Hz. If that's not possible, use the native sample rate of the audio source (instead of re-sampling). This field is optional for FLAC and WAV audio files, but is required for all other audio formats. For details, seeAudioEncoding.
audio_channel_count
int32
The number of channels in the input audio data. ONLY set this for MULTI-CHANNEL recognition. Valid values for LINEAR16 and FLAC are1-8. Valid values for OGG_OPUS are '1'-'254'. Valid value for MULAW, AMR, AMR_WB and SPEEX_WITH_HEADER_BYTE is only1. If0or omitted, defaults to one channel (mono). Note: We only recognize the first channel by default. To perform independent recognition on each channel setenable_separate_recognition_per_channelto 'true'.
enable_separate_recognition_per_channel
bool
This needs to be set totrueexplicitly andaudio_channel_count> 1 to get each channel recognized separately. The recognition result will contain achannel_tagfield to state which channel that result belongs to. If this is not true, we will only recognize the first channel. The request is billed cumulatively for all channels recognized:audio_channel_countmultiplied by the length of the audio.
language_code
string
Required. The language of the supplied audio as aBCP-47language tag. Example: "en-US". SeeLanguage Supportfor a list of the currently supported language codes.
max_alternatives
int32
Maximum number of recognition hypotheses to be returned. Specifically, the maximum number ofSpeechRecognitionAlternativemessages within eachSpeechRecognitionResult. The server may return fewer thanmax_alternatives. Valid values are0-30. A value of0or1will return a maximum of one. If omitted, will return a maximum of one.
profanity_filter
bool
If set totrue, the server will attempt to filter out profanities, replacing all but the initial character in each filtered word with asterisks, e.g. "f***". If set tofalseor omitted, profanities won't be filtered out.
Array ofSpeechContext. A means to provide context to assist the speech recognition. For more information, seespeech adaptation.
enable_word_time_offsets
bool
Iftrue, the top result includes a list of words and the start and end time offsets (timestamps) for those words. Iffalse, no word-level time offset information is returned. The default isfalse.
enable_automatic_punctuation
bool
If 'true', adds punctuation to recognition result hypotheses. This feature is only available in select languages. Setting this for requests in other languages has no effect at all. The default 'false' value does not add punctuation to result hypotheses.
Config to enable speaker diarization and set additional parameters to make diarization better suited for your application. Note: When this is enabled, we send all the words from the beginning of the audio for the top alternative in every consecutive STREAMING responses. This is done in order to improve our speaker tags as our models learn to identify the speakers in the conversation over time. For non-streaming requests, the diarization results will be provided only in the top alternative of the FINAL SpeechRecognitionResult.
Which model to select for the given request. Select the model best suited to your domain to get best results. If a model is not explicitly specified, then we auto-select a model based on the parameters in the RecognitionConfig.
use_enhanced
bool
Set to true to use an enhanced model for speech recognition. Ifuse_enhancedis set to true and themodelfield is not set, then an appropriate enhanced model is chosen if an enhanced model exists for the audio.
Ifuse_enhancedis true and an enhanced version of the specified model does not exist, then the speech is recognized using the standard version of the specified model.
from google.cloud import speech
client = speech.SpeechClient()
with open(speech_file, "rb") as audio_file:
content = audio_file.read()
audio = speech.RecognitionAudio(content=content)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=44100,
language_code="en-US",
audio_channel_count=2,
enable_separate_recognition_per_channel=True,
)
response = client.recognize(config=config, audio=audio)
for i, result in enumerate(response.results):
alternative = result.alternatives[0]
print("-" * 20)
print("First alternative of result {}".format(i))
print(u"Transcript: {}".format(alternative.transcript))
print(u"Channel Tag: {}".format(result.channel_tag))