Files
MediaNCognition/hw4/report/main.tex
2024-05-27 00:01:48 +08:00

188 lines
5.9 KiB
TeX
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
% Homework template for Inference and Information
% UPDATE: September 26, 2017 by Xiangxiang
\documentclass[a4paper]{article}
\usepackage{ctex}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{moreenum}
\usepackage{mathtools}
\usepackage{url}
\usepackage{bm}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{color}
\usepackage{float}
\newfontfamily\codefont[Ligatures=ResetAll]{Fira Code}[Contextuals={Alternate}]
\newfontfamily\cascadia{Cascadia Code}
\lstset{
basicstyle = \small\codefont,
% ---
tabsize = 4,
showstringspaces = false,
numbers = left,
numberstyle = \codefont,
% ---
breaklines = true,
captionpos = t,
% ---
frame = l,
flexiblecolumns,
}
\lstdefinestyle{Python}{
language = Python, % 语言选Python
keywordstyle = \color{blue},
keywordstyle = [2] \color{teal},
stringstyle = \color{orange!80!black},
commentstyle = \color{red},
identifierstyle = \color{blue!80!white},
}
\lstdefinestyle{Bash}{
language = bash
}
\usepackage{subcaption}
\usepackage{booktabs} % toprule
\usepackage[mathcal]{eucal}
\usepackage[thehwcnt = 4]{iidef}
\thecourseinstitute{清华大学电子工程系}
\thecoursename{\textbf{媒体与认知}}
\theterm{2023-2024学年春季学期}
\hwname{作业}
\begin{document}
\courseheader
\name{高艺轩}
\vspace{3mm}
\centerline{\textbf{\Large{理论部分}}}
\section{单选题15分}
\subsection{\underline{D}}
\subsection{\underline{A}}
\subsection{\underline{A}}
\subsection{\underline{C}}
\subsection{\underline{B}}
\section{计算题15 分)}
% 计算题1
\subsection{隐含马尔可夫模型}
\hspace{2em}暑假中小E每天进行一项体育活动包括跑步R、游泳S和打球B所选择的体育活动受某种潜在因素如心情的影响。小E每天把进行体育活动的照片发至微信朋友圈我们可以根据观测信息推测该潜在因素的状态。
\hspace{2em}假设该潜在因素分为$S_1$$S_2$两种状态。在$S_1$小E选择三种体育活动的概率分别为0.60.20.2;在$S_2$小E选择三种体育活动的概率分别为0.10.60.3。
\hspace{2em}该潜在因素的变化也有一定规律,若某天处于$S_1$的状态,第二天处于$S_1$$S_2$的状态的概率分别为0.50.5;若某天处于$S_2$的状态,第二天处于$S_1$$S_2$的状态的概率分别为0.60.4。
\hspace{2em}暑假第一天处于$S_1$$S_2$的状态的概率均为0.5。
\vspace{3mm}
(1) 采用隐含马尔可夫模型(HMM)对小E暑假体育活动安排进行建模{\color{blue}请写出HMM对应的参数$\lambda=\{\pi, A, B\}$}
\begin{proof}[解]
\[\pi = \begin{bmatrix}
0.5\\0.5
\end{bmatrix}\]
\[A = \begin{bmatrix}
0.5 & 0.5\\
0.6 & 0.4\\
\end{bmatrix}\]
\[B = \begin{bmatrix}
0.6 & 0.2 & 0.2\\
0.1 & 0.6 & 0.3
\end{bmatrix}\]
\end{proof}
\vspace{3mm}
(2) 假设暑假第1、2、3天小E所进行的体育活动依次为跑步R、打球B和游泳S{\color{blue}请计算出现该观测序列的概率}
\begin{proof}[解]
\begin{align*}
\alpha_1(S_1) & = 0.5 \times 0.6 = 0.3\\
\alpha_1(S_2) & = 0.5 \times 0.1 = 0.05\\
\alpha_2(S_1) & = (\alpha_1(S_1) \times 0.5 + \alpha_1(S_2) \times 0.6) \times 0.2\\
& = 0.036\\
\alpha_2(S_2) & = (\alpha_1(S_1) \times 0.5 + \alpha_1(S_2) \times 0.4) \times 0.3\\
& = 0.051\\
\alpha_3(S_1) & = (\alpha_2(S_1) \times 0.5 + \alpha_2(S_2) \times 0.6) \times 0.2\\
& = 0.00972\\
\alpha_3(S_2) & = (\alpha_2(S_1) \times 0.5 + \alpha_2(S_2) \times 0.4) \times 0.6\\
& = 0.02304\\
P(O \mid \lambda) & = \alpha_3(S_1) + \alpha_3(S_2) = 0.03276\\
\end{align*}
\end{proof}
\vspace{3mm}
(3) 在(2)的条件下。{\color{blue}请利用Viterbi算法推测暑假第1、2、3天最可能的隐含状态序列}
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{img/20240526_155701910_iOS.png}
\end{figure}
% 请根据是否选择自选课题的情况选择“编程作业报告”或“自选课题开题报告”中的一项完成
\section{编程作业报告}
\subsection{模型的训练与测试}
首先进行数据预处理。预处理后进行模型训练,训练的结果见图\ref{fig:default_train}
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{img/train.png}
\caption{默认测试}
\label{fig:default_train}
\end{figure}
默认配置的生成样本:
\begin{lstlisting}
python sample.py --ckpt_path workdirs/quansongci
\end{lstlisting}
得到的输出为
\lstinputlisting{img/default_sample.txt}
若指定初始文本:
\begin{lstlisting}
python sample.py --ckpt_path workdirs/quansongci --start +++清平乐
\end{lstlisting}
得到的输出为
\lstinputlisting{img/specific_start_sample.txt}
\subsection{探究位置编码和残差链接在模型中的作用}
关闭位置编码的训练:
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{img/no_pos_train.png}
\end{figure}
得到的生成结果:
\lstinputlisting{img/no_pos_sample.txt}
可以看到,模型没有很好理解句子的长度的关系。
关闭残差连接的训练:
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{img/no_res_train.png}
\end{figure}
得到的生成结果:
\lstinputlisting{img/no_res_sample.txt}
模型训练遇到了梯度消失的问题,很难有效地训练。
\subsection{可视化}
\begin{figure}[H]
\centering
\includegraphics[width=.8\linewidth]{img/attention_vis.png}
\end{figure}
许多的词语的注意力系数都会集中在题目的几个字上,可以看到模型主要是分析了不同词牌名对内容的相关性。
\end{document}
%%% Local Variables:
%%% mode: late\rvx
%%% TeX-master: t
%%% End: