1
【1】卷积神经网络是一类典型的处理图像的模型,其中卷积是其中一种非常重要的函数操作。试计算下列输入和卷积核做卷积的结果。(注意:此处卷积操作无需旋转180度)
\[
\mathrm {I n p u t} = \left( \begin{array}{c c c c} 1 & 3 & 0 & - 1 \\ 3 & 0 & - 1 & 2 \\ 1 & - 1 & 2 & 0 \end{array} \right), \mathrm {K e r n e l} = \left( \begin{array}{c c} - 1 & 1 \\ - 1 & 1 \end{array} \right)
\]
由卷积运算公式可知
\[
o u t p u t _ {1 1} = 1 \cdot (- 1) + 3 \cdot 1 + 3 \cdot (- 1) + 0 \cdot 1 = - 1
\]
\[
o u t p u t _ {1 2} = 3 \cdot (- 1) + 0 \cdot 1 + 0 \cdot (- 1) + (- 1) \cdot 1 = - 4
\]
\[
o u t p u t _ {1 3} = 0 \cdot (- 1) + (- 1) \cdot 1 + (- 1) \cdot (- 1) + 2 \cdot 1 = 2
\]
\[
o u t p u t _ {2 1} = 3 \cdot (- 1) + 0 \cdot 1 + 1 \cdot (- 1) + (- 1) \cdot 1 = - 5
\]
\[
o u t p u t _ {2 2} = 0 \cdot (- 1) + (- 1) \cdot 1 + (- 1) \cdot (- 1) + 2 \cdot 1 = 2
\]
\[
o u t p u t _ {2 3} = (- 1) \cdot (- 1) + 2 \cdot 1 + 2 \cdot (- 1) + 0 \cdot 1 = 1
\]
\[
\text {Output} = \left( \begin{array}{c c c} - 1 & - 4 & 2 \\ - 5 & 2 & 1 \end{array} \right)
\]
【2】现有一组图片数据集,任务目标是将这些图片分类。其中图片中包含的类别有:猫、狗、鹦鹉、人。试用One-Hot向量将类别表示为向量。
【3】现有文本集(一行为一个文本)如下。试计算,该文本集中各个单词(不区分大小写)在各文本中的TF-IDF值。
I know.
You know.
I know that you know.
I know that you know that I know.
【4】现有一个数据集有5个数据,分别被分类在 \(( 0 , 1 ) ^ { T } , ( 0 , 1 ) ^ { T } , ( 0 , 1 ) ^ { T } , ( 1 , 0 ) ^ { T } , ( 1 , 0 ) ^ { T }\) ,而一个模型给出的评分分别为 \(( 2 , 8 ) ^ { T } , ( 1 , 9 ) ^ { T } , ( 3 , 2 ) ^ { T } , ( 1 , 5 ) ^ { T } , ( 2 , 0 ) ^ { T }\) ,试给出此时模型给各个数据的概率评分以及交叉熵损失的值。
由
\[
\operatorname {S o f t m a x} \left(x _ {i}\right) = \frac {e ^ {x _ {i}}}{\sum_ {j = 1} ^ {n} e ^ {x _ {j}}}
\]
可知各个数据的概率评分为
\[
\begin{array}{l} \left( \begin{array}{c} e ^ {2} / (e ^ {2} + e ^ {8}) \\ e ^ {8} / (e ^ {2} + e ^ {8}) \end{array} \right), \left( \begin{array}{c} e ^ {1} / (e ^ {1} + e ^ {9}) \\ e ^ {9} / (e ^ {1} + e ^ {9}) \end{array} \right), \left( \begin{array}{c} e ^ {3} / (e ^ {3} + e ^ {2}) \\ e ^ {2} / (e ^ {3} + e ^ {2}) \end{array} \right), \left( \begin{array}{c} e ^ {1} / (e ^ {1} + e ^ {5}) \\ e ^ {5} / (e ^ {1} + e ^ {5}) \end{array} \right), \left( \begin{array}{c} e ^ {2} / (e ^ {2} + e ^ {0}) \\ e ^ {0} / (e ^ {2} + e ^ {0}) \end{array} \right) \\ \approx \left( \begin{array}{c} 0. 0 0 2 5 \\ 0. 9 9 7 5 \end{array} \right), \left( \begin{array}{c} 0. 0 0 0 3 \\ 0. 9 9 9 7 \end{array} \right), \left( \begin{array}{c} 0. 7 3 1 1 \\ 0. 2 6 8 9 \end{array} \right), \left( \begin{array}{c} 0. 0 1 8 0 \\ 0. 9 8 2 0 \end{array} \right), \left( \begin{array}{c} 0. 8 8 0 8 \\ 0. 1 1 9 2 \end{array} \right) \\ \end{array}
\]
又由交叉熵损失计算公式
\[
L = - \sum_ {c = 1} ^ {K} y _ {c} \log (p _ {c})
\]
可知各个数据的交叉熵损失为
\[
L _ {1} = - (0 \cdot \log 0. 0 0 2 5 + 1 \cdot \log 0. 9 9 7 5) \approx 0. 0 0 3 6
\]
\[
L _ {2} = - (0 \cdot \log 0. 0 0 0 3 + 1 \cdot \log 0. 9 9 9 7) \approx 0. 0 0 0 4
\]
\[
L _ {3} = - (0 \cdot \log 0. 7 3 1 1 + 1 \cdot \log 0. 2 6 8 9) \approx 1. 8 9 4 9
\]
\[
L _ {4} = - (1 \cdot \log 0. 0 1 8 0 + 0 \cdot \log 0. 9 8 2 0) \approx 5. 7 9 5 9
\]
\[
L _ {5} = - (1 \cdot \log 0. 8 8 0 8 + 0 \cdot \log 0. 1 1 9 2) \approx 0. 1 8 3 1
\]
【5】设数据集为 \(x _ { 1 } , x _ { 2 } , \cdots , x _ { n }\) 其中被分为两类 \(y _ { 1 } , y _ { 2 }\) 。如果使用线性分类器,试给出一个考虑结构风险的损失函数的公式。
【6】利用Python将一张黑白图片或彩色图片转化为矩阵或张量,并使图片水平翻转。
原图:

翻转后:
