<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sentiment Analysis | Ziyang Lin</title><link>https://ziyanglin.netlify.app/en/categories/sentiment-analysis/</link><atom:link href="https://ziyanglin.netlify.app/en/categories/sentiment-analysis/index.xml" rel="self" type="application/rss+xml"/><description>Sentiment Analysis</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Mon, 27 Jul 2020 04:56:23 +0100</lastBuildDate><image><url>https://ziyanglin.netlify.app/img/icon-192.png</url><title>Sentiment Analysis</title><link>https://ziyanglin.netlify.app/en/categories/sentiment-analysis/</link></image><item><title>2020 Assessing the Funniness of Edited News Headlines</title><link>https://ziyanglin.netlify.app/en/project/my2020_nlp_funniness_estimation/</link><pubDate>Mon, 27 Jul 2020 04:56:23 +0100</pubDate><guid>https://ziyanglin.netlify.app/en/project/my2020_nlp_funniness_estimation/</guid><description>&lt;p>This project aims to develop potential solutions for the tasks rised by the competition
&lt;a href="https://competitions.codalab.org/competitions/20970#learn_the_details" title="competition">&lt;code>Assessing the Funniness of Edited News Headlines (SemEval-2020)&lt;/code>&lt;/a> on the platform &lt;a href="https://competitions.codalab.org" title="competition">CodaLab&lt;/a>&lt;/p>
&lt;p>As of July 26, 2020, the test result of my trained model (&amp;lsquo;bert-base-uncased&amp;rsquo; from the &lt;a href="https://huggingface.co/transformers/index.html" title="huggingface">Huggingface transformers&lt;/a>) &lt;code>ranked third&lt;/code> in the ranking of
Post Evaluation Task 1 on the CodaLab&lt;/p>
&lt;p align="center">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/task1_ranking.png" width="600" />
&lt;/p>
&lt;hr>
&lt;h2 id="contents">Contents&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="#tasks-description">Tasks Description&lt;/a>&lt;/li>
&lt;li>&lt;a href="#data-preprocessing">Data Preprocessing&lt;/a>&lt;/li>
&lt;li>&lt;a href="#models-choices--design">Models Choices &amp;amp; Design&lt;/a>&lt;/li>
&lt;li>&lt;a href="#design-of-training-processes-for-task-two-only">Design of Training Processes (for task two only)&lt;/a>&lt;/li>
&lt;li>&lt;a href="#optimizer--learning-rate-scheduler">Optimizer &amp;amp; Learning Rate Scheduler&lt;/a>&lt;/li>
&lt;li>&lt;a href="#prime-hyperparameters">Prime Hyperparameters&lt;/a>&lt;/li>
&lt;li>&lt;a href="#results">Results&lt;/a>&lt;/li>
&lt;li>&lt;a href="#discussion">Discussion&lt;/a>&lt;/li>
&lt;li>&lt;a href="#prospective">Prospective&lt;/a>&lt;/li>
&lt;li>&lt;a href="#License">License&lt;/a>&lt;/li>
&lt;/ul>
&lt;h2 id="tasks-description">Tasks Description&lt;/h2>
&lt;ul>
&lt;li>&lt;code>Task one&lt;/code> - Given one edited headline, design a regression model to predict how funny it is&lt;/li>
&lt;li>&lt;code>Task two&lt;/code> - Given the original headline and two manually edited versions, design a model to predict which edited version is the funnier of the two&lt;/li>
&lt;/ul>
&lt;h2 id="data-preprocessing">Data Preprocessing&lt;/h2>
&lt;h3 id="task-one">Task One&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>Convert original headlines into normal sentences (Remove &lt;code>&amp;lt;&lt;/code> and &lt;code>/&amp;gt;&lt;/code> by applying RE)&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Get the edited version of headlines by doing word substitution using RE&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Do tokenization and lowercasing for each edited-original headlines pair&lt;/p>
&lt;p>Data preprocessing for pre-trained LMs (BERT-liked LMs):&lt;/p>
&lt;ul>
&lt;li>Version 1 - Concatenate original headlines and new headlines&lt;/li>
&lt;li>Version 2 - Concatenate new headlines and new words&lt;/li>
&lt;li>Version 3 – Contain only new headlines&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="task-two">Task Two&lt;/h3>
&lt;p>There are 3 versions of data preprocessing:&lt;/p>
&lt;ul>
&lt;li>The normal version&lt;/li>
&lt;li>The headlines truncated version&lt;/li>
&lt;li>The punctuation removal version&lt;/li>
&lt;/ul>
&lt;h2 id="models-choices--design">Models Choices &amp;amp; Design&lt;/h2>
&lt;h3 id="task-one1">Task One&lt;/h3>
&lt;ul>
&lt;li>Two Inputs FFNN&lt;/li>
&lt;li>Two Inputs CNN&lt;/li>
&lt;li>Two Inputs RNN&lt;/li>
&lt;li>Two Inputs Concatenated RNN&lt;/li>
&lt;li>Pre-trained LM + a regression layer (LMs applied: BERT, ALBERT, XLNet, ELECTRA)&lt;/li>
&lt;/ul>
&lt;h4 id="two-inputs-ffnn">Two Inputs FFNN&lt;/h4>
&lt;p>This model is a two inputs’ feed forward neural network in which two input matrices representing all the original headlines and their corresponding
edited headlines respectively are passed simultaneously to the first so called embedding layer of the model to get the word embedding of the fixed
dimension for each word in the headline. Following above the model will do averaging for each headline to get the ‘document representation (vector)’
for each headline. Then these headlines’ vector representations are passed to a combination of three concatenated fully connected layers where the
information about “how humour they are” are encoded. The Relu activation is applied after output from each of the first two hidden layers to prevent
gradient vanishing and gradient exploding. Finally, all weighted sums or all vector products between the n-th row of the original matrix and the n-th
row of the edited matrix are computed such that a vector with the size (origin_headlines_num, 1) is returned.&lt;/p>
&lt;p align="center">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/two_inputs_FFNN.png" width="700" />
&lt;/p>
&lt;h4 id="two-inputs-cnn">Two Inputs CNN&lt;/h4>
&lt;p>This model uses text CNN architecture with single windows size instead of FFNN for the regression task. The original headlines tensor and the edited
headlines tensor are taken as the two inputs. In the output layer, unlike the normal matrix multiplication, all weighted sums or all vector products
between the n-th row of the original matrix and the n-th row of the edited matrix are computed such that a vector with the size (origin_headlines_num, 1)
is returned.&lt;/p>
&lt;p align="center">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/two_inputs_cnn.png" width="500" />
&lt;/p>
&lt;h4 id="two-inputs-rnn">Two Inputs RNN&lt;/h4>
&lt;p>This model uses single layer bidirectional RNN architecture for the regression task. It is again the same as Two Inputs CNN that takes two tensors as its
inputs and does a row-wise weighted summation in the output layer.&lt;/p>
&lt;p align="center">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/two_inputs_rnn.png" width="500" />
&lt;/p>
&lt;h4 id="two-inputs-concatenated-rnn">Two Inputs Concatenated RNN&lt;/h4>
&lt;p>This model is all the same as Two Inputs RNN except it concatenates the two last hidden states for the original headlines and the edited headlines to form
a single representation and do a normal matrix multiplication in the output layer.&lt;/p>
&lt;h4 id="pretrained-lm--a-regression-layer-lms-applied-bert-albert-xlnet-electra">Pre-trained LM + a regression layer (LMs applied: BERT, ALBERT, XLNet, ELECTRA)&lt;/h4>
&lt;h5 id="version-1--concatenate-original-headlines-and-new-headlines">Version 1 - Concatenate original headlines and new headlines&lt;/h5>
&lt;p align="left">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/lm_inputs_version_1.png" width="600" />
&lt;/p>
&lt;h5 id="version-2--concatenate-new-headlines-and-new-words">Version 2 - Concatenate new headlines and new words&lt;/h5>
&lt;p align="left">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/lm_inputs_version_2.png" width="600" />
&lt;/p>
&lt;h5 id="version-3--contain-only-new-headlines">Version 3 – Contain only new headlines&lt;/h5>
&lt;p align="left">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/lm_inputs_version_3.png" width="600" />
&lt;/p>
&lt;h3 id="task-two1">Task Two&lt;/h3>
&lt;h4 id="pretrained-lm--a-classification-layer">Pre-trained LM + a classification layer&lt;/h4>
&lt;h5 id="concatenate-edited-headline-1-and-edited-headline-2">Concatenate edited headline 1 and edited headline 2&lt;/h5>
&lt;p align="left">
&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/2_seq_inputs_lm.png" width="650" />
&lt;/p>
&lt;h2 id="design-of-training-processes-for-task-two-only">Design of Training Processes (for task two only)&lt;/h2>
&lt;h3 id="version-1">Version 1:&lt;/h3>
&lt;ul>
&lt;li>Training the model “Pre-trained LM + a classification layer”
straightly for the real classification task&lt;/li>
&lt;/ul>
&lt;h3 id="version-2-fake-task--real-task">Version 2 (Fake Task + Real Task):&lt;/h3>
&lt;ul>
&lt;li>Firstly, training the model “Pre-trained LM + a regression layer” for a fake regression task on the training dataset&lt;/li>
&lt;li>After training well, get rid of the regression layer and add an initialized classification layer on top of the pre-trained LM&lt;/li>
&lt;li>Finally training the model for the real classification task&lt;/li>
&lt;/ul>
&lt;h2 id="optimizer--learning-rate-scheduler">Optimizer &amp;amp; Learning Rate Scheduler&lt;/h2>
&lt;h3 id="for-ffnn-cnn-rnn">For FFNN, CNN, RNN:&lt;/h3>
&lt;ul>
&lt;li>The optimizer &lt;code>AdamW&lt;/code> and the scheduler &lt;code>CosineAnnealingLR&lt;/code> provided by pytorch&lt;/li>
&lt;/ul>
&lt;h3 id="for-pretrained-lms-bertliked-lms">For pre-trained LMs (BERT-liked LMs):&lt;/h3>
&lt;ul>
&lt;li>The optimizer &lt;code>AdamW&lt;/code> and the scheduler &lt;code>get_linear_schedule_with_warmup&lt;/code> from &lt;a href="https://huggingface.co/transformers/index.html" title="huggingface">Huggingface transformers&lt;/a>&lt;/li>
&lt;/ul>
&lt;h2 id="prime-hyperparameters">Prime Hyperparameters&lt;/h2>
&lt;ul>
&lt;li>Learning Rate&lt;/li>
&lt;li>Fine-tuning Rate&lt;/li>
&lt;li>Adam Epsilon&lt;/li>
&lt;li>Weight Decay&lt;/li>
&lt;li>Warmup Ratio&lt;/li>
&lt;li>Number of Steps&lt;/li>
&lt;/ul>
&lt;h2 id="results">Results&lt;/h2>
&lt;h3 id="task-one2">Task One&lt;/h3>
&lt;h4 id="best-performance-achieved-by-two-inputs-ffnn">Best performance achieved by Two Inputs FFNN&lt;/h4>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>EPOCHS&lt;/th>
&lt;th>LRATE&lt;/th>
&lt;th>EMBEDDING_DIM&lt;/th>
&lt;th>HIDDEN_DIM_1&lt;/th>
&lt;th>HIDDEN_DIM_2&lt;/th>
&lt;th>HIDDEN_DIM_3&lt;/th>
&lt;th>Train Loss&lt;/th>
&lt;th>Val. Loss&lt;/th>
&lt;th>Test Loss&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>100&lt;/td>
&lt;td>0.145&lt;/td>
&lt;td>300&lt;/td>
&lt;td>100&lt;/td>
&lt;td>50&lt;/td>
&lt;td>10&lt;/td>
&lt;td>0.575&lt;/td>
&lt;td>0.581&lt;/td>
&lt;td>0.576&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h4 id="best-performance-achieved-by-two-inputs-cnn">Best performance achieved by Two Inputs CNN&lt;/h4>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>EPOCHS&lt;/th>
&lt;th>LRATE&lt;/th>
&lt;th>EMBEDDING_DIM&lt;/th>
&lt;th>FC_OUT_DIM&lt;/th>
&lt;th>N_OUT_CHANNELS&lt;/th>
&lt;th>WINDOW_SIZE&lt;/th>
&lt;th>DROPOUT&lt;/th>
&lt;th>Train Loss&lt;/th>
&lt;th>Val. Loss&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>500&lt;/td>
&lt;td>5e-3&lt;/td>
&lt;td>50&lt;/td>
&lt;td>25&lt;/td>
&lt;td>100&lt;/td>
&lt;td>3&lt;/td>
&lt;td>0.7&lt;/td>
&lt;td>0.624&lt;/td>
&lt;td>0.661&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h4 id="best-performance-achieved-by-two-inputs-rnn">Best performance achieved by Two Inputs RNN&lt;/h4>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>EPOCHS&lt;/th>
&lt;th>LRATE&lt;/th>
&lt;th>EMBEDDING_DIM&lt;/th>
&lt;th>HIDDEN_DIM&lt;/th>
&lt;th>FC_OUTPUT_DIM&lt;/th>
&lt;th>BIDIRECTIONAL&lt;/th>
&lt;th>DROPOUT&lt;/th>
&lt;th>Train Loss&lt;/th>
&lt;th>Val. Loss&lt;/th>
&lt;th>Test Loss&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>30&lt;/td>
&lt;td>1e-4&lt;/td>
&lt;td>50&lt;/td>
&lt;td>128&lt;/td>
&lt;td>32&lt;/td>
&lt;td>Ture&lt;/td>
&lt;td>0.3&lt;/td>
&lt;td>0.586&lt;/td>
&lt;td>0.576&lt;/td>
&lt;td>0.571&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h4 id="best-performance-achieved-by-pretrained-lms">Best performance achieved by Pre-trained LMs&lt;/h4>
&lt;ul>
&lt;li>Without Data Augmentation
&lt;ul>
&lt;li>Model: bert_base_uncased&lt;/li>
&lt;li>Inputs structure: new headlines + new words&lt;/li>
&lt;li>Test loss: 0.52937&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>With Data Augmentation (add “funlines” training dataset)
&lt;ul>
&lt;li>Model: bert_base_uncased&lt;/li>
&lt;li>Inputs structure: new headlines + new words&lt;/li>
&lt;li>&lt;code>Test loss: 0.52054 (Best performance achieved among all trials)&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th align="center">&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/task1_log.png" alt="task1_log">&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td align="center">&lt;em>T1 Pre-trained LMs Log&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="task-two2">Task Two&lt;/h3>
&lt;h4 id="version-1-straightly-training-the-model-for-the-real-task">Version 1: Straightly training the model for the real task&lt;/h4>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th align="center">&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/task2_v1_log1.png" alt="task2_v1_log1">&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td align="center">&lt;em>T2 Log 1&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th align="center">&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/task2_v1_log2.png" alt="task2_v1_log2">&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td align="center">&lt;em>T2 Log 2&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h4 id="version-2-fake-task-training--real-task-training">Version 2: Fake Task Training + Real Task Training&lt;/h4>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th align="center">&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/task2_v2_f_log.png" alt="task2_v2_f_log">&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td align="center">&lt;em>T2 Fake Task Log&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th align="center">&lt;img src="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/images/task2_v2_r_log.png" alt="task2_v2_r_log">&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td align="center">&lt;em>T2 Real Task Log&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="discussion">Discussion&lt;/h2>
&lt;h3 id="task-one3">Task One&lt;/h3>
&lt;ul>
&lt;li>The performance of Two Inputs RNN is just slightly better compared with that of the Two Inputs FFNN (0.5759702196 vs. 0.5751694002) while the time complexity
of the Two Inputs RNN is much higher than the Two Inputs FFNN, at some point the current version of Two Inputs RNN is resources-wasted.&lt;/li>
&lt;li>The Two Inputs CNN with a single window size performs worse than the Two Inputs FFNN and the Two Inputs RNN, and one of possible reasons is that it only looks
at one size of n-gram and hence ignores the knowledge of n-grams with different lengths.&lt;/li>
&lt;/ul>
&lt;h3 id="task-two3">Task Two&lt;/h3>
&lt;ul>
&lt;li>For different preprocessing methods, the headlines truncated version and the punctuation removal version have the same performance as the normal one except
that truncating headlines will reduce the training time for a single epoch.&lt;/li>
&lt;li>The issue of overfitting on the training dataset is hard to overcome when applying BERT-liked pre-trained LMs (Although several methods, such as data
augmentation, weight decay and dropout increase have been tried to mitigate this problem.&lt;/li>
&lt;li>Surprisingly, the fake task training for pre-trained LMs does not help to improve the performance of the model in real task even a little bit.&lt;/li>
&lt;li>With the same hyperparameters setting for the certain task, the performance of the newly proposed pre-trained LM is not necessarily the best.&lt;/li>
&lt;/ul>
&lt;h2 id="prospective">Prospective&lt;/h2>
&lt;ul>
&lt;li>Construct a pretrain LM to do a binary classification task in which the model learns to decide whether a word from the edited new headline is original or
edited. Take the embeddings out of the pretrain model and use it to initialize the model for the real regression task. By doing so we expect the embeddings can
be informed some knowledge about the relationship between original headlines and edited headlines.&lt;/li>
&lt;li>Build up a pretrain LM to do a text translation task on the training dataset and use the embeddings of this model to initialize the model for the real
regression task. (Aim to learn the semantics of funniness).&lt;/li>
&lt;li>Intuitively thinking the performance of the Two Inputs CNN might be improved by increasing the number of the window sizes (different n-gram filters).&lt;/li>
&lt;li>Applying the pre-trained LM Longformer rather than other BERT-liked models for the task two, in which the Longformer has the ‘global attention mask’ and it
can probably better model the relationship between the edited word and the other words in a headline (e.g. &lt;code>How important is the edited word for the whole headline in order to make it funnier?&lt;/code> / &lt;code>How does the edited word contribute to the meaning of the whole sentence?&lt;/code>).&lt;/li>
&lt;/ul>
&lt;h2 id="license">License&lt;/h2>
&lt;p>This project following MIT License as written in the &lt;a href="https://github.com/JackyLin97/2020_NLP_Funniness_Estimation-PyTorch/raw/master/LICENSE">LICENSE&lt;/a> file.&lt;/p>
&lt;hr></description></item></channel></rss>