{ "cells": [ { "cell_type": "markdown", "id": "1526ab44-6369-42e8-bd50-7cc15001268e", "metadata": { "tags": [] }, "source": [ "# 1. As an example, there are about $3\\times 10^8$ possible 6-grams in English. What is the issue when there are too many subwords? How to address the issue? Hint: refer to the end of Section 3.2 of the fastText paper (Bojanowski et al., 2017)." ] }, { "cell_type": "markdown", "id": "97b8cac2-f5e9-4f40-96a3-2ff6792644eb", "metadata": {}, "source": [ "To address the issue, the fastText paper proposes to use a hashing function to map each subword to a fixed-size set of buckets, and use the bucket index as the input feature. This way, the dimensionality of the input matrix is reduced to the number of buckets, which is much smaller than the number of possible subwords. Furthermore, the paper suggests to use a hierarchical softmax function to speed up the output computation, and to use a sub-sampling scheme to discard the most frequent subwords, which are less informative" ] }, { "cell_type": "markdown", "id": "c2599bf7-a31f-4e74-b58f-461cbc34e63c", "metadata": {}, "source": [ "# 2. How to design a subword embedding model based on the continuous bag-of-words model?" ] }, { "cell_type": "markdown", "id": "3bd65093-f56b-4002-9760-45ab8038e807", "metadata": {}, "source": [ "Define a CBOW model that takes a sequence of context subwords as input, and outputs a probability distribution over the target subwords" ] }, { "cell_type": "markdown", "id": "c6bcc2e4-b947-431e-8067-97ff6f69e46b", "metadata": {}, "source": [ "# 3. To get a vocabulary of size m, how many merging operations are needed when the initial symbol vocabulary size is n?" ] }, { "cell_type": "markdown", "id": "9dccc7d2-ddaf-4873-a91f-1e5eb1d37ec6", "metadata": {}, "source": [ "n-m" ] }, { "cell_type": "markdown", "id": "d4172b0a-62dc-4f69-a72a-1edc40fec3d8", "metadata": {}, "source": [ "# 4. How to extend the idea of byte pair encoding to extract phrases?" ] }, { "cell_type": "markdown", "id": "0de9a8f9-5547-4939-8a0f-69ec0701ef35", "metadata": {}, "source": [ "To extend the idea of BPE to extract phrases, one possible approach is to apply BPE on the word level, rather than the character level. That is, instead of treating each character as a symbol, we can treat each word as a symbol, and merge the most frequent pair of words into a new phrase. This way, we can obtain a vocabulary of phrases that capture the collocations and idioms of the language." ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:d2l]", "language": "python", "name": "conda-env-d2l-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }