언어 모델은 더 긴 토큰 시퀀스 내에 토큰 또는 토큰 시퀀스가 발생할 확률을 추정합니다. 토큰은 단어, 하위 단어(단어의 하위 집합), 단일 문자일 수 있습니다.
아이콘을 클릭하여 토큰에 대해 자세히 알아보세요.
대부분의 최신 언어 모델은 하위 단어, 즉 의미론적 의미가 포함된 텍스트 청크를 기준으로 토큰화합니다. 청크의 길이는 구두점이나 소유격 s와 같은 단일 문자에서 전체 단어까지 다양할 수 있습니다. 접두사와 접미어는 별도의 하위 단어로 표시될 수 있습니다. 예를 들어 unwatched라는 단어는 다음 세 가지 하위 단어로 표현할 수 있습니다.
un (접두사)
watch(루트)
ed (접미사)
고양이라는 단어는 다음의 두 하위 단어로 표현할 수 있습니다.
cat (루트)
s (접미사)
'antidisestablishmentarianism'과 같이 더 복잡한 단어는 다음과 같은 6개의 하위 단어로 표현될 수 있습니다.
안티
dis
설정
멘트
아리안
이즘
토큰화는 언어별로 수행되므로 토큰당 문자 수는 언어마다 다릅니다 영어의 경우 토큰 1개는 약 4자 또는 단어의 약 3/4에 해당하므로 토큰 400개는 영어 단어 300개에 해당합니다.
토큰은 언어 모델링의 원자 단위 또는 가장 작은 단위입니다.
이제 토큰도 <ph type="x-smartling-placeholder"></ph> 컴퓨터 비전과 <ph type="x-smartling-placeholder"></ph> 오디오 생성을 해야 합니다.
다음 문장과 이 문장을 완성할 수 있는 토큰을 생각해 보세요.
When I hear rain on my roof, I _______ in my kitchen.
언어 모델은 빈칸을 채우는 데 사용될 수 있는 다양한 토큰 또는 토큰 시퀀스의 확률을 결정합니다. 예를 들어 확률 테이블은 가능한 토큰과 그 확률을 식별합니다.
확률
토큰
9.4%
수프 요리
5.2%
주전자를 데우기
3.6%
몸을 움츠리다
2.5%
낮잠
2.2%
휴식
어떤 상황에서는 토큰의 시퀀스가 한 문장의 전체 문장이 될 수 있습니다. 단락 또는 에세이 전체의 내용이 포함됩니다.
애플리케이션은 확률 표를 사용하여 예측할 수 있습니다. 예측은 가장 높은 확률(예: 'cook soup')일 수도 있고 특정 임곗값보다 높은 확률을 가진 토큰 중에서 무작위로 선택된 토큰일 수도 있습니다.
텍스트 시퀀스에서 빈칸을 채울 확률을 추정하면 다음과 같은 보다 복잡한 작업으로도 확장됩니다.
텍스트를 생성하는 중입니다.
텍스트를 한 언어에서 다른 언어로 번역
문서 요약
토큰의 통계적 패턴을 모델링함으로써 최신 언어 모델은 매우 강력한 언어 내부 표현을 생성하고 이를 통해 있습니다.
N-gram 언어 모델
N-그램은 언어 모델을 만드는 데 사용되는 단어의 순서가 지정된 시퀀스입니다. 여기서 N은 시퀀스의 단어 수입니다. 예를 들어 N이 2인 경우 N-그램은 2-그램(또는 빅그램)이라고 합니다. N이 5인 경우 N-그램은 5-그램이라고 합니다. 학습 문서에 다음과 같은 문구가 있습니다.
you are very nice
그 결과 2-그램은 다음과 같습니다.
나는
매우
대단하다
N이 3인 경우 N-그램을 3-그램(또는 트라이그램)이라고 합니다. 같은 구문에서 결과 3-그램은 다음과 같습니다.
넌 정말
진짜 친절해
두 단어가 입력으로 주어지면 3-그램을 기반으로 하는 언어 모델은 확률을 평가합니다. 예를 들어 다음 두 단어가 있다고 가정해 보겠습니다.
orange is
언어 모델은 학습에서 파생된 다양한 3-그램을 모두 검사함 orange is로 시작하는 코퍼스의 조합을 사용하여 가능성이 가장 높은 세 번째 단어를 결정합니다. 수백 개의 3-그램이 orange is라는 두 단어로 시작할 수 있지만, 다음 두 가지 가능성에만 집중하세요.
orange is ripe orange is cheerful
첫 번째 가능성 (orange is ripe)은 과일 주황색에 관한 것이고 두 번째 가능성 (orange is cheerful)은 색상에 관한 것입니다. 주황색입니다.
컨텍스트
인간은 비교적 긴 맥락을 유지할 수 있습니다. 연극의 3막을 시청하는 동안 1막에서 소개된 캐릭터에 관한 지식을 유지합니다. 마찬가지로 장황한 농담을 보내면 맥락을 기억할 수 있어 웃음을 자아냅니다. 장난이 아니더라도 말이죠.
언어 모델에서는 컨텍스트가 대상 토큰입니다. 컨텍스트는 언어 모델이 '주황색'인지 여부를 판단하는 데 감귤류 과일 또는 색상을 나타냅니다.
문맥은 언어 모델이 더 나은 예측을 하는 데 도움이 될 수 있지만 3-gram은 충분한 문맥을 제공하나요? 안타깝게도 3-그램의 유일한 컨텍스트는 첫 두 단어입니다 예를 들어 orange is라는 두 단어는 언어 모델이 세 번째 단어를 예측하기에 충분한 컨텍스트를 제공하지 않습니다. 3-그램을 기반으로 하는 언어 모델은 컨텍스트의 부족으로 인해 많은 실수를 합니다.
긴 N-그램은 짧은 N-그램보다 더 많은 맥락을 제공합니다. 그러나 N이 커질수록 각 인스턴스의 상대적 발생 횟수는 감소합니다. N이 매우 커지면 언어 모델에는 일반적으로 N 토큰이 각 발생마다 단일 인스턴스만 있으므로 타겟 토큰을 예측하는 데 큰 도움이 되지 않습니다.
순환 신경망(RNN)
순환 신경망은 N-그램보다 더 많은 컨텍스트를 제공합니다. 순환 신경망은 신경망의 학습합니다. 예를 들어 순환 신경망은 각 단어에서 선택된 컨텍스트를 점진적으로 학습하고 이를 무시하는 방법을 학습하게 됨 문장을 만듭니다. 대규모 순환 신경망은 여러 개의 문장에서 컨텍스트를 획득할 수 있음 학습합니다.
순환 신경망은 N-그램보다 더 많은 컨텍스트를 학습하지만 반복 신경망이 직관적으로 이해할 수 있는 것은 제한됩니다. 순환 신경망은 '토큰별로' 정보를 평가합니다. 이와 대조적으로 대규모 언어 모델은 섹션 - 전체 맥락을 한 번에 평가할 수 있습니다.
긴 컨텍스트에 대해 순환 신경망을 학습시키는 것은 소실 경사 문제에 대해 자세히 알아보세요.
연습문제: 학습 내용 점검하기
영어 텍스트에 대한 예측이 더 정확한 언어 모델은 무엇인가요?
6-그램을 기반으로 하는 언어 모델
5-그램을 기반으로 하는 언어 모델
답은 학습 세트의 크기와 다양성에 따라 다릅니다.
학습 세트에 수백만 개의 다양한 문서에 걸쳐 있는 경우 6-그램을 기반으로 하는 모델은 아마도 모델보다 5그램을 기준으로 합니다.
6-그램을 기반으로 하는 언어 모델입니다.
이 언어 모델은 더 많은 컨텍스트를 보유하고 있지만, 이 모델이 많은 문서를 기반으로 학습하지 않는 한 대부분의 6그램은 드물게 사용됩니다.
5-그램을 기반으로 한 언어 모델입니다.
이 언어 모델은 컨텍스트가 적기 때문에 6-그램 기반으로 언어 모델보다 우수한 성능을 보였습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[[["\u003cp\u003eThis module explores language models, which estimate the probability of a token or sequence of tokens occurring within a longer sequence, enabling tasks like text generation, translation, and summarization.\u003c/p\u003e\n"],["\u003cp\u003eLanguage models utilize context, the surrounding information of a target token, to enhance prediction accuracy, with recurrent neural networks offering more context than traditional N-grams.\u003c/p\u003e\n"],["\u003cp\u003eN-grams are ordered sequences of words used to build language models, with longer N-grams providing more context but potentially encountering sparsity issues.\u003c/p\u003e\n"],["\u003cp\u003eTokens, the atomic units of language modeling, represent words, subwords, or characters and are crucial for understanding and processing language.\u003c/p\u003e\n"],["\u003cp\u003eWhile recurrent neural networks improve context understanding compared to N-grams, they have limitations, paving the way for the emergence of large language models that evaluate the whole context simultaneously.\u003c/p\u003e\n"]]],[],null,["| **Estimated module length:** 45 minutes\n| **Learning objectives**\n|\n| - Define a few different types of language models and their components.\n| - Describe how large language models are created and the importance of context and parameters.\n| - Identify how large language models take advantage of self-attention.\n| - Reveal three key problems with large language models.\n| - Explain how fine-tuning and distillation can improve a model's predictions and efficiency.\n| **Prerequisites:**\n|\n| This module assumes you are familiar with the concepts covered in the\n| following modules:\n|\n| - [Introduction to Machine Learning](/machine-learning/intro-to-ml)\n| - [Linear regression](/machine-learning/crash-course/linear-regression)\n| - [Working with categorical data](/machine-learning/crash-course/categorical-data)\n| - [Datasets, generalization, and overfitting](/machine-learning/crash-course/overfitting)\n| - [Neural networks](/machine-learning/crash-course/neural-networks)\n| - [Embeddings](/machine-learning/crash-course/embeddings)\n\nWhat is a language model?\n\nA [**language model**](/machine-learning/glossary#language-model)\nestimates the probability of a [**token**](/machine-learning/glossary#token)\nor sequence of tokens occurring within a longer sequence of tokens. A token\ncould be a word, a subword (a subset of a word), or even a single character.\n\nClick the icon to learn more about tokens. \nMost modern language models tokenize by subwords, that is, by chunks of\ntext containing semantic meaning. The chunks could vary in length from\nsingle characters like punctuation or the possessive *s* to whole words.\nPrefixes and suffixes might be represented as separate subwords.\nFor example, the word *unwatched* might be represented by the following\nthree subwords:\n\n- un (the prefix)\n- watch (the root)\n- ed (the suffix)\n\nThe word *cats* might be represented by the following two subwords:\n\n- cat (the root)\n- s (the suffix)\n\nA more complex word like \"antidisestablishmentarianism\" might be represented\nas six subwords:\n\n- anti\n- dis\n- establish\n- ment\n- arian\n- ism\n\nTokenization is language specific, so the number of characters per token\ndiffers across languages. For English, one token corresponds to \\~4 characters\nor about 3/4 of a word, so 400 tokens \\~= 300 English words.\n\nTokens are the atomic unit or smallest unit of language modeling.\n\nTokens are now also being successfully applied to\n[computer vision](https://ai.googleblog.com/2023/03/scaling-vision-transformers-to-22.html) and\n[audio generation](https://ai.googleblog.com/2022/10/audiolm-language-modeling-approach-to.html).\n\nConsider the following sentence and the token(s) that might complete it: \n\n```\nWhen I hear rain on my roof, I _______ in my kitchen.\n```\n\nA language model determines the probabilities of different tokens or\nsequences of tokens to complete that blank. For example, the following\nprobability table identifies some possible tokens and their probabilities:\n\n| Probability | Token(s) |\n|-------------|------------------|\n| 9.4% | cook soup |\n| 5.2% | warm up a kettle |\n| 3.6% | cower |\n| 2.5% | nap |\n| 2.2% | relax |\n\nIn some situations, the sequence of tokens could be an entire sentence,\nparagraph, or even an entire essay.\n\nAn application can use the probability table to make predictions.\nThe prediction might be the highest probability (for example, \"cook soup\")\nor a random selection from tokens having a probability greater than a certain\nthreshold.\n\nEstimating the probability of what fills in the blank in a text sequence can\nbe extended to more complex tasks, including:\n\n- Generating text.\n- Translating text from one language to another.\n- Summarizing documents.\n\nBy modeling the statistical patterns of tokens, modern language models develop\nextremely powerful internal representations of language and can generate\nplausible language.\n\nN-gram language models\n\n[**N-grams**](/machine-learning/glossary#n-gram) are ordered sequences of words\nused to build language models, where N is the number of words in the sequence.\nFor example, when N is 2, the N-gram is called a **2-gram** (or a\n[**bigram**](/machine-learning/glossary#bigram)); when N is 5, the N-gram is\ncalled a 5-gram. Given the following phrase in a training document: \n\n```\nyou are very nice\n```\n\nThe resulting 2-grams are as follows:\n\n- you are\n- are very\n- very nice\n\nWhen N is 3, the N-gram is called a **3-gram** (or a\n[**trigram**](/machine-learning/glossary#trigram)). Given that same phrase, the\nresulting 3-grams are:\n\n- you are very\n- are very nice\n\nGiven two words as input, a language model based on 3-grams can predict the\nlikelihood of the third word. For example, given the following two words: \n\n```\norange is\n```\n\nA language model examines all the different 3-grams derived from its training\ncorpus that start with `orange is` to determine the most likely third word.\nHundreds of 3-grams could start with the two words `orange is`, but you can\nfocus solely on the following two possibilities: \n\n```\norange is ripe\norange is cheerful\n```\n\nThe first possibility (`orange is ripe`) is about orange the fruit,\nwhile the second possibility (`orange is cheerful`) is about the color\norange.\n\nContext\n\nHumans can retain relatively long contexts. While watching Act 3 of a play, you\nretain knowledge of characters introduced in Act 1. Similarly, the\npunchline of a long joke makes you laugh because you can remember the context\nfrom the joke's setup.\n\nIn language models, **context** is helpful information before or after the\ntarget token. Context can help a language model determine whether \"orange\"\nrefers to a citrus fruit or a color.\n\nContext can help a language model make better predictions, but does a\n3-gram provide sufficient context? Unfortunately, the only context a 3-gram\nprovides is the first two words. For example, the two words `orange is` doesn't\nprovide enough context for the language model to predict the third word.\nDue to lack of context, language models based on 3-grams make a lot of mistakes.\n\nLonger N-grams would certainly provide more context than shorter N-grams.\nHowever, as N grows, the relative occurrence of each instance decreases.\nWhen N becomes very large, the language model typically has only a single\ninstance of each occurrence of N tokens, which isn't very helpful in\npredicting the target token.\n\nRecurrent neural networks\n\n[**Recurrent neural\nnetworks**](/machine-learning/glossary#recurrent-neural-network)\nprovide more context than N-grams. A recurrent neural network is a type of\n[**neural network**](/machine-learning/glossary#neural-network) that trains on\na sequence of tokens. For example, a recurrent neural network\ncan *gradually* learn (and learn to ignore) selected context from each word\nin a sentence, kind of like you would when listening to someone speak.\nA large recurrent neural network can gain context from a passage of several\nsentences.\n\nAlthough recurrent neural networks learn more context than N-grams, the amount\nof useful context recurrent neural networks can intuit is still relatively\nlimited. Recurrent neural networks evaluate information \"token by token.\"\nIn contrast, large language models---the topic of the next\nsection---can evaluate the whole context at once.\n\nNote that training recurrent neural networks for long contexts is constrained by\nthe [**vanishing gradient\nproblem**](/machine-learning/glossary#vanishing-gradient-problem).\n\nExercise: Check your understanding \nWhich language model makes better predictions for English text?\n\n- A language model based on 6-grams\n- A language model based on 5-grams \nThe answer depends on the size and diversity of the training set. \nIf the training set spans millions of diverse documents, then the model based on 6-grams will probably outperform the model based on 5-grams. \nThe language model based on 6-grams. \nThis language model has more context, but unless this model has trained on a lot of documents, most of the 6-grams will be rare. \nThe language model based on 5-grams. \nThis language model has less context, so it is unlikely to outperform the language model based on 6-grams.\n| **Key terms:**\n|\n| - [Bigram](/machine-learning/glossary#bigram)\n| - [Language model](/machine-learning/glossary#language-model)\n| - [N-gram](/machine-learning/glossary#n-gram)\n| - [Neural network](/machine-learning/glossary#neural-network)\n| - [Recurrent neural network](/machine-learning/glossary#recurrent-neural-network)\n| - [Token](/machine-learning/glossary#token)\n| - [Trigram](/machine-learning/glossary#trigram)\n- [Vanishing gradient problem](/machine-learning/glossary#vanishing-gradient-problem) \n[Help Center](https://support.google.com/machinelearningeducation)"]]