kaggle www.kaggle.com/c/quora-question-pairs/submissions
Quora ์ง๋ฌธ ๋ต๋ณ ์ฌ์ดํธ์์
๊ฐ์ ์ง๋ฌธ์ ๋ํ ํ๋ณ ๋ฌธ์ column
# ['id', 'qid1', 'qid2', 'question1', 'question2', 'is_duplicate']
CNN - ํฉ์ฑ ์ ๊ฒฝ๋ง
In deep learning, a convolutional neural network (CNN, or ConvNet) is a class of deep neural networks, most commonly applied to analyzing visual imagery.[1] They are also known as shift invariant or space invariant artificial neural networks (SIANN), based on their shared-weights architecture and translation invariance characteristics.[2][3] They have applications in image and video recognition, recommender systems,[4] image classification, Image segmentation, medical image analysis, natural language processing,[5] brain-computer interfaces,[6] and financial time series.[7]
Process
* Embedding
import tensorflow as tf
from tensorflow.keras import layers
class SentenceEmbedding(tf.keras.layers):
def __init__(self,**kwargs):
super(SentenceEmbedding,self).__init__()
self.conv = layers.Conv1D(kargs['conv_num_filters'],kargs['conv_window_size'],
activation=tf.keras.activations.relu,
padding='same')
- filters: ๊ฐ์ค์น, (NLP-๋จ์ด์ ์,Image-์ด๋ฏธ์ง์ ํน์ง)
- kernel_size: filter ํ๋ ฌ์ ํฌ๊ธฐ
- activation: ๋ชฉํ ์์น๋ก ๋ณํ ํด์ฃผ๋ ํจ์
gelu(...): Applies the Gaussian error linear unit (GELU) activation function.
linear(...): Linear activation function (pass-through).
relu(...): Applies the rectified linear unit activation function.
sigmoid(...): Sigmoid activation function, sigmoid(x) = 1 / (1 + exp(-x)).
softmax(...): Softmax converts a real vector to a vector of categorical probabilities.
tanh(...): Hyperbolic tangent activation function. - padding:
same: input size์ output size๊ฐ ๊ฐ๋ค.
valid: "ํจ๋ฉ ์์"์ ์๋ฏธ
casual: input_size๋ณด๋ค ํฐ(ํฝ์ฐฝํ) output_size
self.max_pool = layers.MaxPool1D(karg['max_pool_seq_len'],1)
- pool_size:(int) maxpool ์ฌ์ด์ฆ
- strides: pool ์ด๋ ๊ฐ๊ฒฉ
- padding: ์ฌ์ด์ฆ ๋ณ๊ฒฝ
max_pool input์ ํน์ง ์ถ์ถ
self.dense = layers.Dense(kargs['sent_embedding_dimension'],
activation=tf.keras.activation.relu)
units: output dimension
# activation์ผ๋ก output์ ํฌ๊ธฐ๋ฅผ ์ ํ๋ค.
def call(self,x):
x = self.conv(x)
x = self.maxpool(x)
x = self.dense(x)
return tf.squeeze(x)
# tf.squeeze(x) ๋ถํ์ํ ์ฐจ์ ์ ๊ฑฐ
# SimilarityModel (๋ณธ ๋ชจ๋ธ)
class SentenceSimilarityModel(tf.keras.Model):
def __init__(self,**kargs):
super(SentenceSimilarityModel, self).__init__(name=kargs['model_name'])
self.word_embedding = layers.Embedding(kargs['vocab_size'],kargs['word_embedding_dimension'])
self.base_encoder = SentenceEmbedding(**kargs) # ๋ฌธ์ฅ1 ์๋ฒ ๋ฉ
self.hypo_encoder = SentenceEmbedding(**kargs) # ๋ฌธ์ฅ2 ์๋ฒ ๋ฉ
self.dense = layers.Dense(kargs['hidden_dimension'],
activation=tf.keras.activations.relu)
self.logit = layers.Dense(1,activation=tf.keras.activations.sigmoid)
self.dropout = layers.Dropout(kargs['dropout_rate'])
def call(self,x):
x1, x2 = x
b_x = self.word_embedding(x1)
h_x = self.word_embedding(x2)
b_x = self.dropout(b_x)
h_x = self.dropout(h_x)
b_x = self.base_encoder(b_x)
h_x = self.hypo_encoder(h_x)
e_x = tf.concat([b_x,h_x],-1)
e_x = self.dense(e_x)
e_x = self.dropout(e_x)
return self.logit(e_x) # 0~1๋ก ๋ณํ
- tf.keras.layers.Dropout(
rate,
noise_shape=None,
seed=None,
**kwargs)
rate: (Float) 0~1 Fraction of the input units to drop.
Bayesian ์ ๊ฒฝ๋ง์ ํตํด ํด๋น ๋ด๋ฐ์ ๋ํ ํ์ต์ด ๋ฌด์๋ฏธ ํ ๊ฒฝ์ฐ ๋ค๋ฅธ ๋ด๋ฐ์ ํ์ต์ ์ค์ ์ผ๋ก ๋๋ค.
'๐ฃ๏ธ Natural Language Processing' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
MaLSTM (0) | 2021.02.13 |
---|---|
[Kaggle] ๋ค์ด๋ฒ ์ํ ๋ฆฌ๋ทฐ ๋ถ๋ฅ(1) (0) | 2021.02.12 |
PCA, SVD ์ ์ฌ ์๋ฏธ ๋ถ์ (0) | 2021.02.11 |
KoNLPy ์ข ๋ฅ (0) | 2021.02.06 |
SVD(singular value decomposition) VS SVM(support vector machine) (0) | 2021.02.05 |