├── .gitattributes ├── .gitignore ├── CLM2 ├── 100_makeup_1.csv └── 100_makeup_2.csv ├── README.md ├── Readme_final.docx ├── cnn ├── DBN.py ├── allfmea.txt ├── classfmea.txt ├── cnn_features.pl ├── convolutional_mlp_amazon.py ├── convolutional_mlp_amazon.pyc ├── format.m ├── format1.pl ├── format1b.pl ├── logistic_sgd.py ├── logistic_sgd.pyc ├── mlp.py ├── mlp.pyc ├── morb │ ├── __init__.py │ ├── __init__.pyc │ ├── activation_functions.py │ ├── activation_functions.pyc │ ├── base.py │ ├── base.pyc │ ├── factors.py │ ├── misc.py │ ├── misc.pyc │ ├── monitors.py │ ├── monitors.pyc │ ├── objectives.py │ ├── objectives.pyc │ ├── parameters.py │ ├── parameters.pyc │ ├── rbms.py │ ├── rbms.pyc │ ├── samplers.py │ ├── samplers.pyc │ ├── stats.py │ ├── stats.pyc │ ├── trainers.py │ ├── trainers.pyc │ ├── units.py │ ├── units.pyc │ ├── updaters.py │ └── updaters.pyc ├── mpqa_rnn.m ├── pack_Data.py ├── rbm.py ├── run2 │ ├── train_rnn_0.mat │ ├── train_rnn_1.mat │ ├── train_rnn_2.mat │ ├── train_rnn_3.mat │ ├── train_rnn_4.mat │ ├── train_rnn_5.mat │ ├── train_rnn_6.mat │ ├── train_rnn_7.mat │ ├── train_rnn_8.mat │ └── train_rnn_9.mat ├── transformtarget.m ├── utils.py ├── utils.pyc ├── utilsm.py ├── utilsm.pyc └── weights │ └── layer0b_0.save ├── cnninput.zip ├── crop_jul14.m ├── maketrain.m ├── pack_Data_foldb.py ├── readdata.m ├── resizeall.m ├── time.pl ├── transcriptions ├── 100_makeup.csv ├── 100_makeup.trs ├── 101_movies.csv ├── 101_movies.trs ├── 102_books.csv ├── 102_books.trs ├── 103_books.csv ├── 103_books.trs ├── 104_makeup.csv └── cats.txt ├── transcriptions2.zip ├── transcriptions3 ├── 100_makeup.csv ├── 100_makeup.trs ├── 101_movies.csv ├── 101_movies.trs ├── 102_books.csv ├── 102_books.trs ├── 103_books.csv └── cats.txt └── videos.zip /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multi-Modal-Sentiment-Detection 2 | Multi Modal Sentiment Detection 3 | 1. Videos are in video folder 4 | 2. CLM2 contains face outline from CLM software 5 | 3. Transcripts and time intervals for each video are in folder ‘transcriptions’ 6 | 4. Perl time.pl 7 | 5. Extract start and end of time segments into folder ‘transcriptions3’ 8 | 6. Matlab –r readdata.m 9 | 7. This will divide each video using segment information into folder ‘transcription2’ 10 | 8. Check the width and height of the video 11 | 9. Matlab –r crop_jul14.m 12 | 10. This will crop each video and save in folder ‘cnninput’ 13 | 11. There are 10 folders for 50 videos each 14 | 12. Matlab –r resizeall.m will reduce the resolution and duplicate the time series video 15 | 13. Matlab –r maketrain.m divide each of the 10 files into train, val and test 16 | 14. We can change the test files here with new dataset. 17 | 15. Python pack_Data_vid_cv.py will pack files for deep cnn 18 | 16. Cnninput/pack_Data_foldb.py this will pack same validation and test data 19 | 17. cnn/convolutional_mlp_amazon.py will run deep cnn on all 10 files 20 | 18. perl cnn_features.pl convert output to text 21 | 19. matlab –r format.m 22 | 20. matlab –r moud_rnn.m 23 | 21. Output for each file is in classfmea.txt and allfmea.txt 24 | -------------------------------------------------------------------------------- /Readme_final.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/Readme_final.docx -------------------------------------------------------------------------------- /cnn/DBN.py: -------------------------------------------------------------------------------- 1 | """ 2 | """ 3 | import os 4 | import sys 5 | import time 6 | 7 | import numpy 8 | 9 | import theano 10 | import theano.tensor as T 11 | from theano.tensor.shared_randomstreams import RandomStreams 12 | 13 | from logistic_sgd import LogisticRegression, load_data 14 | from mlp import HiddenLayer 15 | from rbm import RBM 16 | 17 | 18 | # start-snippet-1 19 | class DBN(object): 20 | """Deep Belief Network 21 | 22 | A deep belief network is obtained by stacking several RBMs on top of each 23 | other. The hidden layer of the RBM at layer `i` becomes the input of the 24 | RBM at layer `i+1`. The first layer RBM gets as input the input of the 25 | network, and the hidden layer of the last RBM represents the output. When 26 | used for classification, the DBN is treated as a MLP, by adding a logistic 27 | regression layer on top. 28 | """ 29 | 30 | def __init__(self, numpy_rng, theano_rng=None, n_ins=100, 31 | hidden_layers_sizes=[500, 500], n_outs=2): 32 | """This class is made to support a variable number of layers. 33 | 34 | :type numpy_rng: numpy.random.RandomState 35 | :param numpy_rng: numpy random number generator used to draw initial 36 | weights 37 | 38 | :type theano_rng: theano.tensor.shared_randomstreams.RandomStreams 39 | :param theano_rng: Theano random generator; if None is given one is 40 | generated based on a seed drawn from `rng` 41 | 42 | :type n_ins: int 43 | :param n_ins: dimension of the input to the DBN 44 | 45 | :type hidden_layers_sizes: list of ints 46 | :param hidden_layers_sizes: intermediate layers size, must contain 47 | at least one value 48 | 49 | :type n_outs: int 50 | :param n_outs: dimension of the output of the network 51 | """ 52 | 53 | self.sigmoid_layers = [] 54 | self.rbm_layers = [] 55 | self.params = [] 56 | self.n_layers = len(hidden_layers_sizes) 57 | 58 | assert self.n_layers > 0 59 | 60 | if not theano_rng: 61 | theano_rng = RandomStreams(numpy_rng.randint(2 ** 30)) 62 | 63 | # allocate symbolic variables for the data 64 | self.x = T.matrix('x') # the data is presented as rasterized images 65 | self.y = T.ivector('y') # the labels are presented as 1D vector 66 | # of [int] labels 67 | # end-snippet-1 68 | # The DBN is an MLP, for which all weights of intermediate 69 | # layers are shared with a different RBM. We will first 70 | # construct the DBN as a deep multilayer perceptron, and when 71 | # constructing each sigmoidal layer we also construct an RBM 72 | # that shares weights with that layer. During pretraining we 73 | # will train these RBMs (which will lead to chainging the 74 | # weights of the MLP as well) During finetuning we will finish 75 | # training the DBN by doing stochastic gradient descent on the 76 | # MLP. 77 | 78 | for i in xrange(self.n_layers): 79 | # construct the sigmoidal layer 80 | 81 | # the size of the input is either the number of hidden 82 | # units of the layer below or the input size if we are on 83 | # the first layer 84 | if i == 0: 85 | input_size = n_ins 86 | else: 87 | input_size = hidden_layers_sizes[i - 1] 88 | 89 | # the input to this layer is either the activation of the 90 | # hidden layer below or the input of the DBN if you are on 91 | # the first layer 92 | if i == 0: 93 | layer_input = self.x 94 | else: 95 | layer_input = self.sigmoid_layers[-1].output 96 | 97 | sigmoid_layer = HiddenLayer(rng=numpy_rng, 98 | input=layer_input, 99 | n_in=input_size, 100 | n_out=hidden_layers_sizes[i], 101 | activation=T.nnet.sigmoid) 102 | 103 | # add the layer to our list of layers 104 | self.sigmoid_layers.append(sigmoid_layer) 105 | 106 | # its arguably a philosophical question... but we are 107 | # going to only declare that the parameters of the 108 | # sigmoid_layers are parameters of the DBN. The visible 109 | # biases in the RBM are parameters of those RBMs, but not 110 | # of the DBN. 111 | self.params.extend(sigmoid_layer.params) 112 | 113 | # Construct an RBM that shared weights with this layer 114 | rbm_layer = RBM(numpy_rng=numpy_rng, 115 | theano_rng=theano_rng, 116 | input=layer_input, 117 | n_visible=input_size, 118 | n_hidden=hidden_layers_sizes[i], 119 | W=sigmoid_layer.W, 120 | hbias=sigmoid_layer.b) 121 | self.rbm_layers.append(rbm_layer) 122 | 123 | # We now need to add a logistic layer on top of the MLP 124 | self.logLayer = LogisticRegression( 125 | input=self.sigmoid_layers[-1].output, 126 | n_in=hidden_layers_sizes[-1], 127 | n_out=n_outs) 128 | self.params.extend(self.logLayer.params) 129 | 130 | # compute the cost for second phase of training, defined as the 131 | # negative log likelihood of the logistic regression (output) layer 132 | self.finetune_cost = self.logLayer.negative_log_likelihood(self.y) 133 | 134 | # compute the gradients with respect to the model parameters 135 | # symbolic variable that points to the number of errors made on the 136 | # minibatch given by self.x and self.y 137 | self.errors = self.logLayer.errors(self.y) 138 | 139 | def pretraining_functions(self, train_set_x, batch_size, k): 140 | '''Generates a list of functions, for performing one step of 141 | gradient descent at a given layer. The function will require 142 | as input the minibatch index, and to train an RBM you just 143 | need to iterate, calling the corresponding function on all 144 | minibatch indexes. 145 | 146 | :type train_set_x: theano.tensor.TensorType 147 | :param train_set_x: Shared var. that contains all datapoints used 148 | for training the RBM 149 | :type batch_size: int 150 | :param batch_size: size of a [mini]batch 151 | :param k: number of Gibbs steps to do in CD-k / PCD-k 152 | 153 | ''' 154 | 155 | # index to a [mini]batch 156 | index = T.lscalar('index') # index to a minibatch 157 | learning_rate = T.scalar('lr') # learning rate to use 158 | 159 | # number of batches 160 | n_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size 161 | # begining of a batch, given `index` 162 | batch_begin = index * batch_size 163 | # ending of a batch given `index` 164 | batch_end = batch_begin + batch_size 165 | 166 | pretrain_fns = [] 167 | for rbm in self.rbm_layers: 168 | 169 | # get the cost and the updates list 170 | # using CD-k here (persisent=None) for training each RBM. 171 | # TODO: change cost function to reconstruction error 172 | cost, updates = rbm.get_cost_updates(learning_rate, 173 | persistent=None, k=k) 174 | 175 | # compile the theano function 176 | fn = theano.function( 177 | inputs=[index, theano.Param(learning_rate, default=0.1)], 178 | outputs=cost, 179 | updates=updates, 180 | givens={ 181 | self.x: train_set_x[batch_begin:batch_end] 182 | } 183 | ) 184 | # append `fn` to the list of functions 185 | pretrain_fns.append(fn) 186 | 187 | return pretrain_fns 188 | 189 | def build_finetune_functions(self, datasets, batch_size, learning_rate): 190 | '''Generates a function `train` that implements one step of 191 | finetuning, a function `validate` that computes the error on a 192 | batch from the validation set, and a function `test` that 193 | computes the error on a batch from the testing set 194 | 195 | :type datasets: list of pairs of theano.tensor.TensorType 196 | :param datasets: It is a list that contain all the datasets; 197 | the has to contain three pairs, `train`, 198 | `valid`, `test` in this order, where each pair 199 | is formed of two Theano variables, one for the 200 | datapoints, the other for the labels 201 | :type batch_size: int 202 | :param batch_size: size of a minibatch 203 | :type learning_rate: float 204 | :param learning_rate: learning rate used during finetune stage 205 | 206 | ''' 207 | 208 | (train_set_x, train_set_y) = datasets[0] 209 | (valid_set_x, valid_set_y) = datasets[1] 210 | (test_set_x, test_set_y) = datasets[2] 211 | 212 | # compute number of minibatches for training, validation and testing 213 | n_valid_batches = valid_set_x.get_value(borrow=True).shape[0] 214 | n_valid_batches /= batch_size 215 | n_test_batches = test_set_x.get_value(borrow=True).shape[0] 216 | n_test_batches /= batch_size 217 | 218 | index = T.lscalar('index') # index to a [mini]batch 219 | 220 | # compute the gradients with respect to the model parameters 221 | gparams = T.grad(self.finetune_cost, self.params) 222 | 223 | # compute list of fine-tuning updates 224 | updates = [] 225 | for param, gparam in zip(self.params, gparams): 226 | updates.append((param, param - gparam * learning_rate)) 227 | 228 | train_fn = theano.function( 229 | inputs=[index], 230 | outputs=self.finetune_cost, 231 | updates=updates, 232 | givens={ 233 | self.x: train_set_x[ 234 | index * batch_size: (index + 1) * batch_size 235 | ], 236 | self.y: train_set_y[ 237 | index * batch_size: (index + 1) * batch_size 238 | ] 239 | } 240 | ) 241 | 242 | test_score_i = theano.function( 243 | [index], 244 | self.errors, 245 | givens={ 246 | self.x: test_set_x[ 247 | index * batch_size: (index + 1) * batch_size 248 | ], 249 | self.y: test_set_y[ 250 | index * batch_size: (index + 1) * batch_size 251 | ] 252 | } 253 | ) 254 | 255 | valid_score_i = theano.function( 256 | [index], 257 | self.errors, 258 | givens={ 259 | self.x: valid_set_x[ 260 | index * batch_size: (index + 1) * batch_size 261 | ], 262 | self.y: valid_set_y[ 263 | index * batch_size: (index + 1) * batch_size 264 | ] 265 | } 266 | ) 267 | 268 | # Create a function that scans the entire validation set 269 | def valid_score(): 270 | return [valid_score_i(i) for i in xrange(n_valid_batches)] 271 | 272 | # Create a function that scans the entire test set 273 | def test_score(): 274 | return [test_score_i(i) for i in xrange(n_test_batches)] 275 | 276 | return train_fn, valid_score, test_score 277 | 278 | 279 | def test_DBN(finetune_lr=0.1, pretraining_epochs=100, 280 | pretrain_lr=0.01, k=1, training_epochs=1000, 281 | dataset='audvis2.pkl.gz', batch_size=1): 282 | """ 283 | Demonstrates how to train and test a Deep Belief Network. 284 | 285 | This is demonstrated on MNIST. 286 | 287 | :type finetune_lr: float 288 | :param finetune_lr: learning rate used in the finetune stage 289 | :type pretraining_epochs: int 290 | :param pretraining_epochs: number of epoch to do pretraining 291 | :type pretrain_lr: float 292 | :param pretrain_lr: learning rate to be used during pre-training 293 | :type k: int 294 | :param k: number of Gibbs steps in CD/PCD 295 | :type training_epochs: int 296 | :param training_epochs: maximal number of iterations ot run the optimizer 297 | :type dataset: string 298 | :param dataset: path the the pickled dataset 299 | :type batch_size: int 300 | :param batch_size: the size of a minibatch 301 | """ 302 | 303 | datasets = load_data(dataset) 304 | 305 | train_set_x, train_set_y = datasets[0] 306 | valid_set_x, valid_set_y = datasets[1] 307 | test_set_x, test_set_y = datasets[2] 308 | 309 | # compute number of minibatches for training, validation and testing 310 | n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size 311 | 312 | # numpy random generator 313 | numpy_rng = numpy.random.RandomState(123) 314 | print '... building the model' 315 | # construct the Deep Belief Network 316 | dbn = DBN(numpy_rng=numpy_rng, n_ins=100, 317 | hidden_layers_sizes=[2000], 318 | n_outs=2) 319 | 320 | # start-snippet-2 321 | ######################### 322 | # PRETRAINING THE MODEL # 323 | ######################### 324 | print '... getting the pretraining functions' 325 | pretraining_fns = dbn.pretraining_functions(train_set_x=train_set_x, 326 | batch_size=batch_size, 327 | k=k) 328 | 329 | print '... pre-training the model' 330 | start_time = time.clock() 331 | ## Pre-train layer-wise 332 | for i in xrange(dbn.n_layers): 333 | # go through pretraining epochs 334 | for epoch in xrange(pretraining_epochs): 335 | # go through the training set 336 | c = [] 337 | for batch_index in xrange(n_train_batches): 338 | c.append(pretraining_fns[i](index=batch_index, 339 | lr=pretrain_lr)) 340 | print 'Pre-training layer %i, epoch %d, cost ' % (i, epoch), 341 | print numpy.mean(c) 342 | 343 | end_time = time.clock() 344 | # end-snippet-2 345 | print >> sys.stderr, ('The pretraining code for file ' + 346 | os.path.split(__file__)[1] + 347 | ' ran for %.2fm' % ((end_time - start_time) / 60.)) 348 | ######################## 349 | # FINETUNING THE MODEL # 350 | ######################## 351 | 352 | # get the training, validation and testing function for the model 353 | print '... getting the finetuning functions' 354 | train_fn, validate_model, test_model = dbn.build_finetune_functions( 355 | datasets=datasets, 356 | batch_size=batch_size, 357 | learning_rate=finetune_lr 358 | ) 359 | 360 | print '... finetuning the model' 361 | # early-stopping parameters 362 | patience = 4 * n_train_batches # look as this many examples regardless 363 | patience_increase = 2. # wait this much longer when a new best is 364 | # found 365 | improvement_threshold = 0.995 # a relative improvement of this much is 366 | # considered significant 367 | validation_frequency = min(n_train_batches, patience / 2) 368 | # go through this many 369 | # minibatches before checking the network 370 | # on the validation set; in this case we 371 | # check every epoch 372 | 373 | best_validation_loss = numpy.inf 374 | test_score = 0. 375 | start_time = time.clock() 376 | 377 | done_looping = False 378 | epoch = 0 379 | 380 | while (epoch < training_epochs) and (not done_looping): 381 | epoch = epoch + 1 382 | for minibatch_index in xrange(n_train_batches): 383 | 384 | minibatch_avg_cost = train_fn(minibatch_index) 385 | iter = (epoch - 1) * n_train_batches + minibatch_index 386 | 387 | if (iter + 1) % validation_frequency == 0: 388 | 389 | validation_losses = validate_model() 390 | this_validation_loss = numpy.mean(validation_losses) 391 | print( 392 | 'epoch %i, minibatch %i/%i, validation error %f %%' 393 | % ( 394 | epoch, 395 | minibatch_index + 1, 396 | n_train_batches, 397 | this_validation_loss * 100. 398 | ) 399 | ) 400 | 401 | # if we got the best validation score until now 402 | if this_validation_loss < best_validation_loss: 403 | 404 | #improve patience if loss improvement is good enough 405 | if ( 406 | this_validation_loss < best_validation_loss * 407 | improvement_threshold 408 | ): 409 | patience = max(patience, iter * patience_increase) 410 | 411 | # save best validation score and iteration number 412 | best_validation_loss = this_validation_loss 413 | best_iter = iter 414 | 415 | # test it on the test set 416 | test_losses = test_model() 417 | test_score = numpy.mean(test_losses) 418 | print((' epoch %i, minibatch %i/%i, test error of ' 419 | 'best model %f %%') % 420 | (epoch, minibatch_index + 1, n_train_batches, 421 | test_score * 100.)) 422 | 423 | if patience <= iter: 424 | done_looping = True 425 | break 426 | 427 | end_time = time.clock() 428 | print( 429 | ( 430 | 'Optimization complete with best validation score of %f %%, ' 431 | 'obtained at iteration %i, ' 432 | 'with test performance %f %%' 433 | ) % (best_validation_loss * 100., best_iter + 1, test_score * 100.) 434 | ) 435 | print >> sys.stderr, ('The fine tuning code for file ' + 436 | os.path.split(__file__)[1] + 437 | ' ran for %.2fm' % ((end_time - start_time) 438 | / 60.)) 439 | 440 | 441 | if __name__ == '__main__': 442 | test_DBN() 443 | -------------------------------------------------------------------------------- /cnn/allfmea.txt: -------------------------------------------------------------------------------- 1 | 0.98958 2 | 1 3 | 0.98958 4 | 1 5 | 1 6 | 0.95833 7 | 1 8 | 0.96875 9 | 0.95833 10 | 0.91667 11 | -------------------------------------------------------------------------------- /cnn/classfmea.txt: -------------------------------------------------------------------------------- 1 | 0.98958,0.98958 2 | 1,1 3 | 0.98958,0.98958 4 | 1,1 5 | 1,1 6 | 0.95833,0.95833 7 | 1,1 8 | 0.96875,0.96875 9 | 0.95833,0.95833 10 | 0.91667,0.91667 11 | -------------------------------------------------------------------------------- /cnn/cnn_features.pl: -------------------------------------------------------------------------------- 1 | for($k=0;$k<10;$k++){ 2 | system("perl format1.pl run2/layer0_vid_train$k\.csv > run2/train_cnn$k"); 3 | system("perl format1.pl run2/layer0_vid_val$k\.csv > run2/val_cnn$k"); 4 | system("perl format1.pl run2/layer0_vid_test$k\.csv > run2/test_cnn$k"); 5 | } -------------------------------------------------------------------------------- /cnn/convolutional_mlp_amazon.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/convolutional_mlp_amazon.pyc -------------------------------------------------------------------------------- /cnn/format.m: -------------------------------------------------------------------------------- 1 | clear 2 | 3 | for k=0:9 4 | 5 | filename = sprintf('run2/train_cnn%d',k); 6 | layer3_mat = load(filename); 7 | 8 | [n1 n2] = size(layer3_mat); 9 | 10 | w = 20; f=0; check = 0; 11 | f=reshape(layer3_mat,w,n1/w); 12 | 13 | filename = sprintf('../cnninput/x50_%d/trainy.txt',k+1); 14 | %filename = sprintf('run2/train%d_y',k); 15 | %load 'run2/train0_y'; 16 | train0_y=load(filename); 17 | 18 | label_y = train0_y; 19 | 20 | [n1 n2]=size(f); 21 | [n3 n4]=size(label_y); 22 | 23 | if n2 < n3 24 | label_y = label_y(1:n2,:); 25 | else 26 | f = f(:,1:n3); 27 | end 28 | 29 | g = [f; label_y'+1]; 30 | 31 | filename = sprintf('set_train_rnn%d',k); 32 | dlmwrite(filename,g); 33 | 34 | filename = sprintf('run2/test_cnn%d',k); 35 | layer3_mat = load(filename); 36 | 37 | [n1 n2] = size(layer3_mat); 38 | 39 | w = 20; f=0; check = 0; 40 | f=reshape(layer3_mat,w,n1/w); 41 | 42 | 43 | filename = sprintf('../cnninput/x50_%d/y50.txt',k+1); 44 | %filename = sprintf('run2/test%d_y',k); 45 | %load 'run2/test0_y'; 46 | test0_y=load(filename); 47 | 48 | label_y = test0_y; 49 | 50 | [n1 n2]=size(f); 51 | [n3 n4]=size(label_y); 52 | 53 | if n2 < n3 54 | label_y = label_y(1:n2,:); 55 | else 56 | f = f(:,1:n3); 57 | end 58 | 59 | g = [f; label_y'+1]; 60 | 61 | filename = sprintf('set_test_rnn%d',k); 62 | dlmwrite(filename,g); 63 | 64 | filename = sprintf('run2/val_cnn%d',k); 65 | layer3_mat = load(filename); 66 | 67 | [n1 n2] = size(layer3_mat); 68 | 69 | w = 20; f=0; check = 0; 70 | f=reshape(layer3_mat,w,n1/w); 71 | 72 | filename = sprintf('../cnninput/x50_%d/valy.txt',k+1); 73 | %filename = sprintf('run2/val%d_y',k); 74 | %load 'run2/val0_y'; 75 | val0_y=load(filename); 76 | 77 | label_y = val0_y; 78 | 79 | [n1 n2]=size(f); 80 | [n3 n4]=size(label_y); 81 | 82 | if n2 < n3 83 | label_y = label_y(1:n2,:); 84 | else 85 | f = f(:,1:n3); 86 | end 87 | 88 | 89 | g = [f; label_y'+1]; 90 | 91 | filename = sprintf('set_val_rnn%d',k); 92 | dlmwrite(filename,g); 93 | 94 | end -------------------------------------------------------------------------------- /cnn/format1.pl: -------------------------------------------------------------------------------- 1 | open(FILE,$ARGV[0]); 2 | while($line = ) 3 | { 4 | chomp($line); 5 | @list = (); 6 | @list = split(",",$line); 7 | 8 | for($i=0;$i) 4 | { 5 | chomp($line); 6 | @list = split 7 | $line =~ tr/\[\]//d; 8 | @list = split " ",$line; 9 | for($i=0;$i> sys.stderr, ('The code for file ' + 462 | os.path.split(__file__)[1] + 463 | ' ran for %.1fs' % ((end_time - start_time))) 464 | 465 | if __name__ == '__main__': 466 | sgd_optimization_mnist() 467 | -------------------------------------------------------------------------------- /cnn/logistic_sgd.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/logistic_sgd.pyc -------------------------------------------------------------------------------- /cnn/mlp.py: -------------------------------------------------------------------------------- 1 | """ 2 | This tutorial introduces the multilayer perceptron using Theano. 3 | 4 | A multilayer perceptron is a logistic regressor where 5 | instead of feeding the input to the logistic regression you insert a 6 | intermediate layer, called the hidden layer, that has a nonlinear 7 | activation function (usually tanh or sigmoid) . One can use many such 8 | hidden layers making the architecture deep. The tutorial will also tackle 9 | the problem of MNIST digit classification. 10 | 11 | .. math:: 12 | 13 | f(x) = G( b^{(2)} + W^{(2)}( s( b^{(1)} + W^{(1)} x))), 14 | 15 | References: 16 | 17 | - textbooks: "Pattern Recognition and Machine Learning" - 18 | Christopher M. Bishop, section 5 19 | 20 | """ 21 | __docformat__ = 'restructedtext en' 22 | 23 | 24 | import os 25 | import sys 26 | import time 27 | 28 | import numpy 29 | 30 | import theano 31 | import theano.tensor as T 32 | 33 | 34 | from logistic_sgd import LogisticRegression, load_data 35 | 36 | 37 | # start-snippet-1 38 | class HiddenLayer(object): 39 | def __init__(self, rng, input, n_in, n_out, W=None, b=None, 40 | activation=T.tanh): 41 | """ 42 | Typical hidden layer of a MLP: units are fully-connected and have 43 | sigmoidal activation function. Weight matrix W is of shape (n_in,n_out) 44 | and the bias vector b is of shape (n_out,). 45 | 46 | NOTE : The nonlinearity used here is tanh 47 | 48 | Hidden unit activation is given by: tanh(dot(input,W) + b) 49 | 50 | :type rng: numpy.random.RandomState 51 | :param rng: a random number generator used to initialize weights 52 | 53 | :type input: theano.tensor.dmatrix 54 | :param input: a symbolic tensor of shape (n_examples, n_in) 55 | 56 | :type n_in: int 57 | :param n_in: dimensionality of input 58 | 59 | :type n_out: int 60 | :param n_out: number of hidden units 61 | 62 | :type activation: theano.Op or function 63 | :param activation: Non linearity to be applied in the hidden 64 | layer 65 | """ 66 | self.input = input 67 | # end-snippet-1 68 | 69 | # `W` is initialized with `W_values` which is uniformely sampled 70 | # from sqrt(-6./(n_in+n_hidden)) and sqrt(6./(n_in+n_hidden)) 71 | # for tanh activation function 72 | # the output of uniform if converted using asarray to dtype 73 | # theano.config.floatX so that the code is runable on GPU 74 | # Note : optimal initialization of weights is dependent on the 75 | # activation function used (among other things). 76 | # For example, results presented in [Xavier10] suggest that you 77 | # should use 4 times larger initial weights for sigmoid 78 | # compared to tanh 79 | # We have no info for other function, so we use the same as 80 | # tanh. 81 | if W is None: 82 | W_values = numpy.asarray( 83 | rng.uniform( 84 | low=-numpy.sqrt(6. / (n_in + n_out)), 85 | high=numpy.sqrt(6. / (n_in + n_out)), 86 | size=(n_in, n_out) 87 | ), 88 | dtype=theano.config.floatX 89 | ) 90 | if activation == theano.tensor.nnet.sigmoid: 91 | W_values *= 4 92 | 93 | W = theano.shared(value=W_values, name='W', borrow=True) 94 | 95 | if b is None: 96 | b_values = numpy.zeros((n_out,), dtype=theano.config.floatX) 97 | b = theano.shared(value=b_values, name='b', borrow=True) 98 | 99 | self.W = W 100 | self.b = b 101 | 102 | lin_output = T.dot(input, self.W) + self.b 103 | self.output = ( 104 | lin_output if activation is None 105 | else activation(lin_output) 106 | ) 107 | # parameters of the model 108 | self.params = [self.W, self.b] 109 | 110 | 111 | # start-snippet-2 112 | class MLP(object): 113 | """Multi-Layer Perceptron Class 114 | 115 | A multilayer perceptron is a feedforward artificial neural network model 116 | that has one layer or more of hidden units and nonlinear activations. 117 | Intermediate layers usually have as activation function tanh or the 118 | sigmoid function (defined here by a ``HiddenLayer`` class) while the 119 | top layer is a softamx layer (defined here by a ``LogisticRegression`` 120 | class). 121 | """ 122 | 123 | def __init__(self, rng, input, n_in, n_hidden, n_out): 124 | """Initialize the parameters for the multilayer perceptron 125 | 126 | :type rng: numpy.random.RandomState 127 | :param rng: a random number generator used to initialize weights 128 | 129 | :type input: theano.tensor.TensorType 130 | :param input: symbolic variable that describes the input of the 131 | architecture (one minibatch) 132 | 133 | :type n_in: int 134 | :param n_in: number of input units, the dimension of the space in 135 | which the datapoints lie 136 | 137 | :type n_hidden: int 138 | :param n_hidden: number of hidden units 139 | 140 | :type n_out: int 141 | :param n_out: number of output units, the dimension of the space in 142 | which the labels lie 143 | 144 | """ 145 | 146 | # Since we are dealing with a one hidden layer MLP, this will translate 147 | # into a HiddenLayer with a tanh activation function connected to the 148 | # LogisticRegression layer; the activation function can be replaced by 149 | # sigmoid or any other nonlinear function 150 | self.hiddenLayer = HiddenLayer( 151 | rng=rng, 152 | input=input, 153 | n_in=n_in, 154 | n_out=n_hidden, 155 | activation=T.tanh 156 | ) 157 | 158 | # The logistic regression layer gets as input the hidden units 159 | # of the hidden layer 160 | self.logRegressionLayer = LogisticRegression( 161 | input=self.hiddenLayer.output, 162 | n_in=n_hidden, 163 | n_out=n_out 164 | ) 165 | # end-snippet-2 start-snippet-3 166 | # L1 norm ; one regularization option is to enforce L1 norm to 167 | # be small 168 | self.L1 = ( 169 | abs(self.hiddenLayer.W).sum() 170 | + abs(self.logRegressionLayer.W).sum() 171 | ) 172 | 173 | # square of L2 norm ; one regularization option is to enforce 174 | # square of L2 norm to be small 175 | self.L2_sqr = ( 176 | (self.hiddenLayer.W ** 2).sum() 177 | + (self.logRegressionLayer.W ** 2).sum() 178 | ) 179 | 180 | # negative log likelihood of the MLP is given by the negative 181 | # log likelihood of the output of the model, computed in the 182 | # logistic regression layer 183 | self.negative_log_likelihood = ( 184 | self.logRegressionLayer.negative_log_likelihood 185 | ) 186 | # same holds for the function computing the number of errors 187 | self.errors = self.logRegressionLayer.errors 188 | 189 | # the parameters of the model are the parameters of the two layer it is 190 | # made out of 191 | self.params = self.hiddenLayer.params + self.logRegressionLayer.params 192 | # end-snippet-3 193 | 194 | 195 | def test_mlp(learning_rate=0.01, L1_reg=0.00, L2_reg=0.0001, n_epochs=1000, 196 | dataset='mnist.pkl.gz', batch_size=20, n_hidden=500): 197 | """ 198 | Demonstrate stochastic gradient descent optimization for a multilayer 199 | perceptron 200 | 201 | This is demonstrated on MNIST. 202 | 203 | :type learning_rate: float 204 | :param learning_rate: learning rate used (factor for the stochastic 205 | gradient 206 | 207 | :type L1_reg: float 208 | :param L1_reg: L1-norm's weight when added to the cost (see 209 | regularization) 210 | 211 | :type L2_reg: float 212 | :param L2_reg: L2-norm's weight when added to the cost (see 213 | regularization) 214 | 215 | :type n_epochs: int 216 | :param n_epochs: maximal number of epochs to run the optimizer 217 | 218 | :type dataset: string 219 | :param dataset: the path of the MNIST dataset file from 220 | http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz 221 | 222 | 223 | """ 224 | datasets = load_data(dataset) 225 | 226 | train_set_x, train_set_y = datasets[0] 227 | valid_set_x, valid_set_y = datasets[1] 228 | test_set_x, test_set_y = datasets[2] 229 | 230 | # compute number of minibatches for training, validation and testing 231 | n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size 232 | n_valid_batches = valid_set_x.get_value(borrow=True).shape[0] / batch_size 233 | n_test_batches = test_set_x.get_value(borrow=True).shape[0] / batch_size 234 | 235 | ###################### 236 | # BUILD ACTUAL MODEL # 237 | ###################### 238 | print '... building the model' 239 | 240 | # allocate symbolic variables for the data 241 | index = T.lscalar() # index to a [mini]batch 242 | x = T.matrix('x') # the data is presented as rasterized images 243 | y = T.ivector('y') # the labels are presented as 1D vector of 244 | # [int] labels 245 | 246 | rng = numpy.random.RandomState(1234) 247 | 248 | # construct the MLP class 249 | classifier = MLP( 250 | rng=rng, 251 | input=x, 252 | n_in=28 * 28, 253 | n_hidden=n_hidden, 254 | n_out=10 255 | ) 256 | 257 | # start-snippet-4 258 | # the cost we minimize during training is the negative log likelihood of 259 | # the model plus the regularization terms (L1 and L2); cost is expressed 260 | # here symbolically 261 | cost = ( 262 | classifier.negative_log_likelihood(y) 263 | + L1_reg * classifier.L1 264 | + L2_reg * classifier.L2_sqr 265 | ) 266 | # end-snippet-4 267 | 268 | # compiling a Theano function that computes the mistakes that are made 269 | # by the model on a minibatch 270 | test_model = theano.function( 271 | inputs=[index], 272 | outputs=classifier.errors(y), 273 | givens={ 274 | x: test_set_x[index * batch_size:(index + 1) * batch_size], 275 | y: test_set_y[index * batch_size:(index + 1) * batch_size] 276 | } 277 | ) 278 | 279 | validate_model = theano.function( 280 | inputs=[index], 281 | outputs=classifier.errors(y), 282 | givens={ 283 | x: valid_set_x[index * batch_size:(index + 1) * batch_size], 284 | y: valid_set_y[index * batch_size:(index + 1) * batch_size] 285 | } 286 | ) 287 | 288 | # start-snippet-5 289 | # compute the gradient of cost with respect to theta (sotred in params) 290 | # the resulting gradients will be stored in a list gparams 291 | gparams = [T.grad(cost, param) for param in classifier.params] 292 | 293 | # specify how to update the parameters of the model as a list of 294 | # (variable, update expression) pairs 295 | 296 | # given two list the zip A = [a1, a2, a3, a4] and B = [b1, b2, b3, b4] of 297 | # same length, zip generates a list C of same size, where each element 298 | # is a pair formed from the two lists : 299 | # C = [(a1, b1), (a2, b2), (a3, b3), (a4, b4)] 300 | updates = [ 301 | (param, param - learning_rate * gparam) 302 | for param, gparam in zip(classifier.params, gparams) 303 | ] 304 | 305 | # compiling a Theano function `train_model` that returns the cost, but 306 | # in the same time updates the parameter of the model based on the rules 307 | # defined in `updates` 308 | train_model = theano.function( 309 | inputs=[index], 310 | outputs=cost, 311 | updates=updates, 312 | givens={ 313 | x: train_set_x[index * batch_size: (index + 1) * batch_size], 314 | y: train_set_y[index * batch_size: (index + 1) * batch_size] 315 | } 316 | ) 317 | # end-snippet-5 318 | 319 | ############### 320 | # TRAIN MODEL # 321 | ############### 322 | print '... training' 323 | 324 | # early-stopping parameters 325 | patience = 10000 # look as this many examples regardless 326 | patience_increase = 2 # wait this much longer when a new best is 327 | # found 328 | improvement_threshold = 0.995 # a relative improvement of this much is 329 | # considered significant 330 | validation_frequency = min(n_train_batches, patience / 2) 331 | # go through this many 332 | # minibatche before checking the network 333 | # on the validation set; in this case we 334 | # check every epoch 335 | 336 | best_validation_loss = numpy.inf 337 | best_iter = 0 338 | test_score = 0. 339 | start_time = time.clock() 340 | 341 | epoch = 0 342 | done_looping = False 343 | 344 | while (epoch < n_epochs) and (not done_looping): 345 | epoch = epoch + 1 346 | for minibatch_index in xrange(n_train_batches): 347 | 348 | minibatch_avg_cost = train_model(minibatch_index) 349 | # iteration number 350 | iter = (epoch - 1) * n_train_batches + minibatch_index 351 | 352 | if (iter + 1) % validation_frequency == 0: 353 | # compute zero-one loss on validation set 354 | validation_losses = [validate_model(i) for i 355 | in xrange(n_valid_batches)] 356 | this_validation_loss = numpy.mean(validation_losses) 357 | 358 | print( 359 | 'epoch %i, minibatch %i/%i, validation error %f %%' % 360 | ( 361 | epoch, 362 | minibatch_index + 1, 363 | n_train_batches, 364 | this_validation_loss * 100. 365 | ) 366 | ) 367 | 368 | # if we got the best validation score until now 369 | if this_validation_loss < best_validation_loss: 370 | #improve patience if loss improvement is good enough 371 | if ( 372 | this_validation_loss < best_validation_loss * 373 | improvement_threshold 374 | ): 375 | patience = max(patience, iter * patience_increase) 376 | 377 | best_validation_loss = this_validation_loss 378 | best_iter = iter 379 | 380 | # test it on the test set 381 | test_losses = [test_model(i) for i 382 | in xrange(n_test_batches)] 383 | test_score = numpy.mean(test_losses) 384 | 385 | print((' epoch %i, minibatch %i/%i, test error of ' 386 | 'best model %f %%') % 387 | (epoch, minibatch_index + 1, n_train_batches, 388 | test_score * 100.)) 389 | 390 | if patience <= iter: 391 | done_looping = True 392 | break 393 | 394 | end_time = time.clock() 395 | print(('Optimization complete. Best validation score of %f %% ' 396 | 'obtained at iteration %i, with test performance %f %%') % 397 | (best_validation_loss * 100., best_iter + 1, test_score * 100.)) 398 | print >> sys.stderr, ('The code for file ' + 399 | os.path.split(__file__)[1] + 400 | ' ran for %.2fm' % ((end_time - start_time) / 60.)) 401 | 402 | 403 | if __name__ == '__main__': 404 | test_mlp() 405 | -------------------------------------------------------------------------------- /cnn/mlp.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/mlp.pyc -------------------------------------------------------------------------------- /cnn/morb/__init__.py: -------------------------------------------------------------------------------- 1 | import base 2 | import parameters 3 | import units 4 | import rbms 5 | import stats 6 | import trainers 7 | import updaters 8 | import monitors 9 | import samplers 10 | import activation_functions 11 | import misc 12 | import objectives 13 | 14 | __all__ = ['base', 'parameters', 'units', 'rbms', 'stats', 'trainers', 15 | 'updaters', 'monitors', 'samplers', 'activation_functions', 16 | 'misc', 'objectives'] 17 | -------------------------------------------------------------------------------- /cnn/morb/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/__init__.pyc -------------------------------------------------------------------------------- /cnn/morb/activation_functions.py: -------------------------------------------------------------------------------- 1 | import theano 2 | import theano.tensor as T 3 | 4 | ## common activation functions 5 | 6 | sigmoid = T.nnet.sigmoid 7 | 8 | def softmax(x): 9 | # expected input dimensions: 10 | # 0 = minibatches 11 | # 1 = units 12 | # 2 = states 13 | 14 | r = x.reshape((x.shape[0]*x.shape[1], x.shape[2])) 15 | # r 0 = minibatches * units 16 | # r 1 = states 17 | 18 | # this is the expected input for theano.nnet.softmax 19 | s = T.nnet.softmax(r) 20 | 21 | # reshape back to original shape 22 | return s.reshape(x.shape) 23 | 24 | def softmax_with_zero(x): 25 | # expected input dimensions: 26 | # 0 = minibatches 27 | # 1 = units 28 | # 2 = states 29 | 30 | r = x.reshape((x.shape[0]*x.shape[1], x.shape[2])) 31 | # r 0 = minibatches * units 32 | # r 1 = states 33 | r0 = T.concatenate([r, T.zeros_like(r)[:, 0:1]], axis=1) # add row of zeros for zero energy state 34 | 35 | # this is the expected input for theano.nnet.softmax 36 | p0 = T.nnet.softmax(r0) 37 | 38 | # reshape back to original shape, but with the added state 39 | return p0.reshape((x.shape[0], x.shape[1], x.shape[2] + 1)) 40 | 41 | 42 | -------------------------------------------------------------------------------- /cnn/morb/activation_functions.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/activation_functions.pyc -------------------------------------------------------------------------------- /cnn/morb/base.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/base.pyc -------------------------------------------------------------------------------- /cnn/morb/factors.py: -------------------------------------------------------------------------------- 1 | import theano.tensor as T 2 | from morb.base import Parameters 3 | 4 | from operator import mul 5 | 6 | # general 'Factor' implementation that can represent factored parameters by 7 | # combining other types of parameters. This could be used to implement a 8 | # factored convolutional RBM or something, or an n-way factored RBM with n >= 2. 9 | 10 | # The idea is that the 'Factor' object acts as an RBM and Units proxy for the 11 | # contained Parameters, and is used as a Parameters object within the RBM. 12 | 13 | # The Parameters contained within the Factor MUST NOT be added to the RBM, 14 | # because their joint energy term is not linear in each of the individual 15 | # factored parameter sets (but rather multiplicative). Adding them to the 16 | # RBM would cause them to contribute an energy term, which doesn't make sense. 17 | 18 | # TODO: an uninitialised factor typically just results in bogus results, it doesn't 19 | # raise any exceptions. This isn't very clean. Maybe find a way around this. 20 | 21 | class Factor(Parameters): 22 | """ 23 | A 'factor' can be used to construct factored parameters from other 24 | Parameters instances. 25 | """ 26 | def __init__(self, rbm, name=None): 27 | super(Factor, self).__init__(rbm, [], name=name) 28 | # units_list is initially empty, but is expanded later by adding Parameters. 29 | self.variables = [] # same for variables 30 | self.params_list = [] 31 | self.terms = {} 32 | self.energy_gradients = {} # careful, this is now a dict of LISTS to support parameter tying. 33 | self.energy_gradient_sums = {} # same here! 34 | self.initialized = False 35 | 36 | def check_initialized(self): 37 | if not self.initialized: 38 | raise RuntimeError("Factor '%s' has not been initialized." % self.name) 39 | 40 | def factor_product(self, params, vmap): 41 | """ 42 | The factor product needed to compute the activation of the other units 43 | tied by Parameters params. 44 | """ 45 | # get all Parameters except for the given instance 46 | fp_params_list = list(self.params_list) # make a copy 47 | fp_params_list.remove(params) # remove the given instance 48 | 49 | # compute activation terms of the factor 50 | activations = [fp_params.terms[self](vmap) for fp_params in fp_params_list] 51 | 52 | # multiply the activation terms 53 | return reduce(mul, activations) 54 | 55 | def update_terms(self, params): 56 | """ 57 | Add activation terms for the units associated with Parameters instance params 58 | """ 59 | ul = list(params.units_list) # copy 60 | ul.remove(self) 61 | for u in ul: 62 | def term(vmap): 63 | fp = self.factor_product(params, vmap) # compute factor values 64 | fvmap = vmap.copy() 65 | fvmap.update({ self: fp }) # insert them in a vmap copy 66 | return params.terms[u](fvmap) # pass the copy to the Parameters instance so it can compute its activation 67 | self.terms[u] = term 68 | 69 | def update_energy_gradients(self, params): 70 | """ 71 | Add/update energy gradients for the variables associated with Parameters instance params 72 | """ 73 | for var in params.variables: 74 | def grad(vmap): 75 | fp = self.factor_product(params, vmap) # compute factor values 76 | fvmap = vmap.copy() 77 | fvmap.update({ self: fp }) # insert them in a vmap copy 78 | return params.energy_gradient_for(var, fvmap) 79 | 80 | def grad_sum(vmap): 81 | fp = self.factor_product(params, vmap) # compute factor values 82 | fvmap = vmap.copy() 83 | fvmap.update({ self: fp }) # insert them in a vmap copy 84 | return params.energy_gradient_sum_for(var, fvmap) 85 | 86 | if var not in self.energy_gradients: 87 | self.energy_gradients[var] = [] 88 | self.energy_gradient_sums[var] = [] 89 | self.energy_gradients[var].append(grad) 90 | self.energy_gradient_sums[var].append(grad_sum) 91 | 92 | def activation_term_for(self, units, vmap): 93 | self.check_initialized() 94 | return self.terms[units](vmap) 95 | 96 | def energy_gradient_for(self, variable, vmap): 97 | self.check_initialized() 98 | return sum(f(vmap) for f in self.energy_gradients[variable]) # sum all contributions 99 | 100 | def energy_gradient_sum_for(self, variable, vmap): 101 | self.check_initialized() 102 | return sum(f(vmap) for f in self.energy_gradient_sums[variable]) # sum all contributions 103 | 104 | def energy_term(self, vmap): 105 | """ 106 | The energy term of the factor, which is the product of all activation 107 | terms of the factor from the contained Parameters instances. 108 | """ 109 | self.check_initialized() 110 | factor_activations = [params.terms[self](vmap) for params in self.params_list] 111 | return T.sum(reduce(mul, factor_activations)) 112 | 113 | def initialize(self): 114 | """ 115 | Extract Units instances and variables from each contained Parameters 116 | instance. Unfortunately there is no easy way to do this automatically 117 | when the Parameters instances are created, because the add_parameters 118 | method is called before they are fully initialised. 119 | """ 120 | if self.initialized: # don't initialize multiple times 121 | return # TODO: maybe this should raise a warning? 122 | 123 | for params in self.params_list: 124 | self.variables.extend(params.variables) 125 | units_list = list(params.units_list) 126 | units_list.remove(self) 127 | self.units_list.extend(units_list) 128 | self.update_terms(params) 129 | self.update_energy_gradients(params) 130 | 131 | self.initialized = True 132 | 133 | def add_parameters(self, params): 134 | """ 135 | This method is called by the Parameters constructor when the 'rbm' 136 | argument is substituted for a Factor instance. 137 | """ 138 | self.params_list.append(params) 139 | 140 | def __repr__(self): 141 | units_names = ", ".join(("'%s'" % u.name) for u in self.units_list) 142 | return "" % (self.name, units_names) 143 | 144 | -------------------------------------------------------------------------------- /cnn/morb/misc.py: -------------------------------------------------------------------------------- 1 | # miscellaneous utility functions 2 | 3 | import theano 4 | from theano import tensor 5 | import numpy 6 | 7 | 8 | def tensordot(a, b, axes=2): 9 | """ 10 | implementation of tensordot that reduces to a regular matrix product. This allows tensordot to be GPU accelerated, 11 | which isn't possible with the default Theano implementation (which is just a wrapper around numpy.tensordot). 12 | based on code from Tijmen Tieleman's gnumpy http://www.cs.toronto.edu/~tijmen/gnumpy.html 13 | """ 14 | if numpy.isscalar(axes): 15 | # if 'axes' is a number of axes to multiply and sum over (trailing axes 16 | # of a, leading axes of b), we can just reshape and use dot. 17 | outshape = tensor.concatenate([a.shape[:a.ndim - axes], b.shape[axes:]]) 18 | outndim = a.ndim + b.ndim - 2*axes 19 | a_reshaped = a.reshape((tensor.prod(a.shape[:a.ndim - axes]), tensor.prod(a.shape[a.ndim - axes:]))) 20 | b_reshaped = b.reshape((tensor.prod(b.shape[:axes]), tensor.prod(b.shape[axes:]))) 21 | return tensor.dot(a_reshaped, b_reshaped).reshape(outshape, ndim=outndim) 22 | elif len(axes) == 2: 23 | # if 'axes' is a pair of axis lists, we first shuffle the axes of a and 24 | # b to reduce this to the first case (note the recursion). 25 | a_other, b_other = tuple(axes[0]), tuple(axes[1]) 26 | num_axes = len(a_other) 27 | a_order = tuple(x for x in tuple(xrange(a.ndim)) if x not in a_other) + a_other 28 | b_order = b_other + tuple(x for x in tuple(xrange(b.ndim)) if x not in b_other) 29 | a_shuffled = a.dimshuffle(a_order) 30 | b_shuffled = b.dimshuffle(b_order) 31 | return tensordot(a_shuffled, b_shuffled, num_axes) 32 | else: 33 | raise ValueError("Axes should be scalar valued or a list/tuple of len 2.") 34 | -------------------------------------------------------------------------------- /cnn/morb/misc.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/misc.pyc -------------------------------------------------------------------------------- /cnn/morb/monitors.py: -------------------------------------------------------------------------------- 1 | import theano 2 | import theano.tensor as T 3 | 4 | 5 | def reconstruction_mse(stats, u): 6 | data = stats['data'][u] 7 | reconstruction = stats['model'][u] 8 | return T.mean((data - reconstruction) ** 2) 9 | 10 | def reconstruction_error_rate(stats, u): 11 | data = stats['data'][u] 12 | reconstruction = stats['model'][u] 13 | return T.mean(T.neq(data, reconstruction)) 14 | 15 | def reconstruction_crossentropy(stats, u): 16 | data = stats['data'][u] 17 | reconstruction_activation = stats['model_activation'][u] 18 | return T.mean(T.sum(data*T.log(T.nnet.sigmoid(reconstruction_activation)) + 19 | (1 - data)*T.log(1 - T.nnet.sigmoid(reconstruction_activation)), axis=1)) 20 | # without optimisation: 21 | # return T.mean(T.sum(data*T.log(reconstruction) + (1 - data)*T.log(reconstruction), axis=1)) 22 | # see http://deeplearning.net/tutorial/rbm.html, below the gibbs_hvh and gibbs_vhv code for an explanation. 23 | 24 | 25 | 26 | # TODO: pseudo likelihood? is that feasible? 27 | 28 | 29 | -------------------------------------------------------------------------------- /cnn/morb/monitors.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/monitors.pyc -------------------------------------------------------------------------------- /cnn/morb/objectives.py: -------------------------------------------------------------------------------- 1 | import theano 2 | import theano.tensor as T 3 | 4 | import samplers 5 | 6 | 7 | #def autoencoder(rbm, vmap, visible_units, hidden_units, context_units=[]): 8 | # """ 9 | # Takes an RBM that consists only of units that implement mean field. 10 | # The means of these units will be treated as activations of an autoencoder. 11 | # 12 | # Note that this can only be used for autoencoders with tied weights. 13 | # 14 | # input 15 | # rbm: the RBM object 16 | # vmap: a vmap dictionary of input units instances of the RBM mapped to theano expressions. 17 | # visible_units: a list of input units, the autoencoder will attempt to reconstruct these 18 | # hidden_units: the hidden layer of the autoencoder 19 | # 20 | # context units should simply be added in the vmap, they need not be specified. 21 | # 22 | # output 23 | # a vmap dictionary giving the reconstructions. 24 | # """ 25 | # 26 | # # complete units lists 27 | # visible_units = rbm.complete_units_list(visible_units) 28 | # hidden_units = rbm.complete_units_list(hidden_units) 29 | # 30 | # # complete the supplied vmap 31 | # vmap = rbm.complete_vmap(vmap) 32 | # 33 | # hidden_vmap = rbm.mean_field(hidden_units, vmap) 34 | # hidden_vmap.update(vmap) # we can just add the supplied vmap to the hidden vmap to 35 | # # ensure that any context units are also in the hidden vmap. We do not run the risk 36 | # # of 'overwriting' anything since the hiddens and the visibles are disjoint. 37 | # # note that the hidden vmap need not be completed, since the hidden_units list 38 | # # has already been completed. 39 | # reconstruction_vmap = rbm.mean_field(visible_units, hidden_vmap) 40 | # 41 | # return reconstruction_vmap 42 | 43 | 44 | 45 | ### autoencoder objective + utilities ### 46 | 47 | def autoencoder(rbm, visible_units, hidden_units, v0_vmap, v0_vmap_source=None): 48 | """ 49 | Implements the autoencoder objective: the log likelihood of the visibles given the hiddens, 50 | where the hidden values are obtained using mean field. 51 | 52 | The last argument, v0_vmap_source, allows for using inputs that are different than the targets. 53 | This is useful for implementing denoising regularisation. 54 | """ 55 | if v0_vmap_source is None: 56 | v0_vmap_source = v0_vmap # default to using the same input as source and target 57 | 58 | full_vmap_source = rbm.complete_vmap(v0_vmap_source) 59 | full_vmap = rbm.complete_vmap(v0_vmap) 60 | # add the conditional means for the hidden units to the vmap 61 | for hu in hidden_units: 62 | full_vmap_source[hu] = hu.mean_field(v0_vmap_source) 63 | 64 | # add any missing proxies of the hiddens (unlikely, but you never know) 65 | full_vmap_source = rbm.complete_vmap(full_vmap_source) 66 | 67 | # get log probs of all the visibles 68 | log_prob_terms = [] 69 | for vu in visible_units: 70 | activation_vmap_source = { vu: vu.activation(full_vmap_source) } 71 | lp = vu.log_prob_from_activation(full_vmap, activation_vmap_source) 72 | log_prob_terms.append(T.sum(T.mean(lp, 0))) # mean over the minibatch dimension 73 | 74 | total_log_prob = sum(log_prob_terms) 75 | 76 | return total_log_prob 77 | 78 | 79 | 80 | def mean_reconstruction(rbm, visible_units, hidden_units, v0_vmap): 81 | """ 82 | Computes the mean reconstruction for a given RBM and a set of visibles and hiddens. 83 | E[v|h] with h = E[h|v]. 84 | 85 | input 86 | rbm: the RBM object 87 | vmap: a vmap dictionary of input units instances of the RBM mapped to theano expressions. 88 | visible_units: a list of input units 89 | hidden_units: the hidden layer of the autoencoder 90 | 91 | context units should simply be added in the vmap, they need not be specified. 92 | 93 | output 94 | a vmap dictionary giving the reconstructions. 95 | 96 | NOTE: this vmap may contain more than just the requested values, because the 'visible_units' 97 | units list is completed with all proxies. So it's probably not a good idea to iterate over 98 | the output vmap. 99 | """ 100 | 101 | # complete units lists 102 | visible_units = rbm.complete_units_list(visible_units) 103 | hidden_units = rbm.complete_units_list(hidden_units) 104 | 105 | # complete the supplied vmap 106 | v0_vmap = rbm.complete_vmap(v0_vmap) 107 | 108 | hidden_vmap = rbm.mean_field(hidden_units, v0_vmap) 109 | hidden_vmap.update(v0_vmap) # we can just add the supplied vmap to the hidden vmap to 110 | # ensure that any context units are also in the hidden vmap. We do not run the risk 111 | # of 'overwriting' anything since the hiddens and the visibles are disjoint. 112 | # note that the hidden vmap need not be completed, since the hidden_units list 113 | # has already been completed. 114 | reconstruction_vmap = rbm.mean_field(visible_units, hidden_vmap) 115 | 116 | return reconstruction_vmap 117 | 118 | 119 | 120 | ### regularisation ### 121 | 122 | def sparsity_penalty(rbm, hidden_units, v0_vmap, target): 123 | """ 124 | Implements a cross-entropy sparsity penalty. Note that this only really makes sense if the hidden units are binary. 125 | """ 126 | # complete units lists 127 | hidden_units = rbm.complete_units_list(hidden_units) 128 | 129 | # complete the supplied vmap 130 | v0_vmap = rbm.complete_vmap(v0_vmap) 131 | 132 | hidden_vmap = rbm.mean_field(hidden_units, v0_vmap) 133 | 134 | penalty_terms = [] 135 | for hu in hidden_units: 136 | mean_activation = T.mean(hidden_vmap[hu], 0) # mean over minibatch dimension 137 | penalty_terms.append(T.sum(T.nnet.binary_crossentropy(mean_activation, target))) # sum over the features 138 | 139 | total_penalty = sum(penalty_terms) 140 | return total_penalty 141 | 142 | 143 | ### input corruption ### 144 | 145 | def corrupt_masking(v, corruption_level): 146 | return samplers.theano_rng.binomial(size=v.shape, n=1, p=1 - corruption_level, dtype=theano.config.floatX) * v 147 | 148 | def corrupt_salt_and_pepper(v, corruption_level): 149 | mask = samplers.theano_rng.binomial(size=v.shape, n=1, p=1 - corruption_level, dtype=theano.config.floatX) 150 | rand = samplers.theano_rng.binomial(size=v.shape, n=1, p=0.5, dtype=theano.config.floatX) 151 | return mask * v + (1 - mask) * rand 152 | 153 | def corrupt_gaussian(v, std): 154 | noise = samplers.theano_rng.normal(size=v.shape, avg=0.0, std=std, dtype=theano.config.floatX) 155 | return v + noise 156 | 157 | 158 | 159 | ### common error measures ### 160 | 161 | def mse(units_list, vmap_targets, vmap_predictions): 162 | """ 163 | Computes the mean square error between two vmaps representing data 164 | and reconstruction. 165 | 166 | units_list: list of input units instances 167 | vmap_targets: vmap dictionary containing targets 168 | vmap_predictions: vmap dictionary containing model predictions 169 | """ 170 | return sum(T.mean((vmap_targets[u] - vmap_predictions[u]) ** 2) for u in units_list) 171 | 172 | 173 | def cross_entropy(units_list, vmap_targets, vmap_predictions): 174 | """ 175 | Computes the cross entropy error between two vmaps representing data 176 | and reconstruction. 177 | 178 | units_list: list of input units instances 179 | vmap_targets: vmap dictionary containing targets 180 | vmap_predictions: vmap dictionary containing model predictions 181 | """ 182 | t, p = vmap_targets, vmap_predictions 183 | return sum((- t[u] * T.log(p[u]) - (1 - t[u]) * T.log(1 - p[u])) for u in units_list) 184 | 185 | 186 | -------------------------------------------------------------------------------- /cnn/morb/objectives.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/objectives.pyc -------------------------------------------------------------------------------- /cnn/morb/parameters.py: -------------------------------------------------------------------------------- 1 | from morb.base import Parameters 2 | 3 | import theano 4 | import theano.tensor as T 5 | from theano.tensor.nnet import conv 6 | 7 | from morb.misc import tensordot # better tensordot implementation that can be GPU accelerated 8 | # tensordot = T.tensordot # use theano implementation 9 | 10 | class FixedBiasParameters(Parameters): 11 | # Bias fixed at -1, which is useful for some energy functions (like Gaussian with fixed variance, Beta) 12 | def __init__(self, rbm, units, name=None): 13 | super(FixedBiasParameters, self).__init__(rbm, [units], name=name) 14 | self.variables = [] 15 | self.u = units 16 | 17 | self.terms[self.u] = lambda vmap: T.constant(-1, theano.config.floatX) # T.constant is necessary so scan doesn't choke on it 18 | 19 | def energy_term(self, vmap): 20 | s = vmap[self.u] 21 | return T.sum(s, axis=range(1, s.ndim)) # NO minus sign! bias is -1 so this is canceled. 22 | # sum over all but the minibatch dimension. 23 | 24 | 25 | class ProdParameters(Parameters): 26 | def __init__(self, rbm, units_list, W, name=None): 27 | super(ProdParameters, self).__init__(rbm, units_list, name=name) 28 | assert len(units_list) == 2 29 | self.var = W 30 | self.variables = [self.var] 31 | self.vu = units_list[0] 32 | self.hu = units_list[1] 33 | 34 | self.terms[self.vu] = lambda vmap: T.dot(vmap[self.hu], W.T) 35 | self.terms[self.hu] = lambda vmap: T.dot(vmap[self.vu], W) 36 | 37 | self.energy_gradients[self.var] = lambda vmap: vmap[self.vu].dimshuffle(0, 1, 'x') * vmap[self.hu].dimshuffle(0, 'x', 1) 38 | self.energy_gradient_sums[self.var] = lambda vmap: T.dot(vmap[self.vu].T, vmap[self.hu]) 39 | 40 | def energy_term(self, vmap): 41 | return - T.sum(self.terms[self.hu](vmap) * vmap[self.hu], axis=1) 42 | # return - T.sum(T.dot(vmap[self.vu], self.var) * vmap[self.hu]) 43 | # T.sum sums over the hiddens dimension. 44 | 45 | 46 | class BiasParameters(Parameters): 47 | def __init__(self, rbm, units, b, name=None): 48 | super(BiasParameters, self).__init__(rbm, [units], name=name) 49 | self.var = b 50 | self.variables = [self.var] 51 | self.u = units 52 | 53 | self.terms[self.u] = lambda vmap: self.var 54 | 55 | self.energy_gradients[self.var] = lambda vmap: vmap[self.u] 56 | 57 | def energy_term(self, vmap): 58 | return - T.dot(vmap[self.u], self.var) 59 | # bias is NOT TRANSPOSED because it's a vector, and apparently vectors are COLUMN vectors by default. 60 | 61 | 62 | class AdvancedProdParameters(Parameters): 63 | def __init__(self, rbm, units_list, dimensions_list, W, name=None): 64 | super(AdvancedProdParameters, self).__init__(rbm, units_list, name=name) 65 | assert len(units_list) == 2 66 | self.var = W 67 | self.variables = [self.var] 68 | self.vu = units_list[0] 69 | self.hu = units_list[1] 70 | self.vd = dimensions_list[0] 71 | self.hd = dimensions_list[1] 72 | self.vard = self.vd + self.hd 73 | 74 | # there are vd visible dimensions and hd hidden dimensions, meaning that the weight matrix has 75 | # vd + hd = Wd dimensions. 76 | # the hiddens and visibles have hd+1 and vd+1 dimensions respectively, because the first dimension 77 | # is reserved for minibatches! 78 | self.terms[self.vu] = lambda vmap: tensordot(vmap[self.hu], W, axes=(range(1,self.hd+1),range(self.vd, self.vard))) 79 | self.terms[self.hu] = lambda vmap: tensordot(vmap[self.vu], W, axes=(range(1,self.vd+1),range(0, self.vd))) 80 | 81 | def gradient(vmap): 82 | v_indices = range(0, self.vd + 1) + (['x'] * self.hd) 83 | h_indices = [0] + (['x'] * self.vd) + range(1, self.hd + 1) 84 | v_reshaped = vmap[self.vu].dimshuffle(v_indices) 85 | h_reshaped = vmap[self.hu].dimshuffle(h_indices) 86 | return v_reshaped * h_reshaped 87 | 88 | self.energy_gradients[self.var] = gradient 89 | self.energy_gradient_sums[self.var] = lambda vmap: tensordot(vmap[self.vu], vmap[self.hu], axes=([0],[0])) 90 | # only sums out the minibatch dimension. 91 | 92 | def energy_term(self, vmap): 93 | # v_part = tensordot(vmap[self.vu], self.var, axes=(range(1, self.vd+1), range(0, self.vd))) 94 | v_part = self.terms[self.hu](vmap) 95 | neg_energy = tensordot(v_part, vmap[self.hu], axes=(range(1, self.hd+1), range(1, self.hd+1))) 96 | # we do not sum over the first dimension, which is reserved for minibatches! 97 | return - neg_energy # don't forget to flip the sign! 98 | 99 | 100 | class AdvancedBiasParameters(Parameters): 101 | def __init__(self, rbm, units, dimensions, b, name=None): 102 | super(AdvancedBiasParameters, self).__init__(rbm, [units], name=name) 103 | self.var = b 104 | self.variables = [self.var] 105 | self.u = units 106 | self.ud = dimensions 107 | 108 | self.terms[self.u] = lambda vmap: self.var 109 | 110 | self.energy_gradients[self.var] = lambda vmap: vmap[self.u] 111 | 112 | def energy_term(self, vmap): 113 | return - tensordot(vmap[self.u], self.var, axes=(range(1, self.ud+1), range(0, self.ud))) 114 | 115 | 116 | class SharedBiasParameters(Parameters): 117 | """ 118 | like AdvancedBiasParameters, but a given number of trailing dimensions are 'shared'. 119 | """ 120 | def __init__(self, rbm, units, dimensions, shared_dimensions, b, name=None): 121 | super(SharedBiasParameters, self).__init__(rbm, [units], name=name) 122 | self.var = b 123 | self.variables = [self.var] 124 | self.u = units 125 | self.ud = dimensions 126 | self.sd = shared_dimensions 127 | self.nd = self.ud - self.sd 128 | 129 | self.terms[self.u] = lambda vmap: T.shape_padright(self.var, self.sd) 130 | 131 | self.energy_gradients[self.var] = lambda vmap: T.mean(vmap[self.u], axis=self._shared_axes(vmap)) 132 | 133 | def _shared_axes(self, vmap): 134 | d = vmap[self.u].ndim 135 | return range(d - self.sd, d) 136 | 137 | def energy_term(self, vmap): 138 | # b_padded = T.shape_padright(self.var, self.sd) 139 | # return - T.sum(tensordot(vmap[self.u], b_padded, axes=(range(1, self.ud+1), range(0, self.ud))), axis=0) 140 | # this does not work because tensordot cannot handle broadcastable dimensions. 141 | # instead, the dimensions of b_padded which are broadcastable should be summed out afterwards. 142 | # this comes down to the same thing. so: 143 | t = tensordot(vmap[self.u], self.var, axes=(range(1, self.nd+1), range(0, self.nd))) 144 | # now sum t over its trailing shared dimensions, which mimics broadcast + tensordot behaviour. 145 | axes = range(t.ndim - self.sd, t.ndim) 146 | return - T.sum(t, axis=axes) 147 | 148 | 149 | class Convolutional2DParameters(Parameters): 150 | def __init__(self, rbm, units_list, W, shape_info=None, name=None): 151 | # use the shape_info parameter to provide a dict with keys: 152 | # hidden_maps, visible_maps, filter_height, filter_width, visible_height, visible_width, mb_size 153 | 154 | super(Convolutional2DParameters, self).__init__(rbm, units_list, name=name) 155 | assert len(units_list) == 2 156 | self.var = W # (hidden_maps, visible_maps, filter_height, filter_width) 157 | self.variables = [self.var] 158 | self.vu = units_list[0] # (mb_size, visible_maps, visible_height, visible_width) 159 | self.hu = units_list[1] # (mb_size, hidden_maps, hidden_height, hidden_width) 160 | self.shape_info = shape_info 161 | 162 | # conv input is (output_maps, input_maps, filter height [numrows], filter width [numcolumns]) 163 | # conv input is (mb_size, input_maps, input height [numrows], input width [numcolumns]) 164 | # conv output is (mb_size, output_maps, output height [numrows], output width [numcolumns]) 165 | 166 | def term_vu(vmap): 167 | # input = hiddens, output = visibles so we need to swap dimensions 168 | W_shuffled = self.var.dimshuffle(1, 0, 2, 3) 169 | if self.filter_shape is not None: 170 | shuffled_filter_shape = [self.filter_shape[k] for k in (1, 0, 2, 3)] 171 | else: 172 | shuffled_filter_shape = None 173 | return conv.conv2d(vmap[self.hu], W_shuffled, border_mode='full', \ 174 | image_shape=self.hidden_shape, filter_shape=shuffled_filter_shape) 175 | 176 | def term_hu(vmap): 177 | # input = visibles, output = hiddens, flip filters 178 | W_flipped = self.var[:, :, ::-1, ::-1] 179 | return conv.conv2d(vmap[self.vu], W_flipped, border_mode='valid', \ 180 | image_shape=self.visible_shape, filter_shape=self.filter_shape) 181 | 182 | self.terms[self.vu] = term_vu 183 | self.terms[self.hu] = term_hu 184 | 185 | def gradient(vmap): 186 | raise NotImplementedError # TODO 187 | 188 | def gradient_sum(vmap): 189 | if self.visible_shape is not None: 190 | i_shape = [self.visible_shape[k] for k in [1, 0, 2, 3]] 191 | else: 192 | i_shape = None 193 | 194 | if self.hidden_shape is not None: 195 | f_shape = [self.hidden_shape[k] for k in [1, 0, 2, 3]] 196 | else: 197 | f_shape = None 198 | 199 | v_shuffled = vmap[self.vu].dimshuffle(1, 0, 2, 3) 200 | h_shuffled = vmap[self.hu].dimshuffle(1, 0, 2, 3) 201 | 202 | c = conv.conv2d(v_shuffled, h_shuffled, border_mode='valid', image_shape=i_shape, filter_shape=f_shape) 203 | return c.dimshuffle(1, 0, 2, 3) 204 | 205 | self.energy_gradients[self.var] = gradient 206 | self.energy_gradient_sums[self.var] = gradient_sum 207 | 208 | @property 209 | def filter_shape(self): 210 | keys = ['hidden_maps', 'visible_maps', 'filter_height', 'filter_width'] 211 | if self.shape_info is not None and all(k in self.shape_info for k in keys): 212 | return tuple(self.shape_info[k] for k in keys) 213 | else: 214 | return None 215 | 216 | @property 217 | def visible_shape(self): 218 | keys = ['mb_size', 'visible_maps', 'visible_height', 'visible_width'] 219 | if self.shape_info is not None and all(k in self.shape_info for k in keys): 220 | return tuple(self.shape_info[k] for k in keys) 221 | else: 222 | return None 223 | 224 | @property 225 | def hidden_shape(self): 226 | keys = ['mb_size', 'hidden_maps', 'visible_height', 'visible_width'] 227 | if self.shape_info is not None and all(k in self.shape_info for k in keys): 228 | hidden_height = self.shape_info['visible_height'] - self.shape_info['filter_height'] + 1 229 | hidden_width = self.shape_info['visible_width'] - self.shape_info['filter_width'] + 1 230 | return (self.shape_info['mb_size'], self.shape_info['hidden_maps'], hidden_height, hidden_width) 231 | else: 232 | return None 233 | 234 | def energy_term(self, vmap): 235 | return - T.sum(self.terms[self.hu](vmap) * vmap[self.hu], axis=[1,2,3]) 236 | # sum over all but the minibatch axis 237 | 238 | 239 | 240 | 241 | # TODO: 1D convolution + optimisation 242 | 243 | 244 | 245 | 246 | class ThirdOrderParameters(Parameters): 247 | def __init__(self, rbm, units_list, W, name=None): 248 | super(ThirdOrderParameters, self).__init__(rbm, units_list, name=name) 249 | assert len(units_list) == 3 250 | self.var = W 251 | self.variables = [self.var] 252 | self.u0 = units_list[0] 253 | self.u1 = units_list[1] 254 | self.u2 = units_list[2] 255 | 256 | def term_u0(vmap): 257 | p = tensordot(vmap[self.u1], W, axes=([1],[1])) # (mb, u0, u2) 258 | return T.sum(p * vmap[self.u2].dimshuffle(0, 'x', 1), axis=2) # (mb, u0) 259 | # cannot use two tensordots here because of the minibatch dimension. 260 | 261 | def term_u1(vmap): 262 | p = tensordot(vmap[self.u0], W, axes=([1],[0])) # (mb, u1, u2) 263 | return T.sum(p * vmap[self.u2].dimshuffle(0, 'x', 1), axis=2) # (mb, u1) 264 | 265 | def term_u2(vmap): 266 | p = tensordot(vmap[self.u0], W, axes=([1],[0])) # (mb, u1, u2) 267 | return T.sum(p * vmap[self.u1].dimshuffle(0, 1, 'x'), axis=1) # (mb, u2) 268 | 269 | self.terms[self.u0] = term_u0 270 | self.terms[self.u1] = term_u1 271 | self.terms[self.u2] = term_u2 272 | 273 | def gradient(vmap): 274 | p = vmap[self.u0].dimshuffle(0, 1, 'x') * vmap[self.u1].dimshuffle(0, 'x', 1) # (mb, u0, u1) 275 | p2 = p.dimshuffle(0, 1, 2, 'x') * vmap[self.u2].dimshuffle(0, 'x', 'x', 1) # (mb, u0, u1, u2) 276 | return p2 277 | 278 | self.energy_gradients[self.var] = gradient 279 | 280 | def energy_term(self, vmap): 281 | return - T.sum(self.terms[self.u1](vmap) * vmap[self.u1], axis=1) 282 | # sum is over the u1 dimension, not the minibatch dimension! 283 | 284 | 285 | 286 | 287 | class ThirdOrderFactoredParameters(Parameters): 288 | """ 289 | Factored 3rd order parameters, connecting three Units instances. Each factored 290 | parameter matrix has dimensions (units_size, num_factors). 291 | """ 292 | def __init__(self, rbm, units_list, variables, name=None): 293 | super(ThirdOrderFactoredParameters, self).__init__(rbm, units_list, name=name) 294 | assert len(units_list) == 3 295 | assert len(variables) == 3 296 | self.variables = variables 297 | self.var0 = variables[0] 298 | self.var1 = variables[1] 299 | self.var2 = variables[2] 300 | self.u0 = units_list[0] 301 | self.u1 = units_list[1] 302 | self.u2 = units_list[2] 303 | self.prod0 = lambda vmap: T.dot(vmap[self.u0], self.var0) # (mb, f) 304 | self.prod1 = lambda vmap: T.dot(vmap[self.u1], self.var1) # (mb, f) 305 | self.prod2 = lambda vmap: T.dot(vmap[self.u2], self.var2) # (mb, f) 306 | self.terms[self.u0] = lambda vmap: T.dot(self.prod1(vmap) * self.prod2(vmap), self.var0.T) # (mb, u0) 307 | self.terms[self.u1] = lambda vmap: T.dot(self.prod0(vmap) * self.prod2(vmap), self.var1.T) # (mb, u1) 308 | self.terms[self.u2] = lambda vmap: T.dot(self.prod0(vmap) * self.prod1(vmap), self.var2.T) # (mb, u2) 309 | 310 | # if the same parameter variable is used multiple times, the energy gradients should be added. 311 | # so we need a little bit of trickery here to make this work. 312 | energy_gradient_sums_list = [ 313 | lambda vmap: T.dot(vmap[self.u0].T, self.prod1(vmap) * self.prod2(vmap)), # (u0, f) 314 | lambda vmap: T.dot(vmap[self.u1].T, self.prod0(vmap) * self.prod2(vmap)), # (u1, f) 315 | lambda vmap: T.dot(vmap[self.u2].T, self.prod0(vmap) * self.prod1(vmap)), # (u2, f) 316 | ] # the T.dot also sums out the minibatch dimension 317 | 318 | energy_gradient_sums_dict = {} 319 | for var, grad in zip(self.variables, energy_gradient_sums_list): 320 | if var not in energy_gradient_sums_dict: 321 | energy_gradient_sums_dict[var] = [] 322 | energy_gradient_sums_dict[var].append(grad) 323 | 324 | for var, grad_list in energy_gradient_sums_dict.items(): 325 | def tmp(): # create a closure, otherwise grad_list will always 326 | # refer to the one of the last iteration! 327 | # TODO: this is nasty, is there a cleaner way? 328 | g = grad_list 329 | self.energy_gradient_sums[var] = lambda vmap: sum(f(vmap) for f in g) 330 | tmp() 331 | 332 | # TODO: do the same for the gradient without summing! 333 | 334 | def energy_term(self, vmap): 335 | return - T.sum(self.terms[self.u1](vmap) * vmap[self.u1], axis=1) 336 | # sum is over the u1 dimension, not the minibatch dimension! 337 | 338 | 339 | 340 | 341 | class TransformedParameters(Parameters): 342 | """ 343 | Transform parameter variables, adapt gradients accordingly 344 | """ 345 | def __init__(self, params, transforms, transform_gradients, name=None): 346 | """ 347 | params: a Parameters instance for which variables should be transformed 348 | transforms: a dict mapping variables to their transforms 349 | gradients: a dict mapping variables to the gradient of their transforms 350 | 351 | IMPORTANT: the original Parameters instance should not be used afterwards 352 | as it will be removed from the RBM. 353 | 354 | ALSO IMPORTANT: because of the way the chain rule is applied, the old 355 | Parameters instance is expected to be linear in the variables. 356 | 357 | Example usage: 358 | rbm = RBM(...) 359 | h = Units(...) 360 | v = Units(...) 361 | var_W = theano.shared(...) 362 | W = ProdParameters(rbm, [u, v], var_W, name='W') 363 | W_tf = TransformedParameters(W, { var_W: T.exp(var_W) }, { var_W: T.exp(var_W) }, name='W_tf') 364 | """ 365 | self.encapsulated_params = params 366 | self.transforms = transforms 367 | self.transform_gradients = transform_gradients 368 | 369 | # remove the old instance, this one will replace it 370 | params.rbm.remove_parameters(params) 371 | # TODO: it's a bit nasty that the old instance is first added to the RBM and then removed again. 372 | # maybe there is a way to prevent this? For example, giving the old parameters a 'dummy' RBM 373 | # like in the factor implementation. But then this dummy has to be initialised first... 374 | 375 | # initialise 376 | super(TransformedParameters, self).__init__(params.rbm, params.units_list, name) 377 | 378 | self.variables = params.variables 379 | for u, l in params.terms.items(): # in the terms, replace the vars by their transforms 380 | self.terms[u] = lambda vmap: theano.clone(l(vmap), transforms) 381 | 382 | for v, l in params.energy_gradients.items(): 383 | self.energy_gradients[v] = lambda vmap: l(vmap) * transform_gradients[v] # chain rule 384 | 385 | for v, l in params.energy_gradient_sums.items(): 386 | self.energy_gradient_sums[v] = lambda vmap: l(vmap) * transform_gradients[v] # chain rule 387 | 388 | def energy_term(self, vmap): 389 | old = self.encapsulated_params.energy_term(vmap) 390 | return theano.clone(old, self.transforms) 391 | 392 | 393 | -------------------------------------------------------------------------------- /cnn/morb/parameters.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/parameters.pyc -------------------------------------------------------------------------------- /cnn/morb/rbms.py: -------------------------------------------------------------------------------- 1 | from morb.base import RBM 2 | from morb import units, parameters 3 | 4 | import theano 5 | import theano.tensor as T 6 | 7 | import numpy as np 8 | 9 | 10 | ### RBMS ### 11 | 12 | class BinaryBinaryRBM(RBM): # the basic RBM, with binary visibles and binary hiddens 13 | def __init__(self, n_visible, n_hidden): 14 | super(BinaryBinaryRBM, self).__init__() 15 | # data shape 16 | self.n_visible = n_visible 17 | self.n_hidden = n_hidden 18 | # units 19 | self.v = units.BinaryUnits(self, name='v') # visibles 20 | self.h = units.BinaryUnits(self, name='h') # hiddens 21 | # parameters 22 | self.W = parameters.ProdParameters(self, [self.v, self.h], theano.shared(value = self._initial_W(), name='W'), name='W') # weights 23 | self.bv = parameters.BiasParameters(self, self.v, theano.shared(value = self._initial_bv(), name='bv'), name='bv') # visible bias 24 | self.bh = parameters.BiasParameters(self, self.h, theano.shared(value = self._initial_bh(), name='bh'), name='bh') # hidden bias 25 | 26 | def _initial_W(self): 27 | return np.asarray( np.random.uniform( 28 | low = -4*np.sqrt(6./(self.n_hidden+self.n_visible)), 29 | high = 4*np.sqrt(6./(self.n_hidden+self.n_visible)), 30 | size = (self.n_visible, self.n_hidden)), 31 | dtype = theano.config.floatX) 32 | 33 | def _initial_bv(self): 34 | return np.zeros(self.n_visible, dtype = theano.config.floatX) 35 | 36 | def _initial_bh(self): 37 | return np.zeros(self.n_hidden, dtype = theano.config.floatX) 38 | 39 | 40 | 41 | class BinaryBinaryCRBM(BinaryBinaryRBM): 42 | def __init__(self, n_visible, n_hidden, n_context): 43 | super(BinaryBinaryCRBM, self).__init__(n_visible, n_hidden) 44 | # data shape 45 | self.n_context = n_context 46 | # units 47 | self.x = units.Units(self, name='x') # context 48 | # parameters 49 | self.A = parameters.ProdParameters(self, [self.x, self.v], theano.shared(value = self._initial_A(), name='A'), name='A') # context-to-visible weights 50 | self.B = parameters.ProdParameters(self, [self.x, self.h], theano.shared(value = self._initial_B(), name='B'), name='B') # context-to-hidden weights 51 | 52 | def _initial_A(self): 53 | return np.zeros((self.n_context, self.n_visible), dtype = theano.config.floatX) 54 | 55 | def _initial_B(self): 56 | return np.zeros((self.n_context, self.n_hidden), dtype = theano.config.floatX) 57 | 58 | 59 | 60 | class GaussianBinaryRBM(RBM): # Gaussian visible units 61 | def __init__(self, n_visible, n_hidden): 62 | super(GaussianBinaryRBM, self).__init__() 63 | # data shape 64 | self.n_visible = n_visible 65 | self.n_hidden = n_hidden 66 | # units 67 | self.v = units.GaussianUnits(self, name='v') # visibles 68 | self.h = units.BinaryUnits(self, name='h') # hiddens 69 | # parameters 70 | parameters.FixedBiasParameters(self, self.v.precision_units) 71 | self.W = parameters.ProdParameters(self, [self.v, self.h], theano.shared(value = self._initial_W(), name='W'), name='W') # weights 72 | self.bv = parameters.BiasParameters(self, self.v, theano.shared(value = self._initial_bv(), name='bv'), name='bv') # visible bias 73 | self.bh = parameters.BiasParameters(self, self.h, theano.shared(value = self._initial_bh(), name='bh'), name='bh') # hidden bias 74 | 75 | def _initial_W(self): 76 | return np.asarray( np.random.uniform( 77 | low = -4*np.sqrt(6./(self.n_hidden+self.n_visible)), 78 | high = 4*np.sqrt(6./(self.n_hidden+self.n_visible)), 79 | size = (self.n_visible, self.n_hidden)), 80 | dtype = theano.config.floatX) 81 | 82 | def _initial_bv(self): 83 | return np.zeros(self.n_visible, dtype = theano.config.floatX) 84 | 85 | def _initial_bh(self): 86 | return np.zeros(self.n_hidden, dtype = theano.config.floatX) 87 | 88 | 89 | 90 | class LearntPrecisionGaussianBinaryRBM(RBM): 91 | """ 92 | Important: Wp and bvp should be constrained to be negative. 93 | """ 94 | def __init__(self, n_visible, n_hidden): 95 | super(LearntPrecisionGaussianBinaryRBM, self).__init__() 96 | # data shape 97 | self.n_visible = n_visible 98 | self.n_hidden = n_hidden 99 | # units 100 | self.v = units.LearntPrecisionGaussianUnits(self, name='v') # visibles 101 | self.h = units.BinaryUnits(self, name='h') # hiddens 102 | # parameters 103 | self.Wm = parameters.ProdParameters(self, [self.v, self.h], theano.shared(value = self._initial_W(), name='Wm'), name='Wm') # weights 104 | self.Wp = parameters.ProdParameters(self, [self.v.precision_units, self.h], theano.shared(value = -np.abs(self._initial_W())/1000, name='Wp'), name='Wp') # weights 105 | self.bvm = parameters.BiasParameters(self, self.v, theano.shared(value = self._initial_bias(self.n_visible), name='bvm'), name='bvm') # visible bias 106 | self.bvp = parameters.BiasParameters(self, self.v.precision_units, theano.shared(value = self._initial_bias(self.n_visible), name='bvp'), name='bvp') # precision bias 107 | self.bh = parameters.BiasParameters(self, self.h, theano.shared(value = self._initial_bias(self.n_hidden), name='bh'), name='bh') # hidden bias 108 | 109 | def _initial_W(self): 110 | return np.asarray( np.random.uniform( 111 | low = -4*np.sqrt(6./(self.n_hidden+self.n_visible)), 112 | high = 4*np.sqrt(6./(self.n_hidden+self.n_visible)), 113 | size = (self.n_visible, self.n_hidden)), 114 | dtype = theano.config.floatX) 115 | 116 | def _initial_bias(self, n): 117 | return np.zeros(n, dtype = theano.config.floatX) 118 | 119 | 120 | class LearntPrecisionSeparateGaussianBinaryRBM(RBM): 121 | """ 122 | Important: Wp and bvp should be constrained to be negative. 123 | This RBM models mean and precision with separate hidden units. 124 | """ 125 | def __init__(self, n_visible, n_hidden_mean, n_hidden_precision): 126 | super(LearntPrecisionSeparateGaussianBinaryRBM, self).__init__() 127 | # data shape 128 | self.n_visible = n_visible 129 | self.n_hidden_mean = n_hidden_mean 130 | self.n_hidden_precision = n_hidden_precision 131 | # units 132 | self.v = units.LearntPrecisionGaussianUnits(self, name='v') # visibles 133 | self.hm = units.BinaryUnits(self, name='hm') # hiddens for mean 134 | self.hp = units.BinaryUnits(self, name='hp') # hiddens for precision 135 | # parameters 136 | self.Wm = parameters.ProdParameters(self, [self.v, self.hm], theano.shared(value = self._initial_W(self.n_visible, self.n_hidden_mean), name='Wm'), name='Wm') # weights 137 | self.Wp = parameters.ProdParameters(self, [self.v.precision_units, self.hp], theano.shared(value = -np.abs(self._initial_W(self.n_visible, self.n_hidden_precision))/1000, name='Wp'), name='Wp') # weights 138 | self.bvm = parameters.BiasParameters(self, self.v, theano.shared(value = self._initial_bias(self.n_visible), name='bvm'), name='bvm') # visible bias 139 | self.bvp = parameters.BiasParameters(self, self.v.precision_units, theano.shared(value = self._initial_bias(self.n_visible), name='bvp'), name='bvp') # precision bias 140 | self.bhm = parameters.BiasParameters(self, self.hm, theano.shared(value = self._initial_bias(self.n_hidden_mean), name='bhm'), name='bhm') # hidden bias for mean 141 | self.bhp = parameters.BiasParameters(self, self.hp, theano.shared(value = self._initial_bias(self.n_hidden_precision)+1.0, name='bhp'), name='bhp') # hidden bias for precision 142 | 143 | def _initial_W(self, nv, nh): 144 | return np.asarray( np.random.uniform( 145 | low = -4*np.sqrt(6./(nv+nh)), 146 | high = 4*np.sqrt(6./(nv+nh)), 147 | size = (nv, nh)), 148 | dtype = theano.config.floatX) 149 | 150 | def _initial_bias(self, n): 151 | return np.zeros(n, dtype = theano.config.floatX) 152 | 153 | 154 | 155 | class TruncExpBinaryRBM(RBM): # RBM with truncated exponential visibles and binary hiddens 156 | def __init__(self, n_visible, n_hidden): 157 | super(TruncExpBinaryRBM, self).__init__() 158 | # data shape 159 | self.n_visible = n_visible 160 | self.n_hidden = n_hidden 161 | # units 162 | self.v = units.TruncatedExponentialUnits(self, name='v') # visibles 163 | self.h = units.BinaryUnits(self, name='h') # hiddens 164 | # parameters 165 | self.W = parameters.ProdParameters(self, [self.v, self.h], theano.shared(value = self._initial_W(), name='W'), name='W') # weights 166 | self.bv = parameters.BiasParameters(self, self.v, theano.shared(value = self._initial_bv(), name='bv'), name='bv') # visible bias 167 | self.bh = parameters.BiasParameters(self, self.h, theano.shared(value = self._initial_bh(), name='bh'), name='bh') # hidden bias 168 | 169 | def _initial_W(self): 170 | # return np.asarray( np.random.uniform( 171 | # low = -4*np.sqrt(6./(self.n_hidden+self.n_visible)), 172 | # high = 4*np.sqrt(6./(self.n_hidden+self.n_visible)), 173 | # size = (self.n_visible, self.n_hidden)), 174 | # dtype = theano.config.floatX) 175 | 176 | return np.asarray( np.random.normal(0, 0.01, 177 | size = (self.n_visible, self.n_hidden)), 178 | dtype = theano.config.floatX) 179 | 180 | def _initial_bv(self): 181 | return np.zeros(self.n_visible, dtype = theano.config.floatX) 182 | 183 | def _initial_bh(self): 184 | return np.zeros(self.n_hidden, dtype = theano.config.floatX) 185 | -------------------------------------------------------------------------------- /cnn/morb/rbms.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/rbms.pyc -------------------------------------------------------------------------------- /cnn/morb/samplers.py: -------------------------------------------------------------------------------- 1 | import theano 2 | import theano.tensor as T 3 | 4 | # from theano.tensor.shared_randomstreams import RandomStreams 5 | from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams # veel sneller 6 | import numpy as np 7 | 8 | numpy_rng = np.random.RandomState(123) 9 | theano_rng = RandomStreams(numpy_rng.randint(2**30)) 10 | 11 | ## samplers 12 | 13 | def bernoulli(a): 14 | # a is the bernoulli parameter 15 | return theano_rng.binomial(size=a.shape, n=1, p=a, dtype=theano.config.floatX) 16 | 17 | def gaussian(a, var=1.0): 18 | # a is the mean, var is the variance (not std or precision!) 19 | std = T.sqrt(var) 20 | return theano_rng.normal(size=a.shape, avg=a, std=std, dtype=theano.config.floatX) 21 | 22 | 23 | 24 | def multinomial(a): 25 | # 0 = minibatches 26 | # 1 = units 27 | # 2 = states 28 | p = a.reshape((a.shape[0]*a.shape[1], a.shape[2])) 29 | # r 0 = minibatches * units 30 | # r 1 = states 31 | # this is the expected input for theano.nnet.softmax and theano_rng.multinomial 32 | s = theano_rng.multinomial(n=1, pvals=p, dtype=theano.config.floatX) 33 | return s.reshape(a.shape) # reshape back to original shape 34 | 35 | 36 | def exponential(a): 37 | uniform_samples = theano_rng.uniform(size=a.shape, dtype=theano.config.floatX) 38 | return (-1 / a) * T.log(1 - uniform_samples) 39 | 40 | 41 | def truncated_exponential(a, maximum=1.0): 42 | uniform_samples = theano_rng.uniform(size=a.shape, dtype=theano.config.floatX) 43 | return (-1 / a) * T.log(1 - uniform_samples*(1 - T.exp(-a * maximum))) 44 | 45 | 46 | def truncated_exponential_mean(a, maximum=1.0): 47 | # return (1 / a) + (maximum / (1 - T.exp(maximum*a))) # this is very unstable around a=0, even for a=0.001 it's already problematic. 48 | # here is a version that switches depending on the magnitude of the input 49 | m_real = (1 / a) + (maximum / (1 - T.exp(maximum*a))) 50 | m_approx = 0.5 - (1./12)*a + (1./720)*a**3 - (1./30240)*a**5 # + (1./1209600)*a**7 # this extra term is unnecessary, it's accurate enough 51 | return T.switch(T.abs_(a) > 0.5, m_real, m_approx) 52 | 53 | 54 | 55 | def laplacian(b, mu=0.0): 56 | # laplacian distributition is only exponential family when mu=0! 57 | uniform_samples = theano_rng.uniform(size=b.shape, dtype=theano.config.floatX) 58 | return mu - b*T.sgn(uniform_samples-0.5) * T.log(1 - 2*T.abs_(uniform_samples-0.5)) 59 | 60 | 61 | 62 | ## approximate gamma sampler 63 | # Two approximations for the gamma function are defined. 64 | # Windschitl is very fast, but problematic close to 0, and using the reflection formula 65 | # causes discontinuities. 66 | # Lanczos on the other hand is extremely accurate, but slower. 67 | 68 | def _log_gamma_windschitl(z): 69 | """ 70 | computes log(gamma(z)) using windschitl's approximation. 71 | """ 72 | return 0.5 * (T.log(2*np.pi) - T.log(z) + z * (2 * T.log(z) - 2 + T.log(z * T.sinh(1/z) + 1 / (810*(z**6))))) 73 | 74 | def _log_gamma_ratio_windschitl(z, k): 75 | """ 76 | computes log(gamma(z+k)/gamma(z)) using windschitl's approximation. 77 | """ 78 | return _log_gamma_windschitl(z + k) - _log_gamma_windschitl(z) 79 | 80 | 81 | def _log_gamma_lanczos(z): 82 | # optimised by nouiz. thanks! 83 | assert z.dtype.startswith("float") 84 | # reflection formula. Normally only used for negative arguments, 85 | # but here it's also used for 0 < z < 0.5 to improve accuracy in 86 | # this region. 87 | flip_z = 1 - z 88 | # because both paths are always executed (reflected and 89 | # non-reflected), the reflection formula causes trouble when the 90 | # input argument is larger than one. 91 | # Note that for any z > 1, flip_z < 0. 92 | # To prevent these problems, we simply set all flip_z < 0 to a 93 | # 'dummy' value. This is not a problem, since these computations 94 | # are useless anyway and are discarded by the T.switch at the end 95 | # of the function. 96 | flip_z = T.switch(flip_z < 0, 1, flip_z) 97 | log_pi = np.asarray(np.log(np.pi), dtype=z.dtype) 98 | small = log_pi - T.log(T.sin(np.pi * z)) - _log_gamma_lanczos_sub(flip_z) 99 | big = _log_gamma_lanczos_sub(z) 100 | return T.switch(z < 0.5, small, big) 101 | 102 | 103 | def _log_gamma_lanczos_sub(z): # expanded version 104 | # optimised by nouiz. thanks! 105 | # Coefficients used by the GNU Scientific Library 106 | # note that vectorising this function and using .sum() turns out to be 107 | # really slow! possibly because the dimension across which is summed is 108 | # really small. 109 | g = 7 110 | p = np.array([0.99999999999980993, 676.5203681218851, -1259.1392167224028, 111 | 771.32342877765313, -176.61502916214059, 12.507343278686905, 112 | -0.13857109526572012, 9.9843695780195716e-6, 113 | 1.5056327351493116e-7], dtype=z.dtype) 114 | z = z - 1 115 | x = p[0] 116 | for i in range(1, g + 2): 117 | x += p[i] / (z + i) 118 | t = z + g + 0.5 119 | pi = np.asarray(np.pi, dtype=z.dtype) 120 | log_sqrt_2pi = np.asarray(np.log(np.sqrt(2 * np.pi)), dtype=z.dtype) 121 | return log_sqrt_2pi + (z + 0.5) * T.log(t) - t + T.log(x) 122 | 123 | 124 | def _log_gamma_ratio_lanczos(z, k): 125 | """ 126 | computes log(gamma(z+k)/gamma(z)) using the lanczos approximation. 127 | """ 128 | return _log_gamma_lanczos(z + k) - _log_gamma_lanczos(z) 129 | 130 | 131 | def gamma_approx(k, theta=1): 132 | """ 133 | Sample from a gamma distribution using the Wilson-Hilferty approximation. 134 | The gamma function itself is also approximated, so everything can be 135 | computed on the GPU (using the Lanczos approximation). 136 | """ 137 | lmbda = 1/3.0 # according to Wilson and Hilferty 138 | mu = T.exp(_log_gamma_ratio_lanczos(k, lmbda)) 139 | sigma = T.sqrt(T.exp(_log_gamma_ratio_lanczos(k, 2*lmbda)) - mu**2) 140 | normal_samples = theano_rng.normal(size=k.shape, avg=mu, std=sigma, dtype=theano.config.floatX) 141 | gamma_samples = theta * T.abs_(normal_samples ** 3) 142 | # The T.abs_ is technically incorrect. The problem is that, without it, this formula may yield 143 | # negative samples, which is impossible for the gamma distribution. 144 | # It was also noted that, for very small values of the shape parameter k, the distribution 145 | # of resulting samples is roughly symmetric around 0. By 'folding' the negative part 146 | # onto the positive part, we still get a decent approximation because of this. 147 | return gamma_samples 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /cnn/morb/samplers.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/samplers.pyc -------------------------------------------------------------------------------- /cnn/morb/stats.py: -------------------------------------------------------------------------------- 1 | from morb.base import Stats 2 | 3 | import numpy as np 4 | 5 | import theano 6 | 7 | 8 | def gibbs_step(rbm, vmap, units_list, mean_field_for_stats=[], mean_field_for_gibbs=[]): 9 | # implements a single gibbs step, and makes sure mean field is only used where it should be. 10 | # returns two vmaps, one for stats and one for gibbs. 11 | # also enforces consistency between samples, between the gibbs vmap and the stats vmap. 12 | # the provided lists and vmaps are expected to be COMPLETE. Otherwise, the behaviour is unspecified. 13 | 14 | # first, find out which units we need to sample for the stats vmap, and which for the gibbs vmap. 15 | # Mean field will be used for the others. 16 | units_sample_stats = units_list[:] # make a copy 17 | units_mean_field_stats = [] 18 | for u in mean_field_for_stats: 19 | if u in units_sample_stats: 20 | units_sample_stats.remove(u) # remove all mean field units from the sample list 21 | units_mean_field_stats.append(u) # add them to the mean field list instead 22 | 23 | units_sample_gibbs = units_list[:] 24 | units_mean_field_gibbs = [] 25 | for u in mean_field_for_gibbs: 26 | if u in units_sample_gibbs: 27 | units_sample_gibbs.remove(u) # remove all mean field units from the sample list 28 | units_mean_field_gibbs.append(u) # add them to the mean field list instead 29 | 30 | # now we can compute the total list of units to sample. 31 | # By sampling them all in one go, we can enforce consistency. 32 | units_sample = list(set(units_sample_gibbs + units_sample_stats)) 33 | sample_vmap = rbm.sample(units_sample, vmap) 34 | units_mean_field = list(set(units_mean_field_gibbs + units_mean_field_stats)) 35 | mean_field_vmap = rbm.mean_field(units_mean_field, vmap) 36 | 37 | # now, construct the gibbs and stats vmaps 38 | stats_vmap = dict((u, sample_vmap[u]) for u in units_sample_stats) 39 | stats_vmap.update(dict((u, mean_field_vmap[u]) for u in units_mean_field_stats)) 40 | gibbs_vmap = dict((u, sample_vmap[u]) for u in units_sample_gibbs) 41 | gibbs_vmap.update(dict((u, mean_field_vmap[u]) for u in units_mean_field_gibbs)) 42 | 43 | return stats_vmap, gibbs_vmap 44 | 45 | 46 | def cd_stats(rbm, v0_vmap, visible_units, hidden_units, context_units=[], k=1, mean_field_for_stats=[], mean_field_for_gibbs=[], persistent_vmap=None): 47 | # mean_field_for_gibbs is a list of units for which 'mean_field' should be used during gibbs sampling, rather than 'sample'. 48 | # mean_field_for_stats is a list of units for which 'mean_field' should be used to compute statistics, rather than 'sample'. 49 | 50 | # complete units lists 51 | visible_units = rbm.complete_units_list(visible_units) 52 | hidden_units = rbm.complete_units_list(hidden_units) 53 | context_units = rbm.complete_units_list(context_units) 54 | 55 | # complete the supplied vmap 56 | v0_vmap = rbm.complete_vmap(v0_vmap) 57 | 58 | # extract the context vmap, because we will need to merge it into all other vmaps 59 | context_vmap = dict((u, v0_vmap[u]) for u in context_units) 60 | 61 | h0_activation_vmap = dict((h, h.activation(v0_vmap)) for h in hidden_units) 62 | h0_stats_vmap, h0_gibbs_vmap = gibbs_step(rbm, v0_vmap, hidden_units, mean_field_for_stats, mean_field_for_gibbs) 63 | 64 | # add context 65 | h0_activation_vmap.update(context_vmap) 66 | h0_gibbs_vmap.update(context_vmap) 67 | h0_stats_vmap.update(context_vmap) 68 | 69 | exp_input = [v0_vmap[u] for u in visible_units] 70 | exp_context = [v0_vmap[u] for u in context_units] 71 | exp_latent = [h0_gibbs_vmap[u] for u in hidden_units] 72 | 73 | # scan requires a function that returns theano expressions, so we cannot pass vmaps in or out. annoying. 74 | def gibbs_hvh(*args): 75 | h0_gibbs_vmap = dict(zip(hidden_units, args)) 76 | 77 | v1_in_vmap = h0_gibbs_vmap.copy() 78 | v1_in_vmap.update(context_vmap) # add context 79 | 80 | v1_activation_vmap = dict((v, v.activation(v1_in_vmap)) for v in visible_units) 81 | v1_stats_vmap, v1_gibbs_vmap = gibbs_step(rbm, v1_in_vmap, visible_units, mean_field_for_stats, mean_field_for_gibbs) 82 | 83 | h1_in_vmap = v1_gibbs_vmap.copy() 84 | h1_in_vmap.update(context_vmap) # add context 85 | 86 | h1_activation_vmap = dict((h, h.activation(h1_in_vmap)) for h in hidden_units) 87 | h1_stats_vmap, h1_gibbs_vmap = gibbs_step(rbm, h1_in_vmap, hidden_units, mean_field_for_stats, mean_field_for_gibbs) 88 | 89 | # get the v1 values in a fixed order 90 | v1_activation_values = [v1_activation_vmap[u] for u in visible_units] 91 | v1_gibbs_values = [v1_gibbs_vmap[u] for u in visible_units] 92 | v1_stats_values = [v1_stats_vmap[u] for u in visible_units] 93 | 94 | # same for the h1 values 95 | h1_activation_values = [h1_activation_vmap[u] for u in hidden_units] 96 | h1_gibbs_values = [h1_gibbs_vmap[u] for u in hidden_units] 97 | h1_stats_values = [h1_stats_vmap[u] for u in hidden_units] 98 | 99 | return v1_activation_values + v1_stats_values + v1_gibbs_values + \ 100 | h1_activation_values + h1_stats_values + h1_gibbs_values 101 | 102 | 103 | # support for persistent CD 104 | if persistent_vmap is None: 105 | chain_start = exp_latent 106 | else: 107 | chain_start = [persistent_vmap[u] for u in hidden_units] 108 | 109 | 110 | # The 'outputs_info' keyword argument of scan configures how the function outputs are mapped to the inputs. 111 | # in this case, we want the h1_gibbs_vmap values to map onto the function arguments, so they become 112 | # h0_gibbs_vmap values in the next iteration. To this end, we construct outputs_info as follows: 113 | outputs_info = [None] * (len(exp_input)*3) + [None] * (len(exp_latent)*2) + list(chain_start) 114 | # 'None' indicates that this output is not used in the next iteration. 115 | 116 | exp_output_all_list, theano_updates = theano.scan(gibbs_hvh, outputs_info = outputs_info, n_steps = k) 117 | # we only need the final outcomes, not intermediary values 118 | exp_output_list = [out[-1] for out in exp_output_all_list] 119 | 120 | # reconstruct vmaps from the exp_output_list. 121 | n_input, n_latent = len(visible_units), len(hidden_units) 122 | vk_activation_vmap = dict(zip(visible_units, exp_output_list[0:1*n_input])) 123 | vk_stats_vmap = dict(zip(visible_units, exp_output_list[1*n_input:2*n_input])) 124 | vk_gibbs_vmap = dict(zip(visible_units, exp_output_list[2*n_input:3*n_input])) 125 | hk_activation_vmap = dict(zip(hidden_units, exp_output_list[3*n_input:3*n_input+1*n_latent])) 126 | hk_stats_vmap = dict(zip(hidden_units, exp_output_list[3*n_input+1*n_latent:3*n_input+2*n_latent])) 127 | hk_gibbs_vmap = dict(zip(hidden_units, exp_output_list[3*n_input+2*n_latent:3*n_input+3*n_latent])) 128 | 129 | # add the Theano updates for the persistent CD states: 130 | if persistent_vmap is not None: 131 | for u, v in persistent_vmap.items(): 132 | theano_updates[v] = hk_gibbs_vmap[u] # this should be the gibbs vmap, and not the stats vmap! 133 | 134 | activation_data_vmap = v0_vmap.copy() # TODO: this doesn't really make sense to have in an activation vmap! 135 | activation_data_vmap.update(h0_activation_vmap) 136 | activation_model_vmap = vk_activation_vmap.copy() 137 | activation_model_vmap.update(context_vmap) 138 | activation_model_vmap.update(hk_activation_vmap) 139 | 140 | stats = Stats(theano_updates) # create a new stats object 141 | 142 | # store the computed stats in a dictionary of vmaps. 143 | stats_data_vmap = v0_vmap.copy() 144 | stats_data_vmap.update(h0_stats_vmap) 145 | stats_model_vmap = vk_stats_vmap.copy() 146 | stats_model_vmap.update(context_vmap) 147 | stats_model_vmap.update(hk_stats_vmap) 148 | stats.update({ 149 | 'data': stats_data_vmap, 150 | 'model': stats_model_vmap, 151 | }) 152 | 153 | stats['data_activation'] = activation_data_vmap 154 | stats['model_activation'] = activation_model_vmap 155 | 156 | return stats 157 | 158 | -------------------------------------------------------------------------------- /cnn/morb/stats.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/stats.pyc -------------------------------------------------------------------------------- /cnn/morb/trainers.py: -------------------------------------------------------------------------------- 1 | from morb.base import Trainer 2 | 3 | import theano 4 | import theano.tensor as T 5 | 6 | import numpy as np 7 | 8 | class MinibatchTrainer(Trainer): 9 | # use self.rbm, self.umap, self.get_updates(vmap) 10 | def compile_function(self, initial_vmap, monitors=[], name='func', mb_size=32, train=True, mode=None): 11 | # setting train=False is useful when compiling a function for evaluation only, i.e. no training. 12 | # this is interesting when one wants to evaluate training progress on a validation set, for example. 13 | # then the variables will not be updated, but there might still be updates from scan operations 14 | # for example, so we still have to fetch them! 15 | updates = self.get_theano_updates(train) 16 | 17 | # initialise data sets 18 | data_sets = {} 19 | for u, v in initial_vmap.items(): 20 | shape = (1,) * v.ndim 21 | data_sets[u] = theano.shared(value = np.zeros(shape, dtype=theano.config.floatX), 22 | name="dataset for '%s'" % u.name) 23 | 24 | index = T.lscalar() # index to a minibatch 25 | 26 | # construct givens for the compiled theano function - mapping variables to data 27 | givens = dict((initial_vmap[u], data_sets[u][index*mb_size:(index+1)*mb_size]) for u in initial_vmap) 28 | 29 | TF = theano.function([index], monitors, 30 | updates = updates, givens = givens, name = name, mode = mode) 31 | 32 | def func(dmap): 33 | # dmap is a dict that maps unit types on their respective datasets (numeric). 34 | units_list = dmap.keys() 35 | data_sizes = [int(np.ceil(dmap[u].shape[0] / float(mb_size))) for u in units_list] 36 | 37 | if data_sizes.count(data_sizes[0]) != len(data_sizes): # check if all data sizes are equal 38 | raise RuntimeError("The sizes of the supplied datasets for the different input units are not equal.") 39 | 40 | data_cast = [dmap[u].astype(theano.config.floatX) for u in units_list] 41 | 42 | for i, u in enumerate(units_list): 43 | data_sets[u].set_value(data_cast[i], borrow=True) 44 | 45 | for batch_index in xrange(min(data_sizes)): 46 | yield TF(batch_index) 47 | 48 | return func 49 | 50 | 51 | -------------------------------------------------------------------------------- /cnn/morb/trainers.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/trainers.pyc -------------------------------------------------------------------------------- /cnn/morb/units.py: -------------------------------------------------------------------------------- 1 | from morb.base import Units, ProxyUnits 2 | from morb import samplers, activation_functions 3 | import theano.tensor as T 4 | import numpy as np 5 | 6 | 7 | class BinaryUnits(Units): 8 | def success_probability_from_activation(self, vmap): 9 | return activation_functions.sigmoid(vmap[self]) 10 | 11 | def success_probability(self, vmap): 12 | return self.success_probability_from_activation({ self: self.activation(vmap) }) 13 | 14 | def sample_from_activation(self, vmap): 15 | p = self.success_probability_from_activation(vmap) 16 | return samplers.bernoulli(p) 17 | 18 | def mean_field_from_activation(self, vmap): 19 | return activation_functions.sigmoid(vmap[self]) 20 | 21 | def free_energy_term_from_activation(self, vmap): 22 | # softplus of unit activations, summed over # units 23 | s = - T.nnet.softplus(vmap[self]) 24 | # sum over all but the minibatch dimension 25 | return T.sum(s, axis=range(1, s.ndim)) 26 | 27 | def log_prob_from_activation(self, vmap, activation_vmap): 28 | # the log probability mass function is actually the negative of the 29 | # cross entropy between the unit values and the activations 30 | p = self.success_probability_from_activation(activation_vmap) 31 | return vmap[self] * T.log(p) + (1 - vmap[self]) * T.log(1 - p) 32 | 33 | class GaussianPrecisionProxyUnits(ProxyUnits): 34 | def __init__(self, rbm, units, name=None): 35 | func = lambda x: x**2 / 2.0 36 | super(GaussianPrecisionProxyUnits, self).__init__(rbm, units, func, name) 37 | 38 | class GaussianUnits(Units): 39 | def __init__(self, rbm, name=None): 40 | super(GaussianUnits, self).__init__(rbm, name) 41 | proxy_name = (name + "_precision" if name is not None else None) 42 | self.precision_units = GaussianPrecisionProxyUnits(rbm, self, name=proxy_name) 43 | self.proxy_units = [self.precision_units] 44 | 45 | def mean_from_activation(self, vmap): # mean is the parameter 46 | return vmap[self] 47 | 48 | def mean(self, vmap): 49 | return self.mean_from_activation({ self: self.activation(vmap) }) 50 | 51 | def sample_from_activation(self, vmap): 52 | mu = self.mean_from_activation(vmap) 53 | return samplers.gaussian(mu) 54 | 55 | def mean_field_from_activation(self, vmap): 56 | return vmap[self] 57 | 58 | def log_prob_from_activation(self, vmap, activation_vmap): 59 | return - np.log(np.sqrt(2*np.pi)) - ((vmap[self] - activation_vmap[self])**2 / 2.0) 60 | 61 | 62 | 63 | class LearntPrecisionGaussianProxyUnits(ProxyUnits): 64 | def __init__(self, rbm, units, name=None): 65 | func = lambda x: x**2 66 | super(LearntPrecisionGaussianProxyUnits, self).__init__(rbm, units, func, name) 67 | 68 | class LearntPrecisionGaussianUnits(Units): 69 | def __init__(self, rbm, name=None): 70 | super(LearntPrecisionGaussianUnits, self).__init__(rbm, name) 71 | proxy_name = (name + "_precision" if name is not None else None) 72 | self.precision_units = LearntPrecisionGaussianProxyUnits(rbm, self, name=proxy_name) 73 | self.proxy_units = [self.precision_units] 74 | 75 | def mean_from_activation(self, vmap): 76 | return vmap[self] / self.precision_from_activation(vmap) 77 | 78 | def mean(self, vmap): 79 | a1 = self.activation(vmap) 80 | a2 = self.precision_units.activation(vmap) 81 | return self.mean_from_activation({ self: a1, self.precision_units: a2 }) 82 | 83 | def variance_from_activation(self, vmap): 84 | return 1 / self.precision_from_activation(vmap) 85 | 86 | def variance(self, vmap): 87 | a1 = self.activation(vmap) 88 | a2 = self.precision_units.activation(vmap) 89 | return self.variance_from_activation({ self: a1, self.precision_units: a2 }) 90 | 91 | def precision_from_activation(self, vmap): 92 | return -2 * vmap[self.precision_units] 93 | 94 | def precision(self, vmap): 95 | a1 = self.activation(vmap) 96 | a2 = self.precision_units.activation(vmap) 97 | return self.precision_from_activation({ self: a1, self.precision_units: a2 }) 98 | 99 | def sample_from_activation(self, vmap): 100 | mu = self.mean_from_activation(vmap) 101 | sigma2 = self.variance_from_activation(vmap) 102 | return samplers.gaussian(mu, sigma2) 103 | 104 | def sample(self, vmap): 105 | a1 = self.activation(vmap) 106 | a2 = self.precision_units.activation(vmap) 107 | return self.sample_from_activation({ self: a1, self.precision_units: a2 }) 108 | 109 | def log_prob(self, vmap): 110 | a1 = self.activation(vmap) 111 | a2 = self.precision_units.activation(vmap) 112 | activation_vmap = { self: a1, self.precision_units: a2 } 113 | return self.log_prob_from_activation(vmap, activation_vmap) 114 | 115 | def log_prob_from_activation(self, vmap, activation_vmap): 116 | var = self.variance_from_activation(activation_vmap) 117 | mean = self.mean_from_activation(activation_vmap) 118 | return - np.log(np.sqrt(2 * np.pi * var)) - ((vmap[self] - mean)**2 / (2.0 * var)) 119 | 120 | 121 | 122 | # TODO later: gaussian units with custom fixed variance (maybe per-unit). This probably requires two proxies. 123 | 124 | class SoftmaxUnits(Units): 125 | # 0 = minibatches 126 | # 1 = units 127 | # 2 = states 128 | def probabilities_from_activation(self, vmap): 129 | return activation_functions.softmax(vmap[self]) 130 | 131 | def probabilities(self, vmap): 132 | return self.probabilities_from_activation({ self: self.activation(vmap) }) 133 | 134 | def sample_from_activation(self, vmap): 135 | p = self.probabilities_from_activation(vmap) 136 | return samplers.multinomial(p) 137 | 138 | 139 | class SoftmaxWithZeroUnits(Units): 140 | """ 141 | Like SoftmaxUnits, but in this case a zero state is possible, yielding N+1 possible states in total. 142 | """ 143 | def probabilities_from_activation(self, vmap): 144 | return activation_functions.softmax_with_zero(vmap[self]) 145 | 146 | def probabilities(self, vmap): 147 | return self.probabilities_from_activation({ self: self.activation(vmap) }) 148 | 149 | def sample_from_activation(self, vmap): 150 | p0 = self.probabilities_from_activation(vmap) 151 | s0 = samplers.multinomial(p0) 152 | s = s0[:, :, :-1] # chop off the last state (zero state) 153 | return s 154 | 155 | 156 | class TruncatedExponentialUnits(Units): 157 | def rate_from_activation(self, vmap): # lambda 158 | return -vmap[self] # lambda = -activation! 159 | 160 | def rate(self, vmap): 161 | return self.rate_from_activation({ self: self.activation(vmap) }) 162 | 163 | def sample_from_activation(self, vmap): 164 | rate = self.rate_from_activation(vmap) 165 | return samplers.truncated_exponential(rate) 166 | 167 | def mean_field_from_activation(self, vmap): 168 | rate = self.rate_from_activation(vmap) 169 | return samplers.truncated_exponential_mean(rate) 170 | 171 | def log_prob_from_activation(self, vmap, activation_vmap): 172 | rate = self.rate_from_activation(activation_vmap) 173 | return T.log(rate) - rate * vmap[self] - T.log(1 - T.exp(-rate)) 174 | 175 | 176 | class ExponentialUnits(Units): 177 | def rate_from_activation(self, vmap): # lambda 178 | return -vmap[self] # lambda = -activation! 179 | 180 | def rate(self, vmap): 181 | return self.rate_from_activation({ self: self.activation(vmap) }) 182 | 183 | def sample_from_activation(self, vmap): 184 | rate = self.rate_from_activation(vmap) 185 | return samplers.exponential(rate) # lambda = -activation! 186 | 187 | def mean_field_from_activation(self, vmap): 188 | return 1.0 / self.rate_from_activation(vmap) 189 | 190 | def log_prob_from_activation(self, vmap, activation_vmap): 191 | rate = self.rate_from_activation(activation_vmap) 192 | return T.log(rate) - rate * vmap[self] 193 | 194 | 195 | 196 | class NRELUnits(Units): 197 | """ 198 | Noisy rectified linear units from 'Rectified Linear Units Improve Restricted Boltzmann Machines' 199 | by Nair & Hinton (ICML 2010) 200 | 201 | WARNING: computing the energy or free energy of a configuration does not have the same semantics 202 | as usual with NReLUs, because each ReLU is actually the sum of an infinite number of Bernoulli 203 | units with offset biases. The energy depends on the individual values of these Bernoulli units, 204 | whereas only the sum is ever sampled (approximately). 205 | 206 | See: http://metaoptimize.com/qa/questions/8524/energy-function-of-an-rbm-with-noisy-rectified-linear-units-nrelus 207 | """ 208 | def sample_from_activation(self, vmap): 209 | s = vmap[self] + samplers.gaussian(0, T.nnet.sigmoid(vmap[self])) # approximation: linear + gaussian noise 210 | return T.max(0, s) # rectify 211 | 212 | def mean_field_from_activation(self, vmap): 213 | return T.max(0, vmap[self]) 214 | 215 | 216 | 217 | 218 | class GammaLogProxyUnits(ProxyUnits): 219 | def __init__(self, rbm, units, name=None): 220 | func = lambda x: T.log(x) 221 | super(GammaLogProxyUnits, self).__init__(rbm, units, func, name) 222 | 223 | class GammaUnits(Units): 224 | """ 225 | Two-parameter gamma distributed units, using an approximate sampling procedure for speed. 226 | The activations should satisfy some constraints: 227 | - the activation of the GammaUnits should be strictly negative. 228 | - the activation of the GammaLogProxyUnits should be strictly larger than -1. 229 | It is recommended to use a FixedBiasParameters instance for the GammaLogProxyUnits, 230 | so that the 'remaining' part of the activation should be strictly positive. This 231 | constraint is much easier to satisfy. 232 | """ 233 | def __init__(self, rbm, name=None): 234 | super(GammaUnits, self).__init__(rbm, name) 235 | proxy_name = (name + "_log" if name is not None else None) 236 | self.log_units = GammaLogProxyUnits(rbm, self, name=proxy_name) 237 | self.proxy_units = [self.log_units] 238 | 239 | def sample_from_activation(self, vmap): 240 | a1 = vmap[self] 241 | a2 = vmap[self.log_units] 242 | return samplers.gamma_approx(a2 + 1, -1 / a1) 243 | 244 | def sample(self, vmap): 245 | a1 = self.activation(vmap) 246 | a2 = self.log_units.activation(vmap) 247 | return self.sample_from_activation({ self: a1, self.log_units: a2 }) 248 | 249 | def k_from_activation(self, vmap): 250 | a2 = vmap[self.log_units] 251 | return a2 + 1 252 | 253 | def k(self, vmap): 254 | a1 = self.activation(vmap 255 | ) 256 | a2 = self.log_units.activation(vmap) 257 | return self.k_from_activation({ self: a1, self.log_units: a2 }) 258 | 259 | def theta_from_activation(self, vmap): 260 | a1 = vmap[self] 261 | return -1.0 / a1 262 | 263 | def theta(self, vmap): 264 | a1 = self.activation(vmap) 265 | a2 = self.log_units.activation(vmap) 266 | return self.theta_from_activation({ self: a1, self.log_units: a2 }) 267 | 268 | def mean_from_activation(self, vmap): 269 | k = self.k_from_activation(vmap) 270 | theta = self.theta_from_activation(vmap) 271 | return k * theta 272 | 273 | def mean(self, vmap): 274 | a1 = self.activation(vmap) 275 | a2 = self.log_units.activation(vmap) 276 | return self.mean_from_activation({ self: a1, self.log_units: a2 }) 277 | 278 | 279 | 280 | class SymmetricBinaryProxyUnits(ProxyUnits): 281 | def __init__(self, rbm, units, name=None): 282 | func = lambda x: 1 - x # flip 283 | super(SymmetricBinaryProxyUnits, self).__init__(rbm, units, func, name) 284 | 285 | 286 | class SymmetricBinaryUnits(Units): 287 | """ 288 | Symmetric binary units can be used to include both x and (1 - x) in the energy 289 | function. This is useful in cases where parameters have to be constrained to 290 | yield valid conditional distributions. Making the energy function symmetric 291 | allows for these constraints to be much weaker. For more info, refer to 292 | http://metaoptimize.com/qa/questions/9628/symmetric-energy-functions-for-rbms 293 | and the paper referenced there. 294 | """ 295 | def __init__(self, rbm, name=None): 296 | super(SymmetricBinaryUnits, self).__init__(rbm, name) 297 | proxy_name = (name + '_flipped' if name is not None else None) 298 | self.flipped_units = SymmetricBinaryProxyUnits(rbm, self, name=proxy_name) 299 | self.proxy_units = [self.flipped_units] 300 | 301 | def sample_from_activation(self, vmap): 302 | p = activation_functions.sigmoid(vmap[self] - vmap[self.flipped_units]) 303 | return samplers.bernoulli(p) 304 | 305 | def mean_field_from_activation(self, vmap): 306 | return activation_functions.sigmoid(vmap[self] - vmap[self.flipped_units]) 307 | 308 | def free_energy_term_from_activation(self, vmap): 309 | # softplus of unit activations, summed over # units 310 | s = - T.nnet.softplus(vmap[self] - vmap[self.flipped_units]) 311 | # sum over all but the minibatch dimension 312 | return T.sum(s, axis=range(1, s.ndim)) 313 | 314 | -------------------------------------------------------------------------------- /cnn/morb/units.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/units.pyc -------------------------------------------------------------------------------- /cnn/morb/updaters.py: -------------------------------------------------------------------------------- 1 | from morb.base import Updater, SumUpdater, ScaleUpdater 2 | import samplers 3 | 4 | import theano 5 | import theano.tensor as T 6 | import numpy as np 7 | 8 | 9 | class SelfUpdater(Updater): 10 | def get_update(self): 11 | return self.variable 12 | 13 | DecayUpdater = SelfUpdater 14 | # weight decay: the update == the parameter values themselves 15 | # (decay constant is taken care of by ScaleUpdater) 16 | 17 | class MomentumUpdater(Updater): 18 | def __init__(self, pu, momentum, variable_shape): 19 | # IMPORTANT: since this Updater has state, it requires the shape of the parameter 20 | # variable to be supplied at initialisation. 21 | super(MomentumUpdater, self).__init__(pu.variable, pu.stats_list) 22 | self.pu = pu 23 | self.momentum = momentum 24 | self.variable_shape = variable_shape 25 | 26 | name = pu.variable.name + "_momentum" 27 | self.previous_update = theano.shared(value = np.zeros(self.variable_shape, dtype=theano.config.floatX), name=name) 28 | 29 | # Update calculation has to happen in __init__, because else if get_theano_updates 30 | # is called before get_update, the state update will not be included in the dict. 31 | # This is a bit nasty, and it probably applies for all updaters with state. 32 | # maybe this is a design flaw? 33 | self.update = self.pu.get_update() + self.momentum * self.previous_update 34 | self.theano_updates = { self.previous_update: self.update } 35 | 36 | def get_update(self): 37 | return self.update 38 | 39 | def get_theano_updates(self): 40 | u = self.theano_updates.copy() # the MomentumUpdater's own state updates 41 | u.update(self.pu.get_theano_updates()) # the state updates of the contained Updater 42 | return u 43 | 44 | 45 | class CDUpdater(Updater): 46 | def __init__(self, rbm, variable, stats): 47 | super(CDUpdater, self).__init__(variable, [stats]) 48 | # this updater has only one stats object, so make it more conveniently accessible 49 | self.stats = stats 50 | self.rbm = rbm 51 | 52 | def get_update(self): 53 | positive_term = self.rbm.energy_gradient_sum(self.variable, self.stats['data']) 54 | negative_term = self.rbm.energy_gradient_sum(self.variable, self.stats['model']) 55 | 56 | return positive_term - negative_term 57 | 58 | 59 | class SparsityUpdater(Updater): 60 | def __init__(self, rbm, variable, sparsity_targets, stats): 61 | # sparsity_targets is a dict mapping Units instances to their target activations 62 | super(SparsityUpdater, self).__init__(variable, [stats]) 63 | self.stats = stats 64 | self.rbm = rbm 65 | self.sparsity_targets = sparsity_targets 66 | 67 | def get_update(self): 68 | # modify vmap: subtract target values 69 | # this follows the formulation in 'Biasing RBMs to manipulate latent selectivity and sparsity' by Goh, Thome and Cord (2010), formulas (8) and (9). 70 | vmap = self.stats['data'].copy() 71 | for u, target in self.sparsity_targets.items(): 72 | if u in vmap: 73 | vmap[u] -= target 74 | 75 | return - self.rbm.energy_gradient_sum(self.variable, vmap) # minus sign is important! 76 | 77 | 78 | class BoundUpdater(Updater): 79 | """ 80 | Forces the parameter to be larger than (default) or smaller than a given value. 81 | When type='lower', the bound is a lower bound. This is the default behaviour. 82 | When type='upper', the bound is an upper bound. 83 | The value of the bound is 0 by default, so if no extra arguments are supplied, 84 | this updater will force the parameter values to be positive. 85 | The bound is always inclusive. 86 | """ 87 | def __init__(self, pu, bound=0, type='lower'): 88 | super(BoundUpdater, self).__init__(pu.variable, pu.stats_list) 89 | self.pu = pu 90 | self.bound = bound 91 | self.type = type 92 | 93 | def get_update(self): 94 | update = self.pu.get_update() 95 | if self.type == 'lower': 96 | condition = update >= self.bound 97 | else: # type is 'upper' 98 | condition = update <= self.bound 99 | # return T.switch(condition, update, T.ones_like(update) * self.bound) 100 | return T.switch(condition, update, self.variable) 101 | 102 | def get_theano_updates(self): 103 | # The BoundUpdater has no state, so the only updates that should be returned 104 | # are those of the encapsulated updater. 105 | return self.pu.get_theano_updates() 106 | 107 | 108 | 109 | class GradientUpdater(Updater): 110 | """ 111 | Takes any objective in the form of a scalar Theano expression and uses T.grad 112 | to compute the update with respect to the given parameter variable. 113 | 114 | This can be used to train/finetune a model supervisedly or as an auto- 115 | encoder, for example. 116 | """ 117 | def __init__(self, objective, variable, theano_updates={}): 118 | """ 119 | the theano_updates argument can be used to pass in updates if the objective 120 | contains a scan op or something. 121 | """ 122 | super(GradientUpdater, self).__init__(variable) 123 | self.update = T.grad(objective, variable) 124 | self.theano_updates = theano_updates 125 | 126 | def get_update(self): 127 | return self.update 128 | 129 | def get_theano_updates(self): 130 | return self.theano_updates 131 | 132 | 133 | 134 | # class DenoisingScoreMatchingUpdater(Updater): 135 | # """ 136 | # implements the denoising version of the score matching objective, an alternative to 137 | # maximum likelihood that doesn't require an approximation of the partition function. 138 | 139 | # This version uses a Gaussian kernel. Furthermore, it adds the scale factor 1/sigma**2 140 | # to the free energy of the model, as described in "A connection between score matching 141 | # and denoising autoencoders" by Vincent et al., such that it yields the denoising 142 | # autoencoder objective for a Gaussian-Bernoulli RBM. 143 | 144 | # This approach is only valid if the domain of the input is the real numbers. That means it 145 | # won't work for binary input units, or other unit types that don't define a distribution 146 | # on the entire real line. In practice, this is used almost exclusively with Gaussian 147 | # visible units. 148 | 149 | # std: noise level 150 | # """ 151 | # def __init__(self, rbm, visible_units, hidden_units, v0_vmap, std): 152 | # noise_map = {} 153 | # noisy_vmap = {} 154 | # for vu in visible_units: 155 | # noise_map[vu] = samplers.theano_rng.normal(size=v0_vmap[vu].shape, avg=0.0, std=std, dtype=theano.config.floatX) 156 | # noisy_vmap[vu] = v0_vmap[vu] + noise_map[vu] 157 | 158 | # free_energy = rbm.free_energy(hidden_units, noisy_vmap) 159 | # scores = [T.grad(free_energy, noisy_vmap[u]) for u in visible_units] 160 | # score_map = dict(zip(visible_units, scores)) 161 | 162 | # terms = [] 163 | # for vu in visible_units: 164 | # terms.append(T.sum(T.mean((score_map[vu] + noise_map[vu]) ** 2, 0))) # mean over minibatches 165 | 166 | # self.update = sum(terms) 167 | 168 | # def get_update(self): 169 | # return self.update 170 | 171 | 172 | -------------------------------------------------------------------------------- /cnn/morb/updaters.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/morb/updaters.pyc -------------------------------------------------------------------------------- /cnn/mpqa_rnn.m: -------------------------------------------------------------------------------- 1 | tic 2 | clear 3 | 4 | %rev_ind = importdata('trainb_ind'); 5 | 6 | nclass = 2; 7 | allfmea=zeros(10,1); 8 | classfmea=zeros(10,nclass); 9 | neu = 10; 10 | loopmax = 1; 11 | 12 | for k=0:9 13 | 14 | for loopk=1:loopmax 15 | 16 | if loopk==1 17 | 18 | filename = sprintf('set_train_rnn%d',k); 19 | train1 = importdata(filename); 20 | filename = sprintf('set_val_rnn%d',k); 21 | val = importdata(filename); 22 | filename = sprintf('set_test_rnn%d',k); 23 | test = importdata(filename); 24 | 25 | val = test; 26 | 27 | [n1 n2]=size(train1); 28 | [n3 n4a]=size(val); 29 | [n5 n6]=size(test); 30 | 31 | train4 = [train1 val test]; 32 | %[signals,PC,V] = pca2(train4(1:end-1,:)); 33 | %W3 = cov(signals(1:neu,:)'); 34 | W3 = rand(neu,neu); 35 | 36 | else 37 | train4 = newdata; 38 | end 39 | 40 | n4 = n2+n4a; 41 | 42 | [n7 n8] = size(train4); 43 | X = train4(1:end-1,:); 44 | T = train4(end,:); 45 | T2=transformtarget(T,nclass); 46 | T2 = T2'; 47 | T = T2; 48 | net = layrecnet(1:2,neu); 49 | net.trainFcn = 'trainbr'; 50 | %net.trainFcn = 'trainbfg'; 51 | net.trainParam.epochs = 200; 52 | %net.trainParam.lr = 0.0001; 53 | %net.trainParam.showWindow = false; 54 | %net.trainParam.showWindow=0; 55 | net.performParam.regularization = 0.5; 56 | net.divideFcn = 'divideind'; 57 | net.performFcn = 'mse'; 58 | net.divideParam.trainInd = 1:n2; 59 | net.divideParam.valInd = n2+1:n4; 60 | net.divideParam.testInd = n4+1:size(train4,2); 61 | 62 | [net,tr] = train(net,X,T); 63 | W1 = net.LW{1,1}(:,1:neu); 64 | W2 = net.LW{1,1}(:,neu+1:2*neu); 65 | b = net.b{1,1}; 66 | C = net.LW{2,1}; 67 | 68 | ncase=size(X,2); 69 | Y = net(X); 70 | 71 | %without sdp 72 | %%{ 73 | newy = train4(end,:); 74 | newx = [T(:,1:n4)'*net.LW{2,1};Y(:,n4+1:end)'*net.LW{2,1}]; 75 | %newx = Y'*net.LW{2,1}; 76 | newx = newx'; 77 | newdata = [newx; newy]; 78 | %%} 79 | 80 | % for running sdp 81 | %{ 82 | C = net.LW{2,1}(:,1:neu); 83 | G = jump_deepsdp(W1,W2,W3,b,C); 84 | newy = train4(end,:); 85 | newx = [T(:,1:n4)'*G';Y(:,n4+1:end)'*G']; 86 | newx = newx'; 87 | newdata = [newx; newy]; 88 | 89 | %} 90 | 91 | if loopk==loopmax 92 | filename = sprintf('data_svm%d_%d.txt',loopk+1,k); 93 | dlmwrite(filename,newdata); 94 | filename = sprintf('run2/train_rnn_%d',k); 95 | save (filename, 'net') ; 96 | filename = sprintf('result%d_%d.txt',loopk+1,k); 97 | dlmwrite(filename,Y'); 98 | % filename = sprintf('gp/neu_gp/nlp_neu%d.txt',k); 99 | % dlmwrite(filename,newdata); 100 | end 101 | 102 | end 103 | 104 | [num idx] = max(T(:,n4+1:end)); 105 | [num2 idx2] = max(Y(:,n4+1:end)); 106 | 107 | %[idxb,idx2b]=newxy(idx',idx2',nclass,rev_ind); 108 | 109 | cm = confusionmat(idx,idx2); 110 | 111 | for x=1:nclass 112 | 113 | tp = cm(x,x); 114 | tn = cm(1,1); 115 | for y=2:nclass 116 | tn = tn+cm(y,y); 117 | end 118 | tn = tn-cm(x,x); 119 | 120 | fp = sum(cm(:, x))-cm(x, x); 121 | fn = sum(cm(x, :), 2)-cm(x, x); 122 | pre(x)=tp/(tp+fp+0.01); 123 | rec(x)=tp/(tp+fn+0.01); 124 | %fmea(x) = 2*pre(x)*rec(x)/(pre(x)+rec(x)+0.01); 125 | fmea(x) = (tp+tn)/(tp+fp+tn+fn); 126 | 127 | end 128 | 129 | 130 | classfmea(k+1,:)=fmea; 131 | fmea = sum(fmea)/nclass; 132 | 133 | fmea 134 | 135 | allfmea(k+1)=fmea; 136 | 137 | end 138 | 139 | allfmea 140 | 141 | dlmwrite('allfmea.txt',allfmea); 142 | dlmwrite('classfmea.txt',classfmea); 143 | 144 | toc -------------------------------------------------------------------------------- /cnn/pack_Data.py: -------------------------------------------------------------------------------- 1 | from numpy import genfromtxt 2 | import gzip, cPickle 3 | 4 | dirg = 'run2/' 5 | 6 | name1 = dirg+'train1.txt' 7 | train_set= genfromtxt(name1) 8 | name = dirg+'train1.pkl.gz' 9 | f = gzip.open(name,'wb') 10 | cPickle.dump([train_set], f, protocol=2) 11 | f.close() 12 | del train_set 13 | 14 | name1 = dirg+'val1.txt' 15 | valid_set= genfromtxt(name1) 16 | name = dirg+'val1.pkl.gz' 17 | f = gzip.open(name,'wb') 18 | cPickle.dump([val_set], f, protocol=2) 19 | f.close() 20 | del val_set 21 | 22 | name1 = dirg+'test1.txt' 23 | test_set= genfromtxt(name1) 24 | name = dirg+'test1.pkl.gz' 25 | f = gzip.open(name,'wb') 26 | cPickle.dump([test_set], f, protocol=2) 27 | f.close() 28 | del test_set -------------------------------------------------------------------------------- /cnn/run2/train_rnn_0.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_0.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_1.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_2.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_3.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_4.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_4.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_5.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_5.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_6.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_6.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_7.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_8.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_8.mat -------------------------------------------------------------------------------- /cnn/run2/train_rnn_9.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/run2/train_rnn_9.mat -------------------------------------------------------------------------------- /cnn/transformtarget.m: -------------------------------------------------------------------------------- 1 | function T2=transformtarget(T,num) 2 | %num = 2; 3 | T2 = zeros(1,num); 4 | 5 | for t=1:length(T) 6 | x = zeros(1,num); 7 | x(T(t))=1; 8 | T2 = [T2;x]; 9 | end 10 | 11 | T2 = T2(2:end,:); 12 | end -------------------------------------------------------------------------------- /cnn/utils.py: -------------------------------------------------------------------------------- 1 | """ This file contains different utility functions that are not connected 2 | in anyway to the networks presented in the tutorials, but rather help in 3 | processing the outputs into a more understandable way. 4 | 5 | For example ``tile_raster_images`` helps in generating a easy to grasp 6 | image from a set of samples or weights. 7 | """ 8 | 9 | 10 | import numpy 11 | 12 | 13 | def scale_to_unit_interval(ndar, eps=1e-8): 14 | """ Scales all values in the ndarray ndar to be between 0 and 1 """ 15 | ndar = ndar.copy() 16 | ndar -= ndar.min() 17 | ndar *= 1.0 / (ndar.max() + eps) 18 | return ndar 19 | 20 | 21 | def tile_raster_images(X, img_shape, tile_shape, tile_spacing=(0, 0), 22 | scale_rows_to_unit_interval=True, 23 | output_pixel_vals=True): 24 | """ 25 | Transform an array with one flattened image per row, into an array in 26 | which images are reshaped and layed out like tiles on a floor. 27 | 28 | This function is useful for visualizing datasets whose rows are images, 29 | and also columns of matrices for transforming those rows 30 | (such as the first layer of a neural net). 31 | 32 | :type X: a 2-D ndarray or a tuple of 4 channels, elements of which can 33 | be 2-D ndarrays or None; 34 | :param X: a 2-D array in which every row is a flattened image. 35 | 36 | :type img_shape: tuple; (height, width) 37 | :param img_shape: the original shape of each image 38 | 39 | :type tile_shape: tuple; (rows, cols) 40 | :param tile_shape: the number of images to tile (rows, cols) 41 | 42 | :param output_pixel_vals: if output should be pixel values (i.e. int8 43 | values) or floats 44 | 45 | :param scale_rows_to_unit_interval: if the values need to be scaled before 46 | being plotted to [0,1] or not 47 | 48 | 49 | :returns: array suitable for viewing as an image. 50 | (See:`Image.fromarray`.) 51 | :rtype: a 2-d array with same dtype as X. 52 | 53 | """ 54 | 55 | assert len(img_shape) == 2 56 | assert len(tile_shape) == 2 57 | assert len(tile_spacing) == 2 58 | 59 | # The expression below can be re-written in a more C style as 60 | # follows : 61 | # 62 | # out_shape = [0,0] 63 | # out_shape[0] = (img_shape[0]+tile_spacing[0])*tile_shape[0] - 64 | # tile_spacing[0] 65 | # out_shape[1] = (img_shape[1]+tile_spacing[1])*tile_shape[1] - 66 | # tile_spacing[1] 67 | out_shape = [ 68 | (ishp + tsp) * tshp - tsp 69 | for ishp, tshp, tsp in zip(img_shape, tile_shape, tile_spacing) 70 | ] 71 | 72 | if isinstance(X, tuple): 73 | assert len(X) == 4 74 | # Create an output numpy ndarray to store the image 75 | if output_pixel_vals: 76 | out_array = numpy.zeros((out_shape[0], out_shape[1], 4), 77 | dtype='uint8') 78 | else: 79 | out_array = numpy.zeros((out_shape[0], out_shape[1], 4), 80 | dtype=X.dtype) 81 | 82 | #colors default to 0, alpha defaults to 1 (opaque) 83 | if output_pixel_vals: 84 | channel_defaults = [0, 0, 0, 255] 85 | else: 86 | channel_defaults = [0., 0., 0., 1.] 87 | 88 | for i in xrange(4): 89 | if X[i] is None: 90 | # if channel is None, fill it with zeros of the correct 91 | # dtype 92 | dt = out_array.dtype 93 | if output_pixel_vals: 94 | dt = 'uint8' 95 | out_array[:, :, i] = numpy.zeros( 96 | out_shape, 97 | dtype=dt 98 | ) + channel_defaults[i] 99 | else: 100 | # use a recurrent call to compute the channel and store it 101 | # in the output 102 | out_array[:, :, i] = tile_raster_images( 103 | X[i], img_shape, tile_shape, tile_spacing, 104 | scale_rows_to_unit_interval, output_pixel_vals) 105 | return out_array 106 | 107 | else: 108 | # if we are dealing with only one channel 109 | H, W = img_shape 110 | Hs, Ws = tile_spacing 111 | 112 | # generate a matrix to store the output 113 | dt = X.dtype 114 | if output_pixel_vals: 115 | dt = 'uint8' 116 | out_array = numpy.zeros(out_shape, dtype=dt) 117 | 118 | for tile_row in xrange(tile_shape[0]): 119 | for tile_col in xrange(tile_shape[1]): 120 | if tile_row * tile_shape[1] + tile_col < X.shape[0]: 121 | this_x = X[tile_row * tile_shape[1] + tile_col] 122 | if scale_rows_to_unit_interval: 123 | # if we should scale values to be between 0 and 1 124 | # do this by calling the `scale_to_unit_interval` 125 | # function 126 | this_img = scale_to_unit_interval( 127 | this_x.reshape(img_shape)) 128 | else: 129 | this_img = this_x.reshape(img_shape) 130 | # add the slice to the corresponding position in the 131 | # output array 132 | c = 1 133 | if output_pixel_vals: 134 | c = 255 135 | out_array[ 136 | tile_row * (H + Hs): tile_row * (H + Hs) + H, 137 | tile_col * (W + Ws): tile_col * (W + Ws) + W 138 | ] = this_img * c 139 | return out_array 140 | -------------------------------------------------------------------------------- /cnn/utils.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/utils.pyc -------------------------------------------------------------------------------- /cnn/utilsm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | 5 | def generate_data(N): 6 | """Creates a noisy dataset with some simple pattern in it.""" 7 | T = N * 38 8 | u = np.mat(np.zeros((T, 20))) 9 | for i in range(1, T, 38): 10 | if i % 76 == 1: 11 | u[i - 1:i + 19, :] = np.eye(20) 12 | u[i + 18:i + 38, :] = np.eye(20)[np.arange(19, -1, -1)] 13 | u[i - 1:i + 19, :] += np.eye(20)[np.arange(19, -1, -1)] 14 | else: 15 | u[i - 1:i + 19, 1] = 1 16 | u[i + 18:i + 38, 8] = 1 17 | return u 18 | 19 | def get_context(u, N=4): 20 | T, D = u.shape 21 | x = np.zeros((T, D * N)) 22 | for i in range(N - 1, T): 23 | dat = u[i - 1, :] 24 | for j in range(2, N + 1): 25 | dat = np.concatenate((dat, u[i - j, :]), 1) 26 | x[i, :] = dat 27 | return x 28 | 29 | 30 | 31 | 32 | def plot_data(d): 33 | plt.figure(5) 34 | plt.clf() 35 | plt.imshow(d.reshape((28,28)), interpolation='gaussian') 36 | plt.draw() 37 | 38 | 39 | 40 | 41 | def one_hot(vec, dim=None): 42 | """ 43 | Convert a column vector with indices (normalised) to a one-hot representation. 44 | Each row is a one-hot vector corresponding to an element in the original vector. 45 | """ 46 | length = len(vec) 47 | 48 | if dim is None: # default dimension is the maximal dimension needed to represent 'vec' 49 | dim = np.max(vec) + 1 50 | 51 | m = np.tile(np.arange(dim), (length, 1)) 52 | return (vec == m) 53 | 54 | 55 | 56 | 57 | def load_mnist(): 58 | f = gzip.open('mnist.pkl.gz','rb') 59 | train_set, valid_set, test_set = cPickle.load(f) 60 | f.close() 61 | return train_set, valid_set, test_set 62 | 63 | 64 | 65 | def most_square_shape(num_blocks, blockshape=(1,1)): 66 | x, y = blockshape 67 | num_x = np.ceil(np.sqrt(num_blocks * y / float(x))) 68 | num_y = np.ceil(num_blocks / num_x) 69 | return (num_x, num_y) 70 | 71 | 72 | 73 | def visualise_filters(data, dim=6, posneg=True): 74 | """ 75 | input: a (dim*dim) x H matrix, which is reshaped into filters 76 | """ 77 | num_x, num_y = most_square_shape(data.shape[1], (dim, dim)) 78 | 79 | #pad with zeros so that the number of filters equals num_x * num_y 80 | padding = np.zeros((dim*dim, num_x*num_y - data.shape[1])) 81 | data_padded = np.hstack([data, padding]) 82 | 83 | data_split = data_padded.reshape(dim, dim, num_x, num_y) 84 | 85 | data_with_border = np.zeros((dim+1, dim+1, num_x, num_y)) 86 | data_with_border[:dim, :dim, :, :] = data_split 87 | 88 | filters = data_with_border.transpose(2,0,3,1).reshape(num_x*(dim+1), num_y*(dim+1)) 89 | 90 | filters_with_left_border = np.zeros((num_x*(dim+1)+1, num_y*(dim+1)+1)) 91 | filters_with_left_border[1:, 1:] = filters 92 | 93 | if posneg: 94 | m = np.abs(data).max() 95 | plt.imshow(filters_with_left_border, interpolation='nearest', cmap=plt.cm.RdBu, vmin=-m, vmax=m) 96 | else: 97 | plt.imshow(filters_with_left_border, interpolation='nearest', cmap=plt.cm.binary, vmin = data.min(), vmax=data.max()) 98 | 99 | 100 | -------------------------------------------------------------------------------- /cnn/utilsm.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/utilsm.pyc -------------------------------------------------------------------------------- /cnn/weights/layer0b_0.save: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnn/weights/layer0b_0.save -------------------------------------------------------------------------------- /cnninput.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/cnninput.zip -------------------------------------------------------------------------------- /crop_jul14.m: -------------------------------------------------------------------------------- 1 | clear 2 | tic 3 | load moud.txt; 4 | 5 | filePath=sprintf('cnninput'); 6 | if( exist(filePath, 'dir') ) 7 | rmdir( filePath, 's' ); 8 | end 9 | 10 | pause(10); 11 | mkdir(filePath); 12 | 13 | F = dir('F:\\MOUD\\MOUD\\VideoReviews\\transcriptions2\\*.csv'); 14 | 15 | for k1=1:10 16 | 17 | indexcnt = 1; 18 | %for ii=1:length(F) 19 | startk1 = 1+50*(k1-1); 20 | endk1 = 50*k1; 21 | if k1==10 22 | endk1 = 498; 23 | end 24 | dataall = []; 25 | datayall = []; 26 | dataind = []; 27 | 28 | for ii=startk1:endk1 29 | 30 | if moud(ii) ~= 0 && ii ~=116 31 | 32 | if moud(ii) == -1 33 | moud(ii)=0; 34 | end 35 | 36 | filename = sprintf('CLM2\\%s',F(ii).name); 37 | facexy = importdata(filename); 38 | facexy = floor(facexy); 39 | facexy2 = facexy(1,:); 40 | 41 | for nr=1:10:size(facexy,1) 42 | facexy2=[facexy2;facexy(nr,:)]; 43 | end 44 | 45 | facexy = facexy2; 46 | 47 | filename = sprintf('F:\\MOUD\\MOUD\\VideoReviews\\transcriptions2\\%s',F(ii).name); 48 | dataf=importdata(filename); 49 | 50 | dataf2 = dataf(1,:); 51 | facexy2 = facexy(1,:); 52 | 53 | for nr=1:10:size(facexy,1) 54 | 55 | dataf2 = [dataf2;dataf(nr,:)]; 56 | facexy2=[facexy2;facexy(nr,:)]; 57 | 58 | end 59 | 60 | dataf = dataf2; 61 | facexy = facexy2; 62 | 63 | miny=min(facexy(:,2:69)')'; 64 | minx=min(facexy(:,70:end)')'; 65 | maxy=max(facexy(:,2:69)')'; 66 | maxx=max(facexy(:,70:end)')'; 67 | 68 | maxpix = 250; 69 | 70 | for j=1:size(facexy,1) 71 | 72 | dataf2 = reshape(dataf(j,:),288,352); 73 | dataf2d = zeros(2*maxpix,2*maxpix); 74 | dataf2a = zeros(maxpix,maxpix); 75 | if minx(j)<=0 76 | minx(j) = 1; 77 | end 78 | if miny(j)<=0 79 | miny(j) = 1; 80 | end 81 | if maxx(j) >= 288 82 | maxx(j) = 288; 83 | end 84 | if maxy(j) >= 352 85 | maxy(j) = 352; 86 | end 87 | 88 | dataf2d(1:maxx(j)-minx(j)+1,1:maxy(j)-miny(j)+1) = dataf2(minx(j):maxx(j),miny(j):maxy(j)); 89 | dataf2a = dataf2d(1:maxpix,1:maxpix); 90 | 91 | if j==1 92 | old = dataf2a; 93 | else 94 | dataf2c = [dataf2a old]; 95 | old = dataf2a; 96 | dataf2b = dataf2c(:)'; 97 | if j==2 98 | dataf3 = dataf2b(:)'; 99 | else 100 | dataf3 = [dataf3;dataf2b(:)']; 101 | end 102 | end 103 | end 104 | 105 | dataall{indexcnt}=mat2cell(dataf3); 106 | datayall{indexcnt}=mat2cell(ones(1,size(dataf3,1))*moud(ii)); 107 | dataind{indexcnt}=mat2cell(ii*ones(1,size(dataf3,1))); 108 | indexcnt = indexcnt+1; 109 | end 110 | 111 | end 112 | 113 | for ii=1:indexcnt-1 114 | 115 | if ii==1 116 | dataall2 =cell2mat(dataall{ii}); 117 | datayall2 = cell2mat(datayall{ii}); 118 | dataind2 = cell2mat(dataind{ii}); 119 | else 120 | dataall2 = [dataall2; cell2mat(dataall{ii})]; 121 | datayall2 = [datayall2 cell2mat(datayall{ii})]; 122 | dataind2 = [dataind2 cell2mat(dataind{ii})]; 123 | end 124 | 125 | end 126 | 127 | filePath=sprintf('cnninput\\x50_%d',k1); 128 | if( exist(filePath, 'dir') ) 129 | rmdir( filePath, 's' ); 130 | end 131 | 132 | pause(10); 133 | mkdir(filePath); 134 | 135 | 136 | filename = sprintf('%s\\x50.txt',filePath); 137 | dlmwrite(filename,dataall2); 138 | filename = sprintf('%s\\y50.txt',filePath); 139 | dlmwrite(filename,datayall2'); 140 | filename = sprintf('%s\\ind.txt',filePath); 141 | dlmwrite(filename,dataind2'); 142 | 143 | 144 | end 145 | toc -------------------------------------------------------------------------------- /maketrain.m: -------------------------------------------------------------------------------- 1 | for k=1:10 2 | dataallx = []; 3 | dataally = []; 4 | 5 | for j=1:10 6 | 7 | if k~=j 8 | 9 | filename = sprintf('cnninput/x50_%d/x50b.txt',j); 10 | trainx = importdata(filename); 11 | filename = sprintf('cnninput/x50_%d/y50.txt',j); 12 | trainy = importdata(filename); 13 | 14 | if size(dataallx,1)<2 15 | dataallx = [trainx]; 16 | dataally = [trainy]; 17 | else 18 | dataallx = [dataallx;trainx]; 19 | dataally = [dataally;trainy]; 20 | end 21 | 22 | end 23 | 24 | 25 | end 26 | 27 | n1 = floor(0.7*size(dataallx,1)); 28 | 29 | trainx = dataallx(1:n1,:); 30 | trainy = dataally(1:n1,:); 31 | 32 | valx = dataallx(n1+1:end,:); 33 | valy = dataally(n1+1:end,:); 34 | 35 | filename = sprintf('cnninput/x50_%d/trainx.txt',k); 36 | dlmwrite(filename,trainx); 37 | filename = sprintf('cnninput/x50_%d/trainy.txt',k); 38 | dlmwrite(filename,trainy); 39 | filename = sprintf('cnninput/x50_%d/valx.txt',k); 40 | dlmwrite(filename,valx); 41 | filename = sprintf('cnninput/x50_%d/valy.txt',k); 42 | dlmwrite(filename,valy); 43 | 44 | end 45 | -------------------------------------------------------------------------------- /pack_Data_foldb.py: -------------------------------------------------------------------------------- 1 | from numpy import genfromtxt 2 | import gzip, cPickle 3 | 4 | dirg = 'run2/' 5 | 6 | for i in range(10): 7 | 8 | k = i; 9 | name1 = dirg+'/trainb_cnn'+str(k) 10 | #train_set_x = genfromtxt(name, delimiter=',') 11 | name2 = dirg+'/train'+str(k)+'_y' 12 | #train_set_y = genfromtxt(name, delimiter=',') 13 | 14 | #train_set = train_set_x, train_set_y 15 | train_set= genfromtxt(name1, delimiter=','), genfromtxt(name2, delimiter=',') 16 | #del train_set_x 17 | #del train_set_y 18 | 19 | name1 = dirg+'/testb_cnn'+str(k) 20 | #test_set_x = genfromtxt(name, delimiter=',') 21 | name2 = dirg+'/test'+str(k)+'_y' 22 | #test_set_y = genfromtxt(name, delimiter=',') 23 | #test_set = test_set_x, test_set_y 24 | test_set = genfromtxt(name1, delimiter=','), genfromtxt(name2, delimiter=',') 25 | #del test_set_x 26 | #del test_set_y 27 | 28 | name1 = dirg+'/valb_cnn'+str(k) 29 | #val_set_x = genfromtxt(name, delimiter=',') 30 | name2 = dirg+'/val'+str(k)+'_y' 31 | #val_set_y = genfromtxt(name, delimiter=',') 32 | #val_set = val_set_x, val_set_y 33 | #del val_set_x 34 | #del val_set_y 35 | val_set = genfromtxt(name1, delimiter=','), genfromtxt(name2, delimiter=',') 36 | 37 | dataset = [train_set, val_set, test_set] 38 | del train_set 39 | del val_set 40 | del test_set 41 | 42 | name = dirg+'mpqa_spab'+str(k)+'.pkl.gz' 43 | f = gzip.open(name,'wb') 44 | cPickle.dump(dataset, f, protocol=2) 45 | f.close() 46 | -------------------------------------------------------------------------------- /readdata.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | F = dir('videos\*.mp4'); 4 | for ii = 2:length(F) 5 | 6 | [pathi,name,ext] = fileparts(F(ii).name); 7 | 8 | filename = sprintf('videos\\%s',F(ii).name); 9 | obj = mmreader(filename); 10 | filename = sprintf('transcriptions3\\%s.csv',name); 11 | %filename = 'VideoReviews\transcriptions2\100_makeup.csv' 12 | if exist(filename, 'file') == 2 13 | 14 | time = importdata(filename); 15 | time = time.data; 16 | data = obj.read(); 17 | 18 | [x,y,n,f]=size(data); 19 | data2 = zeros(x*y,1); 20 | 21 | for i=1:f 22 | a=rgb2gray(data(:,:,:,i)); 23 | 24 | b = a(:); 25 | data2 = [data2 b]; 26 | 27 | end 28 | data2 = data2(:,2:end); 29 | data2 = data2'; 30 | [n1 n2] = size(time); 31 | for i=1:n1 32 | startf = floor(time(i,1)*obj.FrameRate); 33 | endf = floor(time(i,2)*obj.FrameRate); 34 | if startf==0 35 | startf=1; 36 | end 37 | if endf > f 38 | endf = f; 39 | end 40 | data3 = data2(startf:endf,:); 41 | filename = sprintf('transcriptions2\\%s_%d.csv',name,i); 42 | % filename = sprintf('VideoReviews\transcriptions2\100_makeup_%d.csv',i); 43 | dlmwrite(filename,data3); 44 | end 45 | 46 | end 47 | %data2 = data2(:,2:end); 48 | %dlmwrite('100_makeup.txt',data2); 49 | end -------------------------------------------------------------------------------- /resizeall.m: -------------------------------------------------------------------------------- 1 | 2 | for k=1:10 3 | 4 | filename = sprintf('cnninput/x50_%d/x50.txt',k); 5 | data = importdata(filename); 6 | 7 | for i=1:size(data,1) 8 | 9 | img1 = reshape(data(i,:),250,500); 10 | img2 = imresize(img1,0.5); 11 | if i==1 12 | new = img2(:)'; 13 | else 14 | new = [new; img2(:)']; 15 | end 16 | 17 | end 18 | 19 | filename = sprintf('cnninput/x50_%d/x50b.txt',k); 20 | dlmwrite(filename,new); 21 | end -------------------------------------------------------------------------------- /time.pl: -------------------------------------------------------------------------------- 1 | 2 | 3 | my $dir = 'transcriptions'; 4 | my $dir2 = 'transcriptions3'; 5 | 6 | opendir(DIR, $dir) or die $!; 7 | 8 | while (my $file = readdir(DIR)) { 9 | 10 | # Use a regular expression to ignore files beginning with a period 11 | next if ($file =~ m/^\./); 12 | 13 | open(FILE, "$dir/$file"); 14 | open(OUT, ">$dir2/$file"); 15 | while($line = ) 16 | { 17 | @list = (); 18 | @list = split "\;",$line; 19 | print OUT "$list[0],$list[1]\n"; 20 | } 21 | close(FILE); 22 | close(OUT); 23 | 24 | print "$file\n"; 25 | 26 | } 27 | 28 | closedir(DIR); -------------------------------------------------------------------------------- /transcriptions/100_makeup.csv: -------------------------------------------------------------------------------- 1 | "#starttime";"#endtime";"transcription";"sentimentAnnotations" 2 | 0.000;3.642;"yo habia visto resenas que decian que picaba cuando la usabas";"-1" 3 | 3.642;9.552;"y la verdad es que si la use una vez y t- y te arde asi// donde lo usas te arde el ojo";"-1" 4 | 9.552;14.197;"y dije no: puede ser posible tanto la deseaba me arde y no la voy a poder usar";"-1" 5 | 14.197;20.545;"esta tambien tira un poquito de pelo pero hagan de cuenta como que se quebra:ba el pelito y es lo que se caia el pelito y es lo que se caia";"-1" 6 | 20.545;23.275;"pero igual con las lavadas se ha dejado de tirar //";"1" 7 | 23.275;27.533;"em: se lavan super facil, se secan rapido se secan rapido //";"1" 8 | 27.533;31.004;"y: bueno con las lavadas ya no: raspa tanto ya no raspa tanto";"1" 9 | 31.004;32.600;"ya esta soportable";"1" 10 | 32.600;34.133;"// pues si: pica un p-";"-1" 11 | -------------------------------------------------------------------------------- /transcriptions/100_makeup.trs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | yo habia visto resenas 9 | 10 | que decian que picaba cuando la usabas 11 | 12 | y la verdad es que si la use una vez 13 | 14 | y t- y te arde asi// donde lo usas te arde el ojo 15 | 16 | y dije no: puede ser posible tanto la deseaba me arde y no la voy a poder usar 17 | 18 | esta tambien tira un poquito de pelo pero hagan de cuenta como que se quebra:ba el pelito y es lo que se caiael pelito y es lo que se caia 19 | 20 | pero igual con las lavadas se ha dejado de tirar 21 | 22 | // 23 | 24 | em: se lavan super facil, se secan rapido se secan rapido 25 | 26 | // 27 | 28 | y: bueno con las lavadas ya no: raspa tanto ya no raspa tanto 29 | 30 | ya esta soportable// pues si: pica un p- 31 | 32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /transcriptions/101_movies.csv: -------------------------------------------------------------------------------- 1 | "#starttime";"#endtime";"transcription";"sentimentAnnotations" 2 | 0.000;6.643;"Y lo que me encanto de esta pelicula es que es:te recurso lo utilizan m:uy, bien porque la c- calidad de la imagen se ve muy bien";"1" 3 | 6.643;17.290;"luego pues cada tenemos esta historia que esta muy: interesante, la verdad es que desde el principio te atrapa y toda la pelicula yo la neta no queria que se acabara la pelicula porque es dia de que tiene super poderes y ahora:, que voy a hacer con ellos ";"1" 4 | 17.290;23.475;"esta su:per interesante, porque ya: la neta todos siempre queremos tener superpoderes y vivimos pensando que algun dia vamos a tener superpoderes.";"1" 5 | 23.475;26.714;"Y: despues de ver la pelicula piensas mas que vas a tener superpoderes,";"1" 6 | 26.714;33.367;"entonces, como agarro a estos tres personajes que se ven tan: comunes, tan: normales, que tienen una relacion como de amigos muy realista, y darles estos superpo-";"1" 7 | -------------------------------------------------------------------------------- /transcriptions/101_movies.trs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | Y lo que me encanto de esta pelicula es que es:te recurso lo utilizan m:uy, bien porque la c- calidad de la imagen se ve muy bien 9 | 10 | luego pues cada tenemos esta historia que esta muy: interesante, la verdad es que desde el principio te atrapa y toda la pelicula yo la neta no queria que se acabara la pelicula porque 11 | 12 | es dia de que tiene super poderes y ahora:, que voy a hacer con ellos esta su:per interesante, porque ya: la neta todos siempre queremos tener superpoderes y vivimos pensando que algun dia vamos a tener superpoderes. 13 | 14 | Y: despues de ver la pelicula piensas mas que vas a tener superpoderes, 15 | 16 | entonces, como agarro a estos tres personajes que se ven tan: comunes, tan: normales, que tienen una relacion como de amigos muy realista, y darles estos superpo- 17 | 18 |
19 |
20 |
21 | -------------------------------------------------------------------------------- /transcriptions/102_books.csv: -------------------------------------------------------------------------------- 1 | "#starttime";"#endtime";"transcription";"sentimentAnnotations" 2 | 0.000;4.956;"Este resumen no les- no le hace justicia, esta: padri:simo el libro";"1" 3 | 4.956;7.954;"es uno de los mejores libros que he leido en muchisimo tiempo la verdad,";"1" 4 | 7.954;13.305;"y como les habia dicho en mi video anterior. Si a ustedes les gusta Harry Potter, seguramente les van a gustar Cazadores de Sombras.";"1" 5 | 13.305;19.397;"No porque se parezca la historia sino porque: tratan asi tem- temas: magicos cosas mitologicas y cosas asi";"1" 6 | 19.397;34.133;"lo que mas me gusto de este libro es que ya cuando llegas al final te lo cambian todo y pasa algo que de veras no te esperaba y eso siempre me gusta el que hagan plot twist me encantan porque me traen cosas que yo no me esperaba y que le agregan mucho mas a la historia y te dan ganas de seguir leyendo los libro-";"1" 7 | -------------------------------------------------------------------------------- /transcriptions/102_books.trs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | Este resumen no les- no le hace justicia, esta: padri:simo el libro 9 | 10 | es uno de los mejores libros que he leido en muchisimo tiempo la verdad, 11 | 12 | y como les habia dicho en mi video anterior. Si a ustedes les gusta Harry Potter, seguramente les van a gustar Cazadores de Sombras. 13 | 14 | No porque se parezca la historia sino porque: tratan asi tem- temas: magicos cosas mitologicas y cosas asi 15 | 16 | lo que mas me gusto de este libro es que ya cuando llegas al final te lo cambian todo y pasa algo que de veras no te esperaba y eso siempre me gusta el que hagan plot twist me encantan porque me traen cosas que yo no me esperaba y que le agregan mucho mas a la historia y te dan ganas de seguir leyendo los libro- 17 | 18 |
19 |
20 |
21 | -------------------------------------------------------------------------------- /transcriptions/103_books.csv: -------------------------------------------------------------------------------- 1 | "#starttime";"#endtime";"transcription";"sentimentAnnotations" 2 | 0.000;1.478;"pero de verdad lo recomiendo";"1" 3 | 1.478;5.234;"porque es que: eh: tiene de todo o sea no es el:";"1" 4 | 5.234;7.567;"no he leido nunca ningun libro de esos zombies";"-1" 5 | 7.567;11.761;"pero de peliculas y tal a mi que tampoco me suelen hacer mucha gracia salvo que Walking Dead";"1" 6 | 11.761;15.415;"que la verdad no me gusta, pero no estamos hablando de eso //";"-1" 7 | 15.415;21.180;"me ha: gustado mucho porque es: Diario de un zombie es: lo que cuenta el es una perso:na";"1" 8 | 21.180;26.772;"una persona que: se ha convertido en zombie pero realmente piensa como una persona";"1" 9 | 26.772;30.325;"y bueno y: tiene muchos momentos de risa de cachondeo";"1" 10 | 30.325;35.131;"momentos tristes de tension con unas- describe las cosas muy: bien // des-";"1" 11 | -------------------------------------------------------------------------------- /transcriptions/103_books.trs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | pero de verdad lo recomiendo 9 | 10 | porque es que: eh: tiene de todo o sea no es el: 11 | 12 | no he leido nunca ningun libro de esos zombies 13 | 14 | pero de peliculas y tal a mi que tampoco me suelen hacer mucha gracia salvo que Walking Dead 15 | 16 | que la verdad no me gusta pero 17 | 18 | no estamos hablando de eso 19 | 20 | // 21 | 22 | me ha: gustado mucho porque es: Diario de un zombie es: lo que cuenta el es una perso:na 23 | 24 | una persona 25 | 26 | que: se ha convertido en zombie pero realmente piensa como una persona 27 | 28 | y bueno 29 | 30 | y: tiene muchos momentos de risa de cachondeo 31 | 32 | momentos tristes de tension con unas- describe las cosas muy: bien 33 | 34 | // 35 | 36 | des- 37 | 38 |
39 |
40 |
41 | -------------------------------------------------------------------------------- /transcriptions/104_makeup.csv: -------------------------------------------------------------------------------- 1 | "#starttime";"#endtime";"Speech";"sentimentAnnotations" 2 | 0.000;3.540;"mm: y- hara su efecto aunque: no lo notes";"1" 3 | 3.540;13.890;"pero lo que no me gusta de este: de este producto, es que cuando les das, a ver si lo puedo hacer, // sale muchi:simo, disparado en linea recta.";"-1" 4 | 13.890;21.122;"En vez de ser un spray que se difumine y te caiga mas producto en el pelo, te cae solamente en un sitio del pelo muchisima cantidad de producto.";"-1" 5 | 21.122;26.010;"Asi que: sera buen producto pero yo no: // eh: no me gusta ";"-1" 6 | 26.010;29.820;"Es que es mm: no me lo puedo echar bien por el pelo sin echarme muchisimo producto.";"-1" 7 | 29.820;31.765;"asi que, // no lo recomiendo si s-";"-1" 8 | -------------------------------------------------------------------------------- /transcriptions/cats.txt: -------------------------------------------------------------------------------- 1 | 100_makeup_1 negative 2 | 100_makeup_2 negative 3 | 100_makeup_3 negative 4 | 100_makeup_4 negative 5 | 100_makeup_5 positive 6 | 100_makeup_6 positive 7 | 100_makeup_7 positive 8 | 100_makeup_8 positive 9 | 100_makeup_9 negative 10 | 101_movies_1 positive 11 | 101_movies_2 positive 12 | 101_movies_3 positive 13 | 101_movies_4 positive 14 | 101_movies_5 positive 15 | 102_books_1 positive 16 | 102_books_2 positive 17 | 102_books_3 positive 18 | 102_books_4 positive 19 | 102_books_5 positive 20 | 103_books_1 positive 21 | 103_books_2 positive 22 | 103_books_3 negative 23 | 103_books_4 positive 24 | 103_books_5 negative 25 | 103_books_6 positive 26 | 103_books_7 positive 27 | 103_books_8 positive 28 | 103_books_9 positive 29 | 104_makeup_1 positive 30 | 104_makeup_2 negative 31 | 104_makeup_3 negative 32 | 104_makeup_4 negative 33 | 104_makeup_5 negative 34 | 104_makeup_6 negative 35 | 105_makeup_1 negative 36 | 105_makeup_2 positive 37 | 105_makeup_3 negative 38 | 105_makeup_4 negative 39 | 105_makeup_5 negative 40 | 105_makeup_6 negative 41 | 105_makeup_7 negative 42 | 105_makeup_8 negative 43 | 105_makeup_9 positive 44 | 107_makeup_1 negative 45 | 107_makeup_2 positive 46 | 107_makeup_3 negative 47 | 107_makeup_4 negative 48 | 107_makeup_5 negative 49 | 107_makeup_6 negative 50 | 107_makeup_7 negative 51 | 107_makeup_8 negative 52 | 107_makeup_9 negative 53 | 108_makeup_1 negative 54 | 108_makeup_2 negative 55 | 108_makeup_3 negative 56 | 108_makeup_4 negative 57 | 108_makeup_5 negative 58 | 108_makeup_6 negative 59 | 109_books_1 positive 60 | 109_books_2 positive 61 | 109_books_3 positive 62 | 109_books_4 neutral 63 | 109_books_5 neutral 64 | 109_books_6 neutral 65 | 110_perfume_1 positive 66 | 110_perfume_2 positive 67 | 110_perfume_3 positive 68 | 110_perfume_4 positive 69 | 110_perfume_5 positive 70 | 110_perfume_6 positive 71 | 111_makeup_1 neutral 72 | 111_makeup_2 negative 73 | 111_makeup_3 negative 74 | 111_makeup_4 negative 75 | 111_makeup_5 negative 76 | 111_makeup_6 negative 77 | 112_makeup_1 negative 78 | 112_makeup_2 negative 79 | 112_makeup_3 negative 80 | 112_makeup_4 positive 81 | 112_makeup_5 negative 82 | 112_makeup_6 negative 83 | 112_makeup_7 negative 84 | 113_makeup_1 negative 85 | 113_makeup_2 negative 86 | 113_makeup_3 negative 87 | 113_makeup_4 negative 88 | 113_makeup_5 positive 89 | 113_makeup_6 positive 90 | 113_makeup_7 negative 91 | 114_perfume_1 positive 92 | 114_perfume_2 positive 93 | 114_perfume_3 positive 94 | 114_perfume_4 positive 95 | 114_perfume_5 neutral 96 | 115_makeup_1 negative 97 | 115_makeup_2 negative 98 | 115_makeup_3 negative 99 | 115_makeup_4 negative 100 | 115_makeup_5 negative 101 | 116_makeup_1 negative 102 | 116_makeup_2 negative 103 | 116_makeup_3 negative 104 | 116_makeup_4 negative 105 | 116_makeup_5 negative 106 | 117_perfume_1 positive 107 | 117_perfume_2 positive 108 | 117_perfume_3 positive 109 | 117_perfume_4 positive 110 | 117_perfume_5 positive 111 | 117_perfume_6 neutral 112 | 119_makeup_1 negative 113 | 119_makeup_2 negative 114 | 119_makeup_3 negative 115 | 119_makeup_4 negative 116 | 119_makeup_5 negative 117 | 119_makeup_6 negative 118 | 121_movies_1 negative 119 | 121_movies_2 negative 120 | 121_movies_3 positive 121 | 121_movies_4 positive 122 | 121_movies_5 neutral 123 | 122_movies_1 positive 124 | 122_movies_2 positive 125 | 122_movies_3 positive 126 | 122_movies_4 positive 127 | 122_movies_5 positive 128 | 126_movies_1 negative 129 | 126_movies_2 negative 130 | 126_movies_3 negative 131 | 126_movies_4 negative 132 | 126_movies_5 negative 133 | 126_movies_6 negative 134 | 127_movies_1 positive 135 | 127_movies_2 positive 136 | 127_movies_3 positive 137 | 127_movies_4 positive 138 | 127_movies_5 positive 139 | 128_movies_1 negative 140 | 128_movies_2 negative 141 | 128_movies_3 positive 142 | 128_movies_4 negative 143 | 128_movies_5 negative 144 | 128_movies_6 negative 145 | 129_movies_1 positive 146 | 129_movies_2 positive 147 | 129_movies_3 positive 148 | 129_movies_4 negative 149 | 129_movies_5 positive 150 | 129_movies_6 negative 151 | 129_movies_7 neutral 152 | 130_makeup_1 negative 153 | 130_makeup_2 positive 154 | 130_makeup_3 negative 155 | 130_makeup_4 negative 156 | 130_makeup_5 positive 157 | 130_makeup_6 negative 158 | 131_makeup_1 negative 159 | 131_makeup_2 neutral 160 | 131_makeup_3 negative 161 | 131_makeup_4 positive 162 | 131_makeup_5 negative 163 | 131_makeup_6 positive 164 | 132_makeup_1 negative 165 | 132_makeup_2 negative 166 | 132_makeup_3 positive 167 | 132_makeup_4 negative 168 | 132_makeup_5 negative 169 | 132_makeup_6 negative 170 | 132_makeup_7 negative 171 | 132_makeup_8 negative 172 | 132_makeup_9 negative 173 | 133_books_1 negative 174 | 133_books_2 negative 175 | 133_books_3 negative 176 | 133_books_4 negative 177 | 133_books_5 negative 178 | 134_makeup_1 positive 179 | 134_makeup_2 positive 180 | 134_makeup_3 positive 181 | 134_makeup_4 positive 182 | 137_books_1 positive 183 | 137_books_2 positive 184 | 137_books_3 positive 185 | 137_books_4 positive 186 | 137_books_5 positive 187 | 137_books_6 positive 188 | 138_books_1 positive 189 | 138_books_2 positive 190 | 138_books_3 positive 191 | 138_books_4 positive 192 | 138_books_5 positive 193 | 138_books_6 positive 194 | 138_books_7 positive 195 | 138_books_8 positive 196 | 139_books_1 positive 197 | 139_books_2 positive 198 | 139_books_3 positive 199 | 139_books_4 positive 200 | 139_books_5 positive 201 | 139_books_6 negative 202 | 139_books_7 neutral 203 | 139_books_8 positive 204 | 140_books_1 positive 205 | 140_books_2 neutral 206 | 140_books_3 neutral 207 | 140_books_4 positive 208 | 140_books_5 positive 209 | 140_books_6 neutral 210 | 141_books_1 positive 211 | 141_books_2 positive 212 | 141_books_3 negative 213 | 141_books_4 positive 214 | 141_books_5 positive 215 | 143_makeup_1 negative 216 | 143_makeup_2 negative 217 | 143_makeup_3 negative 218 | 143_makeup_4 negative 219 | 143_makeup_5 negative 220 | 143_makeup_6 negative 221 | 143_makeup_7 negative 222 | 143_makeup_8 negative 223 | 143_makeup_9 negative 224 | 143_makeup_10 neutral 225 | 144_makeup_1 neutral 226 | 144_makeup_2 negative 227 | 144_makeup_3 negative 228 | 144_makeup_4 positive 229 | 144_makeup_5 negative 230 | 144_makeup_6 neutral 231 | 144_makeup_7 negative 232 | 144_makeup_8 positive 233 | 144_makeup_9 neutral 234 | 145_makeup_1 negative 235 | 145_makeup_2 negative 236 | 145_makeup_3 negative 237 | 145_makeup_4 negative 238 | 145_makeup_5 neutral 239 | 145_makeup_6 positive 240 | 145_makeup_7 negative 241 | 145_makeup_8 neutral 242 | 145_makeup_9 neutral 243 | 145_makeup_10 neutral 244 | 146_makeup_1 negative 245 | 146_makeup_2 negative 246 | 146_makeup_3 negative 247 | 146_makeup_4 negative 248 | 146_makeup_5 positive 249 | 146_makeup_6 negative 250 | 147_makeup_1 neutral 251 | 147_makeup_2 positive 252 | 147_makeup_3 positive 253 | 147_makeup_4 negative 254 | 147_makeup_5 negative 255 | 149_perfume_1 negative 256 | 149_perfume_2 negative 257 | 149_perfume_3 negative 258 | 149_perfume_4 negative 259 | 149_perfume_5 negative 260 | 149_perfume_6 positive 261 | 149_perfume_7 positive 262 | 149_perfume_8 neutral 263 | 149_perfume_9 positive 264 | 150_makeup_1 negative 265 | 150_makeup_2 negative 266 | 150_makeup_3 negative 267 | 150_makeup_4 negative 268 | 150_makeup_5 negative 269 | 150_makeup_6 positive 270 | 151_makeup_1 positive 271 | 151_makeup_2 negative 272 | 151_makeup_3 positive 273 | 151_makeup_4 positive 274 | 151_makeup_5 positive 275 | 151_makeup_6 positive 276 | 153_books_1 neutral 277 | 153_books_2 positive 278 | 153_books_3 negative 279 | 153_books_4 positive 280 | 153_books_5 positive 281 | 153_books_6 neutral 282 | 153_books_7 positive 283 | 157_books_1 positive 284 | 157_books_2 positive 285 | 157_books_3 positive 286 | 157_books_4 neutral 287 | 157_books_5 positive 288 | 157_books_6 positive 289 | 158_books_1 neutral 290 | 158_books_2 positive 291 | 158_books_3 positive 292 | 158_books_4 positive 293 | 158_books_5 neutral 294 | 159_books_1 neutral 295 | 159_books_2 positive 296 | 159_books_3 positive 297 | 159_books_4 negative 298 | 159_books_5 positive 299 | 159_books_6 neutral 300 | 160_movies_1 negative 301 | 160_movies_2 negative 302 | 160_movies_3 negative 303 | 160_movies_4 negative 304 | 160_movies_5 negative 305 | 161_book_1 positive 306 | 161_book_2 positive 307 | 161_book_3 neutral 308 | 161_book_4 positive 309 | 161_book_5 positive 310 | 161_book_6 positive 311 | 161_book_7 neutral 312 | 161_book_8 positive 313 | 162_books_1 negative 314 | 162_books_2 negative 315 | 162_books_3 negative 316 | 162_books_4 positive 317 | 162_books_5 negative 318 | 162_books_6 negative 319 | 162_books_7 negative 320 | 163_books_1 positive 321 | 163_books_2 neutral 322 | 163_books_3 neutral 323 | 163_books_4 positive 324 | 163_books_5 positive 325 | 163_books_6 positive 326 | 164_books_1 positive 327 | 164_books_2 neutral 328 | 164_books_3 positive 329 | 164_books_4 neutral 330 | 164_books_5 positive 331 | 165_makeup_1 positive 332 | 165_makeup_2 positive 333 | 165_makeup_3 positive 334 | 165_makeup_4 positive 335 | 166_movies_1 positive 336 | 166_movies_2 positive 337 | 166_movies_3 positive 338 | 166_movies_4 positive 339 | 166_movies_5 positive 340 | 168_makeup_1 negative 341 | 168_makeup_2 negative 342 | 168_makeup_3 negative 343 | 168_makeup_4 negative 344 | 168_makeup_5 negative 345 | 168_makeup_6 neutral 346 | 170_makeup_1 neutral 347 | 170_makeup_2 neutral 348 | 170_makeup_3 neutral 349 | 170_makeup_4 positive 350 | 170_makeup_5 neutral 351 | 170_makeup_6 negative 352 | 170_makeup_7 neutral 353 | 171_makeup_1 negative 354 | 171_makeup_2 negative 355 | 171_makeup_3 negative 356 | 171_makeup_4 negative 357 | 173_makeup_1 negative 358 | 173_makeup_2 negative 359 | 173_makeup_3 negative 360 | 173_makeup_4 negative 361 | 173_makeup_5 negative 362 | 174_makeup_1 negative 363 | 174_makeup_2 negative 364 | 174_makeup_3 negative 365 | 174_makeup_4 negative 366 | 174_makeup_5 negative 367 | 174_makeup_6 negative 368 | 175_makeup_1 negative 369 | 175_makeup_2 negative 370 | 175_makeup_3 negative 371 | 175_makeup_4 negative 372 | 175_makeup_5 negative 373 | 177_makeup_1 negative 374 | 177_makeup_2 positive 375 | 177_makeup_3 negative 376 | 177_makeup_4 negative 377 | 177_makeup_5 negative 378 | 177_makeup_6 negative 379 | 178_makeup_1 negative 380 | 178_makeup_2 negative 381 | 178_makeup_3 negative 382 | 178_makeup_4 negative 383 | 178_makeup_5 positive 384 | 179_makeup_1 negative 385 | 179_makeup_2 positive 386 | 179_makeup_3 negative 387 | 179_makeup_4 negative 388 | 179_makeup_5 negative 389 | 179_makeup_6 positive 390 | 179_makeup_7 neutral 391 | 180_makeup_1 negative 392 | 180_makeup_2 negative 393 | 180_makeup_3 negative 394 | 180_makeup_4 negative 395 | 180_makeup_5 positive 396 | 180_makeup_6 negative 397 | 180_makeup_7 negative 398 | 181_makeup_1 neutral 399 | 181_makeup_2 negative 400 | 181_makeup_3 negative 401 | 181_makeup_4 negative 402 | 181_makeup_5 negative 403 | 181_makeup_6 negative 404 | 181_makeup_7 negative 405 | 181_makeup_8 negative 406 | 183_books_1 positive 407 | 183_books_2 positive 408 | 183_books_3 positive 409 | 183_books_4 positive 410 | 183_books_5 positive 411 | 183_books_6 positive 412 | 183_books_7 positive 413 | 183_books_8 positive 414 | 184_makeup_1 negative 415 | 184_makeup_2 negative 416 | 184_makeup_3 negative 417 | 184_makeup_4 negative 418 | 184_makeup_5 negative 419 | 184_makeup_6 negative 420 | 184_makeup_7 negative 421 | 184_makeup_8 negative 422 | 184_makeup_9 negative 423 | 186_makeup_1 negative 424 | 186_makeup_2 negative 425 | 186_makeup_3 negative 426 | 186_makeup_4 negative 427 | 186_makeup_5 positive 428 | 186_makeup_6 negative 429 | 187_books_1 neutral 430 | 187_books_2 negative 431 | 187_books_3 negative 432 | 187_books_4 negative 433 | 187_books_5 negative 434 | 187_books_6 negative 435 | 187_books_7 negative 436 | 187_books_8 negative 437 | 188_books_1 neutral 438 | 188_books_2 negative 439 | 188_books_3 negative 440 | 188_books_4 negative 441 | 188_books_5 negative 442 | 189_movies_1 negative 443 | 189_movies_2 negative 444 | 189_movies_3 negative 445 | 189_movies_4 negative 446 | 189_movies_5 negative 447 | 190_movies_1 negative 448 | 190_movies_2 negative 449 | 190_movies_3 positive 450 | 190_movies_4 positive 451 | 190_movies_5 negative 452 | 191_makeup_1 neutral 453 | 191_makeup_2 positive 454 | 191_makeup_3 positive 455 | 191_makeup_4 positive 456 | 191_makeup_5 negative 457 | 191_makeup_6 positive 458 | 191_makeup_7 positive 459 | 193_books_1 negative 460 | 193_books_2 negative 461 | 193_books_3 positive 462 | 193_books_4 negative 463 | 193_books_5 negative 464 | 193_books_6 negative 465 | 193_books_7 negative 466 | 194_books_1 positive 467 | 194_books_2 negative 468 | 194_books_3 positive 469 | 194_books_4 positive 470 | 194_books_5 positive 471 | 196_books_1 positive 472 | 196_books_2 positive 473 | 196_books_3 positive 474 | 197_books_1 positive 475 | 197_books_2 positive 476 | 197_books_3 positive 477 | 197_books_4 positive 478 | 197_books_5 negative 479 | 197_books_6 positive 480 | 198_books_1 positive 481 | 198_books_2 positive 482 | 198_books_3 positive 483 | 198_books_4 positive 484 | 198_books_5 positive 485 | 198_books_6 positive 486 | 198_books_7 positive 487 | 198_books_8 positive 488 | 198_books_9 neutral 489 | 199_books_1 positive 490 | 199_books_2 positive 491 | 199_books_3 negative 492 | 199_books_4 negative 493 | 200_books_1 positive 494 | 200_books_2 positive 495 | 200_books_3 positive 496 | 200_books_4 negative 497 | 200_books_5 positive 498 | 200_books_6 positive -------------------------------------------------------------------------------- /transcriptions2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/transcriptions2.zip -------------------------------------------------------------------------------- /transcriptions3/100_makeup.csv: -------------------------------------------------------------------------------- 1 | "#starttime","#endtime" 2 | 0.000,3.642 3 | 3.642,9.552 4 | 9.552,14.197 5 | 14.197,20.545 6 | 20.545,23.275 7 | 23.275,27.533 8 | 27.533,31.004 9 | 31.004,32.600 10 | 32.600,34.133 11 | -------------------------------------------------------------------------------- /transcriptions3/100_makeup.trs: -------------------------------------------------------------------------------- 1 | 2 | , 3 | 4 | , 5 | 6 | , 7 | 8 | , 9 |
10 | , 11 | 12 | , 13 | 14 | , 15 | yo habia visto resenas 16 | , 17 | 18 | , 19 | que decian que picaba cuando la usabas 20 | , 21 | 22 | , 23 | y la verdad es que si la use una vez 24 | , 25 | 26 | , 27 | y t- y te arde asi// donde lo usas te arde el ojo 28 | , 29 | 30 | , 31 | y dije no: puede ser posible tanto la deseaba me arde y no la voy a poder usar 32 | , 33 | 34 | , 35 | esta tambien tira un poquito de pelo pero hagan de cuenta como que se quebra:ba el pelito y es lo que se caiael pelito y es lo que se caia 36 | , 37 | 38 | , 39 | pero igual con las lavadas se ha dejado de tirar 40 | , 41 | 42 | , 43 | // 44 | , 45 | 46 | , 47 | em: se lavan super facil, se secan rapido se secan rapido 48 | , 49 | 50 | , 51 | // 52 | , 53 | 54 | , 55 | y: bueno con las lavadas ya no: raspa tanto ya no raspa tanto 56 | , 57 | 58 | , 59 | ya esta soportable// pues si: pica un p- 60 | , 61 | 62 | , 63 |
64 | , 65 |
66 | , 67 |
68 | , 69 | -------------------------------------------------------------------------------- /transcriptions3/101_movies.csv: -------------------------------------------------------------------------------- 1 | "#starttime","#endtime" 2 | 0.000,6.643 3 | 6.643,17.290 4 | 17.290,23.475 5 | 23.475,26.714 6 | 26.714,33.367 7 | -------------------------------------------------------------------------------- /transcriptions3/101_movies.trs: -------------------------------------------------------------------------------- 1 | 2 | , 3 | 4 | , 5 | 6 | , 7 | 8 | , 9 |
10 | , 11 | 12 | , 13 | 14 | , 15 | Y lo que me encanto de esta pelicula es que es:te recurso lo utilizan m:uy, bien porque la c- calidad de la imagen se ve muy bien 16 | , 17 | 18 | , 19 | luego pues cada tenemos esta historia que esta muy: interesante, la verdad es que desde el principio te atrapa y toda la pelicula yo la neta no queria que se acabara la pelicula porque 20 | , 21 | 22 | , 23 | es dia de que tiene super poderes y ahora:, que voy a hacer con ellos esta su:per interesante, porque ya: la neta todos siempre queremos tener superpoderes y vivimos pensando que algun dia vamos a tener superpoderes. 24 | , 25 | 26 | , 27 | Y: despues de ver la pelicula piensas mas que vas a tener superpoderes, 28 | , 29 | 30 | , 31 | entonces, como agarro a estos tres personajes que se ven tan: comunes, tan: normales, que tienen una relacion como de amigos muy realista, y darles estos superpo- 32 | , 33 | 34 | , 35 |
36 | , 37 |
38 | , 39 |
40 | , 41 | -------------------------------------------------------------------------------- /transcriptions3/102_books.csv: -------------------------------------------------------------------------------- 1 | "#starttime","#endtime" 2 | 0.000,4.956 3 | 4.956,7.954 4 | 7.954,13.305 5 | 13.305,19.397 6 | 19.397,34.133 7 | -------------------------------------------------------------------------------- /transcriptions3/102_books.trs: -------------------------------------------------------------------------------- 1 | 2 | , 3 | 4 | , 5 | 6 | , 7 | 8 | , 9 |
10 | , 11 | 12 | , 13 | 14 | , 15 | Este resumen no les- no le hace justicia, esta: padri:simo el libro 16 | , 17 | 18 | , 19 | es uno de los mejores libros que he leido en muchisimo tiempo la verdad, 20 | , 21 | 22 | , 23 | y como les habia dicho en mi video anterior. Si a ustedes les gusta Harry Potter, seguramente les van a gustar Cazadores de Sombras. 24 | , 25 | 26 | , 27 | No porque se parezca la historia sino porque: tratan asi tem- temas: magicos cosas mitologicas y cosas asi 28 | , 29 | 30 | , 31 | lo que mas me gusto de este libro es que ya cuando llegas al final te lo cambian todo y pasa algo que de veras no te esperaba y eso siempre me gusta el que hagan plot twist me encantan porque me traen cosas que yo no me esperaba y que le agregan mucho mas a la historia y te dan ganas de seguir leyendo los libro- 32 | , 33 | 34 | , 35 |
36 | , 37 |
38 | , 39 |
40 | , 41 | -------------------------------------------------------------------------------- /transcriptions3/103_books.csv: -------------------------------------------------------------------------------- 1 | "#starttime","#endtime" 2 | 0.000,1.478 3 | 1.478,5.234 4 | 5.234,7.567 5 | 7.567,11.761 6 | 11.761,15.415 7 | 15.415,21.180 8 | 21.180,26.772 9 | 26.772,30.325 10 | 30.325,35.131 11 | -------------------------------------------------------------------------------- /transcriptions3/cats.txt: -------------------------------------------------------------------------------- 1 | 100_makeup_1 negative 2 | , 3 | 100_makeup_2 negative 4 | , 5 | 100_makeup_3 negative 6 | , 7 | 100_makeup_4 negative 8 | , 9 | 100_makeup_5 positive 10 | , 11 | 100_makeup_6 positive 12 | , 13 | 100_makeup_7 positive 14 | , 15 | 100_makeup_8 positive 16 | , 17 | 100_makeup_9 negative 18 | , 19 | 101_movies_1 positive 20 | , 21 | 101_movies_2 positive 22 | , 23 | 101_movies_3 positive 24 | , 25 | 101_movies_4 positive 26 | , 27 | 101_movies_5 positive 28 | , 29 | 102_books_1 positive 30 | , 31 | 102_books_2 positive 32 | , 33 | 102_books_3 positive 34 | , 35 | 102_books_4 positive 36 | , 37 | 102_books_5 positive 38 | , 39 | 103_books_1 positive 40 | , 41 | 103_books_2 positive 42 | , 43 | 103_books_3 negative 44 | , 45 | 103_books_4 positive 46 | , 47 | 103_books_5 negative 48 | , 49 | 103_books_6 positive 50 | , 51 | 103_books_7 positive 52 | , 53 | 103_books_8 positive 54 | , 55 | 103_books_9 positive 56 | , 57 | 104_makeup_1 positive 58 | , 59 | 104_makeup_2 negative 60 | , 61 | 104_makeup_3 negative 62 | , 63 | 104_makeup_4 negative 64 | , 65 | 104_makeup_5 negative 66 | , 67 | 104_makeup_6 negative 68 | , 69 | 105_makeup_1 negative 70 | , 71 | 105_makeup_2 positive 72 | , 73 | 105_makeup_3 negative 74 | , 75 | 105_makeup_4 negative 76 | , 77 | 105_makeup_5 negative 78 | , 79 | 105_makeup_6 negative 80 | , 81 | 105_makeup_7 negative 82 | , 83 | 105_makeup_8 negative 84 | , 85 | 105_makeup_9 positive 86 | , 87 | 107_makeup_1 negative 88 | , 89 | 107_makeup_2 positive 90 | , 91 | 107_makeup_3 negative 92 | , 93 | 107_makeup_4 negative 94 | , 95 | 107_makeup_5 negative 96 | , 97 | 107_makeup_6 negative 98 | , 99 | 107_makeup_7 negative 100 | , 101 | 107_makeup_8 negative 102 | , 103 | 107_makeup_9 negative 104 | , 105 | 108_makeup_1 negative 106 | , 107 | 108_makeup_2 negative 108 | , 109 | 108_makeup_3 negative 110 | , 111 | 108_makeup_4 negative 112 | , 113 | 108_makeup_5 negative 114 | , 115 | 108_makeup_6 negative 116 | , 117 | 109_books_1 positive 118 | , 119 | 109_books_2 positive 120 | , 121 | 109_books_3 positive 122 | , 123 | 109_books_4 neutral 124 | , 125 | 109_books_5 neutral 126 | , 127 | 109_books_6 neutral 128 | , 129 | 110_perfume_1 positive 130 | , 131 | 110_perfume_2 positive 132 | , 133 | 110_perfume_3 positive 134 | , 135 | 110_perfume_4 positive 136 | , 137 | 110_perfume_5 positive 138 | , 139 | 110_perfume_6 positive 140 | , 141 | 111_makeup_1 neutral 142 | , 143 | 111_makeup_2 negative 144 | , 145 | 111_makeup_3 negative 146 | , 147 | 111_makeup_4 negative 148 | , 149 | 111_makeup_5 negative 150 | , 151 | 111_makeup_6 negative 152 | , 153 | 112_makeup_1 negative 154 | , 155 | 112_makeup_2 negative 156 | , 157 | 112_makeup_3 negative 158 | , 159 | 112_makeup_4 positive 160 | , 161 | 112_makeup_5 negative 162 | , 163 | 112_makeup_6 negative 164 | , 165 | 112_makeup_7 negative 166 | , 167 | 113_makeup_1 negative 168 | , 169 | 113_makeup_2 negative 170 | , 171 | 113_makeup_3 negative 172 | , 173 | 113_makeup_4 negative 174 | , 175 | 113_makeup_5 positive 176 | , 177 | 113_makeup_6 positive 178 | , 179 | 113_makeup_7 negative 180 | , 181 | 114_perfume_1 positive 182 | , 183 | 114_perfume_2 positive 184 | , 185 | 114_perfume_3 positive 186 | , 187 | 114_perfume_4 positive 188 | , 189 | 114_perfume_5 neutral 190 | , 191 | 115_makeup_1 negative 192 | , 193 | 115_makeup_2 negative 194 | , 195 | 115_makeup_3 negative 196 | , 197 | 115_makeup_4 negative 198 | , 199 | 115_makeup_5 negative 200 | , 201 | 116_makeup_1 negative 202 | , 203 | 116_makeup_2 negative 204 | , 205 | 116_makeup_3 negative 206 | , 207 | 116_makeup_4 negative 208 | , 209 | 116_makeup_5 negative 210 | , 211 | 117_perfume_1 positive 212 | , 213 | 117_perfume_2 positive 214 | , 215 | 117_perfume_3 positive 216 | , 217 | 117_perfume_4 positive 218 | , 219 | 117_perfume_5 positive 220 | , 221 | 117_perfume_6 neutral 222 | , 223 | 119_makeup_1 negative 224 | , 225 | 119_makeup_2 negative 226 | , 227 | 119_makeup_3 negative 228 | , 229 | 119_makeup_4 negative 230 | , 231 | 119_makeup_5 negative 232 | , 233 | 119_makeup_6 negative 234 | , 235 | 121_movies_1 negative 236 | , 237 | 121_movies_2 negative 238 | , 239 | 121_movies_3 positive 240 | , 241 | 121_movies_4 positive 242 | , 243 | 121_movies_5 neutral 244 | , 245 | 122_movies_1 positive 246 | , 247 | 122_movies_2 positive 248 | , 249 | 122_movies_3 positive 250 | , 251 | 122_movies_4 positive 252 | , 253 | 122_movies_5 positive 254 | , 255 | 126_movies_1 negative 256 | , 257 | 126_movies_2 negative 258 | , 259 | 126_movies_3 negative 260 | , 261 | 126_movies_4 negative 262 | , 263 | 126_movies_5 negative 264 | , 265 | 126_movies_6 negative 266 | , 267 | 127_movies_1 positive 268 | , 269 | 127_movies_2 positive 270 | , 271 | 127_movies_3 positive 272 | , 273 | 127_movies_4 positive 274 | , 275 | 127_movies_5 positive 276 | , 277 | 128_movies_1 negative 278 | , 279 | 128_movies_2 negative 280 | , 281 | 128_movies_3 positive 282 | , 283 | 128_movies_4 negative 284 | , 285 | 128_movies_5 negative 286 | , 287 | 128_movies_6 negative 288 | , 289 | 129_movies_1 positive 290 | , 291 | 129_movies_2 positive 292 | , 293 | 129_movies_3 positive 294 | , 295 | 129_movies_4 negative 296 | , 297 | 129_movies_5 positive 298 | , 299 | 129_movies_6 negative 300 | , 301 | 129_movies_7 neutral 302 | , 303 | 130_makeup_1 negative 304 | , 305 | 130_makeup_2 positive 306 | , 307 | 130_makeup_3 negative 308 | , 309 | 130_makeup_4 negative 310 | , 311 | 130_makeup_5 positive 312 | , 313 | 130_makeup_6 negative 314 | , 315 | 131_makeup_1 negative 316 | , 317 | 131_makeup_2 neutral 318 | , 319 | 131_makeup_3 negative 320 | , 321 | 131_makeup_4 positive 322 | , 323 | 131_makeup_5 negative 324 | , 325 | 131_makeup_6 positive 326 | , 327 | 132_makeup_1 negative 328 | , 329 | 132_makeup_2 negative 330 | , 331 | 132_makeup_3 positive 332 | , 333 | 132_makeup_4 negative 334 | , 335 | 132_makeup_5 negative 336 | , 337 | 132_makeup_6 negative 338 | , 339 | 132_makeup_7 negative 340 | , 341 | 132_makeup_8 negative 342 | , 343 | 132_makeup_9 negative 344 | , 345 | 133_books_1 negative 346 | , 347 | 133_books_2 negative 348 | , 349 | 133_books_3 negative 350 | , 351 | 133_books_4 negative 352 | , 353 | 133_books_5 negative 354 | , 355 | 134_makeup_1 positive 356 | , 357 | 134_makeup_2 positive 358 | , 359 | 134_makeup_3 positive 360 | , 361 | 134_makeup_4 positive 362 | , 363 | 137_books_1 positive 364 | , 365 | 137_books_2 positive 366 | , 367 | 137_books_3 positive 368 | , 369 | 137_books_4 positive 370 | , 371 | 137_books_5 positive 372 | , 373 | 137_books_6 positive 374 | , 375 | 138_books_1 positive 376 | , 377 | 138_books_2 positive 378 | , 379 | 138_books_3 positive 380 | , 381 | 138_books_4 positive 382 | , 383 | 138_books_5 positive 384 | , 385 | 138_books_6 positive 386 | , 387 | 138_books_7 positive 388 | , 389 | 138_books_8 positive 390 | , 391 | 139_books_1 positive 392 | , 393 | 139_books_2 positive 394 | , 395 | 139_books_3 positive 396 | , 397 | 139_books_4 positive 398 | , 399 | 139_books_5 positive 400 | , 401 | 139_books_6 negative 402 | , 403 | 139_books_7 neutral 404 | , 405 | 139_books_8 positive 406 | , 407 | 140_books_1 positive 408 | , 409 | 140_books_2 neutral 410 | , 411 | 140_books_3 neutral 412 | , 413 | 140_books_4 positive 414 | , 415 | 140_books_5 positive 416 | , 417 | 140_books_6 neutral 418 | , 419 | 141_books_1 positive 420 | , 421 | 141_books_2 positive 422 | , 423 | 141_books_3 negative 424 | , 425 | 141_books_4 positive 426 | , 427 | 141_books_5 positive 428 | , 429 | 143_makeup_1 negative 430 | , 431 | 143_makeup_2 negative 432 | , 433 | 143_makeup_3 negative 434 | , 435 | 143_makeup_4 negative 436 | , 437 | 143_makeup_5 negative 438 | , 439 | 143_makeup_6 negative 440 | , 441 | 143_makeup_7 negative 442 | , 443 | 143_makeup_8 negative 444 | , 445 | 143_makeup_9 negative 446 | , 447 | 143_makeup_10 neutral 448 | , 449 | 144_makeup_1 neutral 450 | , 451 | 144_makeup_2 negative 452 | , 453 | 144_makeup_3 negative 454 | , 455 | 144_makeup_4 positive 456 | , 457 | 144_makeup_5 negative 458 | , 459 | 144_makeup_6 neutral 460 | , 461 | 144_makeup_7 negative 462 | , 463 | 144_makeup_8 positive 464 | , 465 | 144_makeup_9 neutral 466 | , 467 | 145_makeup_1 negative 468 | , 469 | 145_makeup_2 negative 470 | , 471 | 145_makeup_3 negative 472 | , 473 | 145_makeup_4 negative 474 | , 475 | 145_makeup_5 neutral 476 | , 477 | 145_makeup_6 positive 478 | , 479 | 145_makeup_7 negative 480 | , 481 | 145_makeup_8 neutral 482 | , 483 | 145_makeup_9 neutral 484 | , 485 | 145_makeup_10 neutral 486 | , 487 | 146_makeup_1 negative 488 | , 489 | 146_makeup_2 negative 490 | , 491 | 146_makeup_3 negative 492 | , 493 | 146_makeup_4 negative 494 | , 495 | 146_makeup_5 positive 496 | , 497 | 146_makeup_6 negative 498 | , 499 | 147_makeup_1 neutral 500 | , 501 | 147_makeup_2 positive 502 | , 503 | 147_makeup_3 positive 504 | , 505 | 147_makeup_4 negative 506 | , 507 | 147_makeup_5 negative 508 | , 509 | 149_perfume_1 negative 510 | , 511 | 149_perfume_2 negative 512 | , 513 | 149_perfume_3 negative 514 | , 515 | 149_perfume_4 negative 516 | , 517 | 149_perfume_5 negative 518 | , 519 | 149_perfume_6 positive 520 | , 521 | 149_perfume_7 positive 522 | , 523 | 149_perfume_8 neutral 524 | , 525 | 149_perfume_9 positive 526 | , 527 | 150_makeup_1 negative 528 | , 529 | 150_makeup_2 negative 530 | , 531 | 150_makeup_3 negative 532 | , 533 | 150_makeup_4 negative 534 | , 535 | 150_makeup_5 negative 536 | , 537 | 150_makeup_6 positive 538 | , 539 | 151_makeup_1 positive 540 | , 541 | 151_makeup_2 negative 542 | , 543 | 151_makeup_3 positive 544 | , 545 | 151_makeup_4 positive 546 | , 547 | 151_makeup_5 positive 548 | , 549 | 151_makeup_6 positive 550 | , 551 | 153_books_1 neutral 552 | , 553 | 153_books_2 positive 554 | , 555 | 153_books_3 negative 556 | , 557 | 153_books_4 positive 558 | , 559 | 153_books_5 positive 560 | , 561 | 153_books_6 neutral 562 | , 563 | 153_books_7 positive 564 | , 565 | 157_books_1 positive 566 | , 567 | 157_books_2 positive 568 | , 569 | 157_books_3 positive 570 | , 571 | 157_books_4 neutral 572 | , 573 | 157_books_5 positive 574 | , 575 | 157_books_6 positive 576 | , 577 | 158_books_1 neutral 578 | , 579 | 158_books_2 positive 580 | , 581 | 158_books_3 positive 582 | , 583 | 158_books_4 positive 584 | , 585 | 158_books_5 neutral 586 | , 587 | 159_books_1 neutral 588 | , 589 | 159_books_2 positive 590 | , 591 | 159_books_3 positive 592 | , 593 | 159_books_4 negative 594 | , 595 | 159_books_5 positive 596 | , 597 | 159_books_6 neutral 598 | , 599 | 160_movies_1 negative 600 | , 601 | 160_movies_2 negative 602 | , 603 | 160_movies_3 negative 604 | , 605 | 160_movies_4 negative 606 | , 607 | 160_movies_5 negative 608 | , 609 | 161_book_1 positive 610 | , 611 | 161_book_2 positive 612 | , 613 | 161_book_3 neutral 614 | , 615 | 161_book_4 positive 616 | , 617 | 161_book_5 positive 618 | , 619 | 161_book_6 positive 620 | , 621 | 161_book_7 neutral 622 | , 623 | 161_book_8 positive 624 | , 625 | 162_books_1 negative 626 | , 627 | 162_books_2 negative 628 | , 629 | 162_books_3 negative 630 | , 631 | 162_books_4 positive 632 | , 633 | 162_books_5 negative 634 | , 635 | 162_books_6 negative 636 | , 637 | 162_books_7 negative 638 | , 639 | 163_books_1 positive 640 | , 641 | 163_books_2 neutral 642 | , 643 | 163_books_3 neutral 644 | , 645 | 163_books_4 positive 646 | , 647 | 163_books_5 positive 648 | , 649 | 163_books_6 positive 650 | , 651 | 164_books_1 positive 652 | , 653 | 164_books_2 neutral 654 | , 655 | 164_books_3 positive 656 | , 657 | 164_books_4 neutral 658 | , 659 | 164_books_5 positive 660 | , 661 | 165_makeup_1 positive 662 | , 663 | 165_makeup_2 positive 664 | , 665 | 165_makeup_3 positive 666 | , 667 | 165_makeup_4 positive 668 | , 669 | 166_movies_1 positive 670 | , 671 | 166_movies_2 positive 672 | , 673 | 166_movies_3 positive 674 | , 675 | 166_movies_4 positive 676 | , 677 | 166_movies_5 positive 678 | , 679 | 168_makeup_1 negative 680 | , 681 | 168_makeup_2 negative 682 | , 683 | 168_makeup_3 negative 684 | , 685 | 168_makeup_4 negative 686 | , 687 | 168_makeup_5 negative 688 | , 689 | 168_makeup_6 neutral 690 | , 691 | 170_makeup_1 neutral 692 | , 693 | 170_makeup_2 neutral 694 | , 695 | 170_makeup_3 neutral 696 | , 697 | 170_makeup_4 positive 698 | , 699 | 170_makeup_5 neutral 700 | , 701 | 170_makeup_6 negative 702 | , 703 | 170_makeup_7 neutral 704 | , 705 | 171_makeup_1 negative 706 | , 707 | 171_makeup_2 negative 708 | , 709 | 171_makeup_3 negative 710 | , 711 | 171_makeup_4 negative 712 | , 713 | 173_makeup_1 negative 714 | , 715 | 173_makeup_2 negative 716 | , 717 | 173_makeup_3 negative 718 | , 719 | 173_makeup_4 negative 720 | , 721 | 173_makeup_5 negative 722 | , 723 | 174_makeup_1 negative 724 | , 725 | 174_makeup_2 negative 726 | , 727 | 174_makeup_3 negative 728 | , 729 | 174_makeup_4 negative 730 | , 731 | 174_makeup_5 negative 732 | , 733 | 174_makeup_6 negative 734 | , 735 | 175_makeup_1 negative 736 | , 737 | 175_makeup_2 negative 738 | , 739 | 175_makeup_3 negative 740 | , 741 | 175_makeup_4 negative 742 | , 743 | 175_makeup_5 negative 744 | , 745 | 177_makeup_1 negative 746 | , 747 | 177_makeup_2 positive 748 | , 749 | 177_makeup_3 negative 750 | , 751 | 177_makeup_4 negative 752 | , 753 | 177_makeup_5 negative 754 | , 755 | 177_makeup_6 negative 756 | , 757 | 178_makeup_1 negative 758 | , 759 | 178_makeup_2 negative 760 | , 761 | 178_makeup_3 negative 762 | , 763 | 178_makeup_4 negative 764 | , 765 | 178_makeup_5 positive 766 | , 767 | 179_makeup_1 negative 768 | , 769 | 179_makeup_2 positive 770 | , 771 | 179_makeup_3 negative 772 | , 773 | 179_makeup_4 negative 774 | , 775 | 179_makeup_5 negative 776 | , 777 | 179_makeup_6 positive 778 | , 779 | 179_makeup_7 neutral 780 | , 781 | 180_makeup_1 negative 782 | , 783 | 180_makeup_2 negative 784 | , 785 | 180_makeup_3 negative 786 | , 787 | 180_makeup_4 negative 788 | , 789 | 180_makeup_5 positive 790 | , 791 | 180_makeup_6 negative 792 | , 793 | 180_makeup_7 negative 794 | , 795 | 181_makeup_1 neutral 796 | , 797 | 181_makeup_2 negative 798 | , 799 | 181_makeup_3 negative 800 | , 801 | 181_makeup_4 negative 802 | , 803 | 181_makeup_5 negative 804 | , 805 | 181_makeup_6 negative 806 | , 807 | 181_makeup_7 negative 808 | , 809 | 181_makeup_8 negative 810 | , 811 | 183_books_1 positive 812 | , 813 | 183_books_2 positive 814 | , 815 | 183_books_3 positive 816 | , 817 | 183_books_4 positive 818 | , 819 | 183_books_5 positive 820 | , 821 | 183_books_6 positive 822 | , 823 | 183_books_7 positive 824 | , 825 | 183_books_8 positive 826 | , 827 | 184_makeup_1 negative 828 | , 829 | 184_makeup_2 negative 830 | , 831 | 184_makeup_3 negative 832 | , 833 | 184_makeup_4 negative 834 | , 835 | 184_makeup_5 negative 836 | , 837 | 184_makeup_6 negative 838 | , 839 | 184_makeup_7 negative 840 | , 841 | 184_makeup_8 negative 842 | , 843 | 184_makeup_9 negative 844 | , 845 | 186_makeup_1 negative 846 | , 847 | 186_makeup_2 negative 848 | , 849 | 186_makeup_3 negative 850 | , 851 | 186_makeup_4 negative 852 | , 853 | 186_makeup_5 positive 854 | , 855 | 186_makeup_6 negative 856 | , 857 | 187_books_1 neutral 858 | , 859 | 187_books_2 negative 860 | , 861 | 187_books_3 negative 862 | , 863 | 187_books_4 negative 864 | , 865 | 187_books_5 negative 866 | , 867 | 187_books_6 negative 868 | , 869 | 187_books_7 negative 870 | , 871 | 187_books_8 negative 872 | , 873 | 188_books_1 neutral 874 | , 875 | 188_books_2 negative 876 | , 877 | 188_books_3 negative 878 | , 879 | 188_books_4 negative 880 | , 881 | 188_books_5 negative 882 | , 883 | 189_movies_1 negative 884 | , 885 | 189_movies_2 negative 886 | , 887 | 189_movies_3 negative 888 | , 889 | 189_movies_4 negative 890 | , 891 | 189_movies_5 negative 892 | , 893 | 190_movies_1 negative 894 | , 895 | 190_movies_2 negative 896 | , 897 | 190_movies_3 positive 898 | , 899 | 190_movies_4 positive 900 | , 901 | 190_movies_5 negative 902 | , 903 | 191_makeup_1 neutral 904 | , 905 | 191_makeup_2 positive 906 | , 907 | 191_makeup_3 positive 908 | , 909 | 191_makeup_4 positive 910 | , 911 | 191_makeup_5 negative 912 | , 913 | 191_makeup_6 positive 914 | , 915 | 191_makeup_7 positive 916 | , 917 | 193_books_1 negative 918 | , 919 | 193_books_2 negative 920 | , 921 | 193_books_3 positive 922 | , 923 | 193_books_4 negative 924 | , 925 | 193_books_5 negative 926 | , 927 | 193_books_6 negative 928 | , 929 | 193_books_7 negative 930 | , 931 | 194_books_1 positive 932 | , 933 | 194_books_2 negative 934 | , 935 | 194_books_3 positive 936 | , 937 | 194_books_4 positive 938 | , 939 | 194_books_5 positive 940 | , 941 | 196_books_1 positive 942 | , 943 | 196_books_2 positive 944 | , 945 | 196_books_3 positive 946 | , 947 | 197_books_1 positive 948 | , 949 | 197_books_2 positive 950 | , 951 | 197_books_3 positive 952 | , 953 | 197_books_4 positive 954 | , 955 | 197_books_5 negative 956 | , 957 | 197_books_6 positive 958 | , 959 | 198_books_1 positive 960 | , 961 | 198_books_2 positive 962 | , 963 | 198_books_3 positive 964 | , 965 | 198_books_4 positive 966 | , 967 | 198_books_5 positive 968 | , 969 | 198_books_6 positive 970 | , 971 | 198_books_7 positive 972 | , 973 | 198_books_8 positive 974 | , 975 | 198_books_9 neutral 976 | , 977 | 199_books_1 positive 978 | , 979 | 199_books_2 positive 980 | , 981 | 199_books_3 negative 982 | , 983 | 199_books_4 negative 984 | , 985 | 200_books_1 positive 986 | , 987 | 200_books_2 positive 988 | , 989 | 200_books_3 positive 990 | , 991 | 200_books_4 negative 992 | , 993 | 200_books_5 positive 994 | , 995 | 200_books_6 positive, 996 | -------------------------------------------------------------------------------- /videos.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SenticNet/multimodal-sentiment-detection/188457f080a61f707018b200aa6755b1d4e7c19b/videos.zip --------------------------------------------------------------------------------