워드 임베딩은 마술이다

hackernews | | 📦 오픈소스
#하드웨어/반도체
원문 출처: hackernews · Genesis Park에서 요약 및 분석

요약

컴퓨터가 언어를 이해하는 원리인 워드 임베딩은 단어 간의 관계를 학습하는 방식입니다. 예를 들어, 모델은 '신용(credit)'이라는 단어 주변에 '카드(card)'가 나올 확률을 예측하도록 훈련됩니다. 이 과정을 통해 컴퓨터는 왕-남자+여자=여왕과 같은 의미적 연결을 파악할 수 있게 됩니다.

본문

Word Embedding is Magic! Word embedding is a magic trick that allows computers to understand language. I've used word embedding models without fully understanding how they work. To scratch this itch, I looked deeper and found one of the most profound inventions, at least to my eyes. It is like magic. How can a computer understand language? I keep seeing this king - man + woman = queen example everywhere. But how does a computer get to discern this? It turns out, it can't. But it can approximate it. We train a model to predict nearby words. Given "credit", the model tries to predict "card". But here's the thing, nobody actually cares about this prediction task. We want the model to understand language, and essentially, the relationship between these two words. So that, at the end of the day, it can do this king - man + woman = queen . We train the model on a task we intend to fail at (or at least, a task we don't plan to use) I'm not going to go in-depth about how word2vec actually works. There are fantastic resources around this. I am just going to talk about the interesting idea that made this possible. If we can somehow represent words as vectors, then we can project them into a multidimensional space and find ways to optimize the distance between two similar words. So it starts with this, how do we represent words as vectors? A one-hot encoded vector is a "dumb" array of zeros and a single one. We can represent words as one-hot encoded vectors. When this one-hot vector is multiplied by a weight matrix, the operation simply selects a row from that matrix. That row is the word's embedding. The "Lookup Table" Trick Click a word to see how the one-hot input isolates a specific row in the hidden layer weights ($W_1$). Now, the fake task given to the network is "Given this word X, what is the probability that word Y is located nearby?" If the model sees "coffee" and "starbucks" together often, it tries to minimize the error in predicting one from the other. The magic happens in the hidden layer. To succeed at the "fake" task, the model is forced to learn compressed, mathematical representations of words. To solve the prediction, the data must pass through a narrow hidden layer (e.g. 300 neurons). Because the layer is narrow, the model is forced to compress the word's identity into a dense vector of numbers. If "intelligent" and "smart" appear in similar contexts, the network realizes it can "save space" and increase accuracy by giving them similar internal scores. These internal scores are the weights of the hidden layer, and these weights are the embeddings. During training, the model adjusts this matrix to improve its ability to predict nearby words. Finally, here's the trick. The prediction task is not the goal. It's a constraint. It forces the model to learn structure and relationships. We don't actually care about the network's ability to predict nearby words. Once the training is over, we typically delete the output layer entirely. We only keep the Weight Matrix, which has become a lookup table of embeddings. This matrix acts as the "brain" that now understands language. Word2Vec intuition A proxy task creates a real embedding Word2Vec predicts nearby words during training, but the prediction is not the thing we keep. The useful artifact is the row learned inside the first weight matrix. The proxy task The task is a training signal. It forces the model to organize words by the company they keep. It is a form of Self-Supervised Learning. We don't need humans to label data. The "fake task" uses the natural structure of language as its own label. It allows the model to "accidentally" learn human semantics, like the famous relationship king - man + woman = queen . As someone working with sequence models and time-series, I've started to see the same pattern everywhere. The loss function is rarely the end goal. It's a tool to shape the representation. This same trick appears elsewhere in ML as well, such as in Autoencoders .

Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.

공유

관련 저널 읽기

전체 보기 →