## 机器学习代考_Machine Learning代考_Positional encoding

The performance of “vanilla” self-attention can be low, since attention is permutation invariant, and hence ignores the input word ordering. To overcome this, we can concatenate the word embeddings with a positional embedding, so that the model knows what order the words oocur in.

One way to do this is to represent each position by an integer. However, neural networks cannot natively handle integers. To overcome this, we can encode the integer in binary form. For example, if we assume the sequence length is $n=3$, we get the following sequence of $d=3$-dimensional bit vectors for each location: $000,001,010,011,100,101,110,111$. We see that the right most index toggles the fastest (has highest frequency), whereas the left most index (most significant bit) toggles the slowest. (We could of course change this, so that the left most bit toggles fastest.) We can represent this as a position matrix $\mathbf{P} \in \mathbb{R}^{n \times d}$.

We can think of the above representation as using a set of basis functions (corresponding to powers of 2), where the coefficients are 0 or 1 . We can obtain a more compact code by using a different set of basis functions, and real-valued weights. [Vas $+17$ ] propose to use a sinusoidal basis, as follows:
$$p_{i, 2 j}=\sin \left(\frac{i}{C^{2 j / d}}\right), p_{i, 2 j+1}=\cos \left(\frac{i}{C^{2 j / d}}\right)$$
where $C=10,000$ corresponds to some maximum sequence length. For example, if $d=4$, the $i$ ‘t row is
$$\boldsymbol{p}_i=\left[\sin \left(\frac{i}{C^{0 / 4}}\right), \cos \left(\frac{i}{C^{0 / 4}}\right), \sin \left(\frac{i}{C^{2 / 4}}\right), \cos \left(\frac{i}{C^{2 / 4}}\right)\right]$$
Figure $15.25$ a shows the corresponding position matrix for $n=60$ and $d=32$. In this case, the left-most columns toggle fastest. We see that each row has a real-valued “fingerprint” representing its location in the sequence. Figure $15.25$ b shows some of the basis functions (column vectors) for dimensions 6 to 9.

The advantage of this representation is two-fold. First, it can be computed for arbitrary length inputs (up to $T \leq C$ ), unlike a learned mapping from integers to vectors. Second, the representation of one location is linearly predictable from any other, given knowledge of their relative distance.

## 机器学习代考_Machine Learning代考_Transformers for images

CNNs (Chapter 14) are the most common model type for processing image data, since they have useful built-in inductive bias, such as locality (due to small kernels), equivariance (due to weight tying), and invariance (due to pooling). Suprisingly, it has been found that transformers can also do well at image classification, at least if trained on enough data. (They need a lot of data to overcome their lack of relevant inductive bias.)

In particular, [Dos+21] present the ViT model (vision transformer), that chops the input up into $16 \times 16$ patches, projects each patch into an embedding space, and then passes this set of embeddings $\boldsymbol{x}{1: T}$ to a transformer, analogous to the way word embeddings are passed to a transformer. The input is also prepended with a special [CLASS] embedding, $\boldsymbol{x}_0$. The output of the transformer is a set of encodings $\boldsymbol{e}{0: T}$; the model maps $\boldsymbol{e}_0$ to the target class label $y$, and is trained in a supervised way. See Figure $15.28$ for an illustration.

After supervised pretraining, the model is fine-tuned on various downstream classification tasks, an approach known as transfer learning (seee Section $19.2$ for more details). When trainéd on “small” datasets such as ImageNet (which has $1 \mathrm{k}$ classes and $1.3 \mathrm{M}$ images), they find that they cannot outperform a pretrained CNN ResNet model (Section 14.3.4) known as BiT (big transfer) $[$ Kol $+20 \mid$. However, when trained on larger datasets, such as ImageNet-21k (with $21 \mathrm{k}$ classes and $14 \mathrm{M}$ images), or the Google-internal JFT dataset (with $18 \mathrm{k}$ classes and 303M images), they find that ViT does better than BiT at transfer learning. It is also cheaper to train than ResNet at this scale. (However, training is still expensive: the large ViT model on ImageNet-21k takes 30 days on a Google Cloud TPUv3 with 8 cores!)

# 机器学习代考

## 机器学习代考_Machine Learning代考_Positional encoding

“vanilla”自注意力的性能可能很低，因为注意力是排列不变的，因此忽略了输入词的顺序。为了克服这个 问题，我们可以将单词嵌入与位置嵌入连接起来，这样模型就知道单词出现的顺序。

$$p_{i, 2 j}=\sin \left(\frac{i}{C^{2 j / d}}\right), p_{i, 2 j+1}=\cos \left(\frac{i}{C^{2 j / d}}\right)$$

$$\boldsymbol{p}_i=\left[\sin \left(\frac{i}{C^{0 / 4}}\right), \cos \left(\frac{i}{C^{0 / 4}}\right), \sin \left(\frac{i}{C^{2 / 4}}\right), \cos \left(\frac{i}{C^{2 / 4}}\right)\right]$$

## 机器学习代考_Machine Learning代考_Transformers for images

CNN (第 14 章) 是处理图像数据的最常见模型类型，因为它们具有有用的内置归纳偏置，例如局部性 (由于小内核) 、等方差 (由于权重绑定) 和不变性 (由于池化) ). 令人惊讶的是，已经发现 transformer 在图像分类方面也能做得很好，至少在对足够的数据进行训练的情况下是这样。（他们需要 大量数据来克服相关归纳偏差的缺乏。）

myassignments-help数学代考价格说明

1、客户需提供物理代考的网址，相关账户，以及课程名称，Textbook等相关资料~客服会根据作业数量和持续时间给您定价~使收费透明，让您清楚的知道您的钱花在什么地方。

2、数学代写一般每篇报价约为600—1000rmb，费用根据持续时间、周作业量、成绩要求有所浮动(持续时间越长约便宜、周作业量越多约贵、成绩要求越高越贵)，报价后价格觉得合适，可以先付一周的款，我们帮你试做，满意后再继续，遇到Fail全额退款。

3、myassignments-help公司所有MATH作业代写服务支持付半款，全款，周付款，周付款一方面方便大家查阅自己的分数，一方面也方便大家资金周转，注意:每周固定周一时先预付下周的定金，不付定金不予继续做。物理代写一次性付清打9.5折。

Math作业代写、数学代写常见问题

myassignments-help擅长领域包含但不是全部: