[ Yii ] 101

Check Yii requirement

http://localhost/yii/requirements/

Generate web name yii_tutorial

yiic webapp D:\xampp\htdocs\yii_tutorial\

 

/assets

/css

/images

/protected/controllers

/protected/models

/protected/views/sites/index.php

/protected/views/layouts/main.php

/protected/extensions ( external extension )

/protected/modules

/protected/components

/protected/config/database.php

/protected/messages ( for i18n )

/protected/runtime ( logs )

/themes

.htaccess

index.php

index-test.php

 

ref : https://drivesoftcenter.net/tutorial/yii/basic/?page=3

Advertisements

CNN / RNN / Universal Sentence Encoding / tensorflow.org/hub

=== CNN Convolutional Neural Network ===
detect object : small part -> line -> box -> bigger part

filter : small metric ( i.e. detect curve )

 

picture x filter ( convolution ); 1 -> max, 0 -> 0

sliding filter window
output: ( if match filter, value is high; if not, value is low )
4 3 4
2 4 3
2 3 4

picture -> filters -> filters -> filters -> classification ( fully connected layer )
detect line detect cross

* AlexNet (2012) :
5 convolution layer, 3 fully connected layer
11×11

* VGG (Oxford University):
smaller filters
deeper ( non-linearity )
3×3

* GoogLeNet (+Inception module)
1×1 concat 3×3 concat 5×5

* ResNet
-> calc loss ( prediction v.s. real ) -> calc gradient -> backpropagation ไปด้านบน
gradient < 0 -> * -> gradient หายไป
สร้างเส้นทางลัดเพื่อให้ gradient backpropagate ไป layer แรกได้
ทำได้ 152 layers

input signal + weight

* DenseNet
เชื่อมทุก layer เพื่อให้ gradient ไม่หายไป

input signal ต่อกับ weight

— Network Architecture Search (NAS) ML เป็นตัวสร้าง ML Architecture —
Reinforcement learning
Controller (ตัวสร้าง architecture) -> Train กับ Data แล้วดู Accuracy
ถ้า data ใหญ่นาน
|
<- feedback

** RNN ( Recurrent Neural Network ) ในการ predict
– filter size
– ควรเลื่อน filter แล้ว skip กี่ช่อง

** transfer learning
learn กับ data เล็กๆ ก่อน
* Normal Cell กล่อง : convolutional cell ที่ input/output มี dimension เท่ากัน
* Reduction Cell กล่อง : convolutional cell ที่ input ครึ่งหนึ่ง ของ output
|
V
imageNet

** NASNet
– ทำให้ search space เล็กลง

=== NLP ===
* RNN
การอ่านหนังสือ ขึ้นกับ state ก่อนหน้า

output output output
^ ^ ^
layer -> layer -> layer
^ ^ ^
input input input

Seq2Seq : Seq or Word in Eng -Encoder-> Seq or Word in Japanese
I -> like -> -> -> Suki

ปัญหา : long term dependency ถ้า state เยอะมากๆ

* CNN with NLP
need many layers

* Attention Machanism
RNN
แต่ละ กล่อง -> w * Find attention word -> context vector

state จะไม่หายไป

query : economic
key : .. , .. , .. , ..
value : matched key ( attention value )

query x key -> distance
value = softmax(query x key)

Multi-head attention
เพิ่ม space key-value

Transformer
Encoder: Encoder self Attention / feed forward ดูว่าคำของตัวเอง Attent กับตัวเอง
Decoder: Decoder self Attention / feed forward ดูว่าคำของตัวเอง Attent กับตัวเอง
Encoder-Decoder Attention

* Position Encoding
sin() / position i ( dimension )
sin() / position i ( dimension )
sin() / position i ( dimension )

position i -encode-> sin

* Universal Sentence Encoding — in tensor flow
sentence -encoder-> vector

– Transformer train with many task
– Deep Averaging network

=== TensorFlow hub (tensorflow.org/hub) ===
Repositories : shared code/model

module : pretrained model/graph
Image module :

Text Module
* NASNet-A mobile, large
* en,jp,de,es
* Word2Vec ( wikipedia )
* ELMo

module = hub.Module(‘https://thub.dev/google/imagenet/nasnet_large/feature_vector/1&#8217;)
trainable=True, tags=(‘train’) ## train

= tf layers dense() ## use model

=== Recommendation System from classification method to deep learning ===
* content base ( เคยจองโรงแรมสามดาว recommend 3 ดาว )
* collaborative filtering ( bob like A,B,C; Alice like A,B,D; Bob may like D, Alice may like C )
** Explicit feedback ( review score ) — ถ้า review น้อยคือไม่ชอบ
** Implicit feedback ( click/booking ) ** — ไม่มี negative feedback

* Collaborative filtering
John review Marriott 7.8 -> Matrix UserxItem
Lebua

Try to fill gap in the Matrix

Marriott Lebua
John 3 7.8
Jane 2.5

Weight John + Weight Aron ด้วย similarity score

Matrix Factorization

mxd x dxn = mxn

 

P
rating Score > 0 W

Drawbacks
* combine many implicit datasource
* recent actions should be more weight
* context information : i.e. trip1 : children = 1, trip2 : no children
* increment learning

** sequence prediction
sequencial manner
booking D -> click C -> booking A -> click B -> booking B

booking D -> click C -> booking A
predict
booking D -> click C -> booking A -> click B -> booking B
predict
embed embed embed +embed

RNN Layer ( initialization = Context vector ) (or concat + Context Vector to RNN Layer)
V
ReLU
V
user feature

Sparse matrix : a lot of hotels
Embedding ( string -> vector ใน dimension ที่กำหนด )

RNN ( recurrent neural network ) : model sequences information

User actions -> Feature Vector -> predict -> label hotel id

Context in recommendation
* user location/search criteria(length of stay/with children?)/time/intention

Reading
– Collaborative Filtering for Impact Feedback Datasets
– BPR Baysian personalization from implicit feedback
– YouTube :
– YouTube :

https://www.skooldio.com/courses/gde-tensorflow-01

 

prophet : facebook forecasting revenue + extra factor

  • capacity of the country
  • change points : i.e. add 2x ads ( speacial event )
  • seasonality / holidays

 

====

ROC Curve : receiver operting Characteristic

prototyping : Wizard of Oz

[ naive_bayes ] GaussianNB and pickle

from sklearn.naive_bayes import GaussianNB

import numpy as np

# example X [count of some words in sentence, count of other words in sentence]
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])

clf = GaussianNB()
clf.fit(X, Y) # GaussianNB(priors=None)

# keep in pickle
MODEL_FILE = Path(__file__).parent / 'model.pkl'
with MODEL_FILE.open('wb') as fp: pickle.dump(model, fp)
# restore from pickle

with MODEL_FILE.open('rb') as fp:
clf = pickle.load(fp)
#
print(clf.predict([[-0.8, -1]])) # [1]

clf_pf = GaussianNB()
clf_pf.partial_fit(X, Y, np.unique(Y)) # GaussianNB(priors=None)
print(clf_pf.predict([[-0.8, -1]])) # [1]

ref : http://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.GaussianNB.html,

https://machinelearningmastery.com/save-load-machine-learning-models-python-scikit-learn/