Tuesday, March 23, 2021

Colab(九。一):TensorFlow - LeNet

 Colab(九。一):TensorFlow - LeNet

2021/03/23

-----

說明:

這是 Kaggle 提供的 LeNet 範例,最後會輸出提交的結果。

-----


https://pixabay.com/zh/photos/poles-water-rotten-old-motion-1030747/

-----

步驟:


一、將 [1] 的內容移入 Colab。


二、加入以下指令

from google.colab import drive

drive.mount('/content/drive/')

# 點入系統提供的連結之後,登入自己的帳戶,會得到一組授權碼,將授權碼輸入後,即可存取自己的 Google Drive。

!ls '/content/drive/My Drive/'


三、修改輸入與輸出檔案的路徑為:

train = pd.read_csv('/content/drive/My Drive/train.csv')

test = pd.read_csv('/content/drive/My Drive/test.csv')

test.to_csv('/content/drive/My Drive/submit.csv', columns = ["Label"])


四、將原來匯入的 tensorflow 

import tensorflow as tf

改為匯入之前的精簡版本 [2], [3]:

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior() 


五、以上都修改後即可正常執行(執行時會出現警告訊息)。


六、檢查 Google Drive 根目錄是否有 submit.csv 檔。


七、可嘗試 TensorFlow 其他的 LeNet 版本 [4]。

-----

References


[1] LeNet-5 Architecture for MNIST using Tensorflow | Kaggle

https://www.kaggle.com/niranjanjagannath/lenet-5-architecture-for-mnist-using-tensorflow


[2] AttributeError: module 'tensorflow' has no attribute 'placeholder' · Issue #14 · theislab/scgen · GitHub

https://github.com/theislab/scgen/issues/14


[3] python - TensorFlow, "'module' object has no attribute 'placeholder'" - Stack Overflow

https://stackoverflow.com/questions/37383812/tensorflow-module-object-has-no-attribute-placeholder


[4] advanced.ipynb - Colaboratory

https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/quickstart/advanced.ipynb#scrollTo=DUNzJc4jTj6G


-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(九):TensorFlow

 Colab(九):TensorFlow

2021/03/23

-----


https://pixabay.com/zh/photos/waterfall-cliff-stream-river-water-962798/

-----

References


TensorFlow - 維基百科,自由的百科全書

https://zh.wikipedia.org/wiki/TensorFlow


TensorFlow Core

https://www.tensorflow.org/tutorials?hl=zh-tw


-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Monday, March 22, 2021

Colab(一一。一):GitHub - Python - LeNet

 Colab(一一。一):GitHub - Python - LeNet

2021/03/09

-----

施工中。。。

-----

目標:可以使用 Colab 執行一個 LeNet - Python 的 GitHub 專案。

目標完成日。

-----


https://pixabay.com/zh/photos/way-communication-travel-2826934/

-----

References


# Colab中運行.py文件

// Colab初探 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天

https://ithelp.ithome.com.tw/articles/10227517


// 2.多个py文件的使用技巧

// Google Colaboratory中有多个py文件时的使用技巧_daniellibin的博客-CSDN博客

https://blog.csdn.net/daniellibin/article/details/102766088


// Running Python code in Colab · AI_GC_Methodology_2018_v1(private)

https://mmchiou.gitbooks.io/ai_gc_methodology_2018_v1-private/content/colab/running-python-code-in-colab.html


// 使用谷歌Colab Notebooks,這6個小技巧你需要掌握 - 知乎_osc_izh4pvr9 - MdEditor

https://www.mdeditor.tw/pl/gvuJ/zh-tw


The Star Also Rises: LeNet Lab(目錄)

https://hemingwang.blogspot.com/2019/04/lenet-lab.html


-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(一一):GitHub

Colab(一一):GitHub

2020/12/27

-----


https://pixabay.com/zh/photos/code-javascript-html-programmer-5290465/

-----


References



# wiki
GitHub - Wikipedia
https://en.wikipedia.org/wiki/GitHub 


# GitHub 
The world’s leading software development platform · GitHub
https://github.com/ 


# documentation
GitHub Guides
https://guides.github.com/


# 2.6K claps 
GIT Good  A Practical Introduction to GIT and GitHub (Hello GitHub)
https://codeburst.io/git-good-part-a-e0d826286a2a 


# 2.3K claps 
Getting started with Git and GitHub  the complete beginner’s guide
https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6


# 623 claps
A full tutorial on how to use GitHub - George Seif - Medium
https://medium.com/@george.seif94/a-full-tutorial-on-how-to-use-github-88466bac7d42 


# 348 claps 
What is Git  An overview of Git and why you should use it
https://levelup.gitconnected.com/what-is-git-how-to-use-it-why-to-use-it-explained-in-depth-76a5066abaaa


-----


# wiki
GitHub - 維基百科,自由的百科全書
https://zh.wikipedia.org/wiki/GitHub 


#
Git 與 Github 版本控制基本指令與操作入門教學 _ TechBridge 技術共筆部落格
https://blog.techbridge.cc/2018/01/17/learning-programming-and-coding-with-python-git-and-github-tutorial/


# 鐵人賽
Learn-Git-in-30-days_README.md at master · doggy8088_Learn-Git-in-30-days · GitHub
https://github.com/doggy8088/Learn-Git-in-30-days/blob/master/zh-tw/README.md 


# Gist
在Medium中使用 GitHub Gist 貼原始碼 - Hong Kong Open Source - Medium
https://medium.com/hong-kong-open-source/%E5%9C%A8medium%E4%B8%AD%E4%BD%BF%E7%94%A8-github-gist-%E8%B2%BC%E5%8E%9F%E5%A7%8B%E7%A2%BC-f8de4493ddb


-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(八。一):Keras - LeNet

 Colab(八。一):LeNet - Keras

2021/03/09

-----

說明:

在 Colab 上,執行 LeNet 的 Keras 版本。

-----


https://pixabay.com/zh/photos/spider-webs-hoarfrost-frozen-cold-4675638/

-----

步驟:

共有六個步驟。


步驟一、啟動 Colab,打開一個新的筆記本 [1]。

步驟二、根據 [2] 的指示,到 Kaggle 下載(可用 Google 帳號登入)訓練集以及測試集的 zip 檔(train.csv 與 test.csv),解壓縮後,將 train.csv 與 test.csv 兩個 csv 檔放到 Google Drive 網路硬碟的根目錄。

步驟三、將 [2] 的 lenet_5.py 的內容搬到 Colab 的筆記本上。有三個地方需要修改。1. 要 mount Google Drive [3]。2. 要修改檔案路徑 [3]。3. 要修改 Pandas 的指令。


1. 新增下列指令

from google.colab import drive

drive.mount('/content/drive/')

# 點入系統提供的連結之後,登入自己的帳戶,會得到一組授權碼,將授權碼輸入後,即可存取自己的 Google Drive。

!ls '/content/drive/My Drive/' 


2. 原程式的 10 跟 11 行(列)

train = pd.read_csv('train.csv')

test = pd.read_csv('test.csv')

改為

train = pd.read_csv('/content/drive/My Drive/train.csv')

test = pd.read_csv('/content/drive/My Drive/test.csv')


3. 原程式的 19 行(列)

sample = sample.reshape([28,28])

改為

sample = sample.values.reshape([28,28])


步驟四、修改完畢後,執行(程式區左上角的三角形)即可看到 LeNet 訓練與執行的結果。

-----


# 實作結果。

-----

步驟五、Runtine、Change runtime type、Hardware accelerator、GPU。選擇 GPU 加速,再看一次結果。

-----

六、超參數調整


epochs = 42


act = 'relu'

act = 'sigmoid'

opt = 'adam'

opt = 'sgd'


1. relu + adam

2. relu + sgd

3. sigmoid + adam

4. sigmoid + sgd


四個組合在 epoch 10 與 epoch 42 的正確率。

1. 收斂極快,極高。0.96。0.99。

2. 收斂較快,較低。0.64。0.93。

3. 收斂較慢,較高。0.61。0.95。

4. 無法收斂。0.10。0.11。

-----

References

[1] 歡迎使用 Colaboratory - Colaboratory

https://colab.research.google.com/


[2] GitHub - TaavishThaman/LeNet-5-with-Keras: Implementation of LeNet-5 with keras

https://github.com/TaavishThaman/LeNet-5-with-Keras


[3] 玩具烏托邦: 貴哥的 colab 初學筆記

https://newtoypia.blogspot.com/2019/07/colab.html


[4] pandas.Series.reshape — pandas 0.19.0 documentation

https://pandas.pydata.org/pandas-docs/version/0.19.0/generated/pandas.Series.reshape.html


-----


# 使用 TPU 的 Keras LeNet

[5] Keras Fashion MNIST - Colaboratory

https://colab.research.google.com/github/tensorflow/tpu/blob/master/tools/colab/fashion_mnist.ipynb


LeNet-5 CNN with Keras - 99.48% | Kaggle

https://www.kaggle.com/curiousprogrammer/lenet-5-cnn-with-keras-99-48


-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(八。二):Keras - DQN

 Colab(八。二):Keras - DQN

2021/03/22

-----


https://pixabay.com/zh/photos/alphabetic-character-alphabet-letters-2538818/

-----

References


[1] Deep Q-Learning with Keras and Gym · Keon's Blog

https://keon.github.io/deep-q-learning/


[2] deep-q-learning/dqn.py at master · keon/deep-q-learning · GitHub

https://github.com/keon/deep-q-learning/blob/master/dqn.py


-----


# 可執行,但這是 Q-learning 非 DQN。只能參考。

[3] Lab 15. 在OpenAI上實作Q-Learning.ipynb 的副本 - Colaboratory

https://colab.research.google.com/drive/16XhWYnVH8ipSlYVaIRLLHZ2QjXjWGQz0#scrollTo=9riuZbu0FRoz


# DQN,可執行,但很慢,換 GPU 也無效。只能參考。

[4] Keras深度强化学习-- Policy Network与DQN实现 - 简书

https://www.jianshu.com/p/e037d42ab6b1


# DQN,可執行。但看起來不容易成功達到山頂。可將 SARS 變數列出就知道了。

[5] Reinforcement Learning w/ Keras + OpenAI: DQNs | by Yash Patel | Towards Data Science

https://towardsdatascience.com/reinforcement-learning-w-keras-openai-dqns-1eed3a5338c


-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(八):Keras

 Colab(八):Keras

2021/03/16

-----


https://pixabay.com/zh/photos/mammal-mouflon-sheep-nature-3024471/

-----

References


Keras: the Python deep learning API

https://keras.io/


主页 - Keras 中文文档

https://keras.io/zh/


keras实现常用深度学习模型LeNet,AlexNet,ZFNet,VGGNet,GoogleNet,Resnet_wmy199216的博客-CSDN博客

https://blog.csdn.net/wmy199216/article/details/71171401


GitHub - erhwenkuo/deep-learning-with-keras-notebooks: Jupyter notebooks for using & learning Keras

https://github.com/erhwenkuo/deep-learning-with-keras-notebooks

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(七。三):Pandas

 Colab(七。三):PandasPandas

2021/03/21

-----


https://pixabay.com/zh/photos/panda-panda-bear-sleep-rest-relax-1236875/

-----

References


pandas documentation — pandas 1.2.3 documentation

https://pandas.pydata.org/docs/index.html


pandas.DataFrame.iloc — pandas 1.2.3 documentation

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html


Reshaping and pivot tables — pandas 1.2.3 documentation

https://pandas.pydata.org/docs/user_guide/reshaping.html

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(七。二):matplotlib

 Colab(七。二):matplotlib

2021/03/22

-----


https://pixabay.com/zh/photos/spices-condiment-aroma-taste-spicy-667116/

-----

References


Matplotlib: Python plotting — Matplotlib 3.3.4 documentation

https://matplotlib.org/


Hello Matplotlib!. 認識Matplotlib的架構及基礎知識,並且了解如何利用數據來創建圖形並進而客… | by MAPE Academy | Python4U | Medium

https://medium.com/python4u/hello-matplotlib-8ffe04355ebf


用 Python 自學資料科學與機器學習入門實戰:Matplotlib 基礎入門

https://blog.techbridge.cc/2018/05/11/python-data-science-and-machine-learning-matplotlib-tutorial/

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Sunday, March 21, 2021

Colab(六):File

 Colab(六):File

2021/03/04

-----

施工中。。。最後剩下的 Tutorial 都放在這裡。

-----

目標:可以使用 Colab 存取雲端硬碟的檔案。

目標達成日:

-----


https://pixabay.com/zh/photos/microscope-research-lab-laboratory-385364/

-----

沒有特別針對 Google Drive 的檔案教材。

mount 之後,預設目錄為 Google Drive 的根目錄。

-----

References


[1] Google Colaboratory–適合Python初學者的雲端開發環境

http://www.cc.ntu.edu.tw/chinese/epaper/0052/20200320_5207.html


[2] 玩具烏托邦: 貴哥的 colab 初學筆記

https://newtoypia.blogspot.com/2019/07/colab.html


-----


[3] python 檔案讀寫. 檔案讀寫是很基本又很常用的功能,但由於我每次要用時都還是會估狗一下,因此還是寫下… | by CW Lin | Medium

https://peaceful0907.medium.com/python-%E6%AA%94%E6%A1%88%E8%AE%80%E5%AF%AB-ef0faf9dae1e


[4] Python常見的檔案處理應用

https://www.learncodewithmike.com/2020/02/python-files.html


[5] Python 第 13 章    檔案

http://yltang.net/tutorial/python/13/


[6] Python 好用模組 - pathlib | My.APOLLO

https://myapollo.com.tw/zh-tw/python-pathlib/


-----


Python 初學第十二講—檔案處理. 利用程式進行讀/寫檔案的處理 | by Yu-Hsuan Chou | ccClub | Medium

https://medium.com/ccclub/ccclub-python-for-beginners-tutorial-bf0648108581


[Python初學起步走-Day29] - 檔案讀寫 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天

https://ithelp.ithome.com.tw/articles/10161708


Python 讀取 txt 文字檔,一篇搞懂! | ShengYu Talk

https://shengyu7697.github.io/blog/2019/10/19/Python-read-text-file/

-----

補充:

7. Input and Output — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/inputoutput.html


8. Errors and Exceptions — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/errors.html


9. Classes — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/classes.html


10. Brief Tour of the Standard Library — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/stdlib.html


11. Brief Tour of the Standard Library — Part II — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/stdlib2.html


12. Virtual Environments and Packages — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/venv.html


13. What Now? — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/whatnow.html


14. Interactive Input Editing and History Substitution — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/interactive.html


15. Floating Point Arithmetic: Issues and Limitations — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/floatingpoint.html


16. Appendix — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/appendix.html

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(五):Module

 Colab(五):Module

2021/03/09

-----


https://pixabay.com/zh/photos/work-typing-computer-notebook-731198/

-----

◎ class and object

-----

先定義 class,再用 class 產生一個一個的 object。

-----

◎ function and method

-----

def 是 function。

class 裡面的 def 是 method。

-----

前幾篇文章,練習了邏輯、迴圈、資料結構。

一開始使用 Colab 的時候,不大習慣,因為那些範例都是片段的程式,而且沒有行號。後來找了一下資料,才知道行號的設定 [1]。但是後來也就習慣沒有行號的方式了。

不過一般 Python 的 package,為了結構化的呈現,會有好幾個 .py 的檔案,每個檔案再由 class 與 def 展開 [3]。

-----

◎ 實作:

-----

一、10 自訂函數 [2]。

二、Class [3]。

三、第 15 章    物件與類別 [4]。

四、Modules  [5]。

-----

誤:

class Animal():

 def __init__(self, name):

  self.name = name

 def who(self):

  return self.name

a = Animal(dog)

print a.who #-> dog

正:

class Animal():

 def __init__(self, name):

  self.name = name

 def who(self):

  return self.name

a = Animal("dog")

print(a.who()) 

-----

誤:

acct1 = Account(‘123–456–789’, ‘Justin’) #開一個帳戶

acct1.deposit(100)

acct1.withdraw(30)

print(acct1.balance) #餘額是 70

正:

acct1 = Account('123–456–789', 'Justin') #開一個帳戶

acct1.deposit(100)

acct1.withdraw(30)

print(acct1.balance) #餘額是 70

-----

References

[1] 如何在Google Colaboratory中显示行号? - Thinbug

https://www.thinbug.com/q/49182502


[2] 10 自訂函數

https://bookdown.org/tonykuoyj/hello-py/functions.html


[3] 關於Python的類別(Class)...基本篇. 我覺得Class是Python速成班最重要的一環… | by 張凱喬 | Medium

https://weilihmen.medium.com/%E9%97%9C%E6%96%BCpython%E7%9A%84%E9%A1%9E%E5%88%A5-class-%E5%9F%BA%E6%9C%AC%E7%AF%87-5468812c58f2


[4] 第 15 章    物件與類別

http://yltang.net/tutorial/python/15/

-----

補充:

[5] 6. Modules — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/modules.html

# 解析Python模組(Module)和套件(Package)的概念

https://www.learncodewithmike.com/2020/01/python-module-and-package.html

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(四):Data Structure

 Colab(四):Data Structure

2021/03/10

-----


https://pixabay.com/zh/photos/stones-wall-quarry-stone-texture-770264/

-----

一、為什麼要學資料結構。

-----

「演算法 + 資料結構 = 程式」[1] 是 Pascal 的發明人 Niklaus Wirth 的名言,以及名著 [2]。這句話可以進一步推廣,「基因演算法 + 資料結構 = 遺傳程式」 [3]。演算法影響解決問題的大方向,資料結構決定了實作這個程式的難易度 [4]。所以,不管你是不是要用 Python 學習演算法與資料結構,你既然決定了用 Python 寫程式,自然要知道 Python 上面有什麼資料結構可以使用 [5], [6]。

-----

二、Built-in Data Structures。

-----

Python 內建的四種資料結構是 list、tuple [7] 與 set、dict [8]。dict 可以多練習一下 [9]。


◎ List

可以用 help(list) 看看總共有有哪些 method。

List 有許多函式可以處理,比剛剛的實作 [7] 細緻一點 [10]。程式碼要稍微品味一下。List 可以用中括號建立(my_list = [] #create empty list)。內容可以是整數、實數、邏輯值,或字串(my_list = [1, 2, 3, 'example', 3.132] #creating list with data)。

建立資料後,可以再新增資料(使用 append()、extend()、insert())。append() 用於新增單一筆資料(my_list.append([555, 12]) #add as a single element)。extend() 用於新增多筆資料(my_list.append([555, 12]) #add as a single element)。insert() 用於在某個位置插入一筆資料(my_list.insert(1, 'insert_example') #add element i)。以上三個函式,都是附屬於 list 的 method,而非內建函式。

刪除資料可以用 del 這個保留字,也可以用 remove、pop、clear 這三個 list 內建的 method。


◎ Dictionary

dict 用大括號建立(my_dict = {'First':'Python','Second':'Java'})。一樣,可以用 help(dict) 看一下有哪些運算或動作可以使用。


◎ Tuple

tuple 使用小括號。tuple 跟 list 很像,但是 list 裡面的值可以修改,tuple 裡面的值不能修改。但是 tuple 的元素還是可以新增(my_tuple = my_tuple + (4, 5, 6) #add elements)。總之,如果元素不打算修改,可以使用 tuple,效能較佳。tuple  也可以是巢狀(多維的)。


◎ Sets

set 跟 dict 有點像,也是使用大括號建立。一樣都不能有重複的元素,也可以說重複的元素無效。其中一個重點是,dict 的元素是 key-value,用冒號連結 key 跟 value。set,既然是 set,自然可以進行 set 的運算,如交集、聯集、相減等等。運算可以用函式,或者用比較簡潔的符號。

-----

三、User-Defined Data Structures

-----


◎ Arrays vs. List

由於 array 不是 Python 內建的資料結構,而是使用者自訂。有兩個方法可以使用 array,用 import as 或者 from import。

第一種方法:

import array as arr

第二種方法:

from array import *

使用第二種方法之後,就可以用 help(array) 檢查有哪些 method 可以使用了。array 跟 list 最大的差別,是 array 裡面的元素,型別都相同。


◎ Stack

◎ Queue

Stack 堆疊是 FILO 先進後出。Queue 列隊是 FIFO 先進先出。Stack 跟 Queue(>>> from collections import deque)可以使用 list 實現 [11]。


◎ Trees

◎ Linked Lists

◎ Graphs

◎ HashMaps

其他資料結構請自行參考 [10]。

-----

◎ 實作練習

-----

一、6 資料容器一 [7]。

二、8 資料容器二 [8]。

三、字典. Dictionary,另一個存資料的好方法 [9]。

四、Data Structures in Python | List, Tuple, Dict, Sets, Stack, Queue | Edureka [10]。

五、Data Structures — Python 3.9.2 documentation [11]。

-----

誤:

starrings = {

    "Rachel Green": "Jennifer Aniston",

    "Monica Geller": "Courteney Cox",

    "Phoebe Buffay": "Lisa Kudrow",

    "Joey Tribbiani": "Matt LeBlanc",

    "Chandler Bing": "Matthew Perry",

    "Ross Geller": "David Schwimmer"

}

for starring in starrings:

    print starring

正:

starrings = {

    "Rachel Green": "Jennifer Aniston",

    "Monica Geller": "Courteney Cox",

    "Phoebe Buffay": "Lisa Kudrow",

    "Joey Tribbiani": "Matt LeBlanc",

    "Chandler Bing": "Matthew Perry",

    "Ross Geller": "David Schwimmer"

}

for starring in starrings:

    print(starring)

-----

誤:

starrings = {

    "Rachel Green": "Jennifer Aniston",

    "Monica Geller": "Courteney Cox",

    "Phoebe Buffay": "Lisa Kudrow",

    "Joey Tribbiani": "Matt LeBlanc",

    "Chandler Bing": "Matthew Perry",

    "Ross Geller": "David Schwimmer"

}

for starring in starrings.keys():

    print starring

正:

starrings = {

    "Rachel Green": "Jennifer Aniston",

    "Monica Geller": "Courteney Cox",

    "Phoebe Buffay": "Lisa Kudrow",

    "Joey Tribbiani": "Matt LeBlanc",

    "Chandler Bing": "Matthew Perry",

    "Ross Geller": "David Schwimmer"

}

for starring in starrings.keys():

    print(starring)

-----

誤:

for starring in starrings.values():

    print starring

正:

for starring in starrings.values():

    print(starring)

-----

誤:

my_squares = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

for i in my_squares:

print(“Key is”, i, “Value is”, my_squares[i])

正:

my_squares = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

for i in my_squares:

    print("Key is", i, "Value is", my_squares[i])

-----

References

[1] Algorithms & data structures

Wirth, Niklaus. Algorithms & data structures. Prentice-Hall, Inc., 1985.


[2] TWIDEEM CIVS

https://twideem.github.io/pages/overcast/20140306A.html


[3] Genetic algorithms + data structures= evolution programs

Michalewicz, Zbigniew. Genetic algorithms + data structures= evolution programs. Springer Science & Business Media, 2013.


[4] 演算法+資料結構=程式 | iThome

https://www.ithome.com.tw/voice/142263


[5] 技術雜談:為什麼要 (或不要) 用 Python 實作資料結構和演算法 | Michael Chen 的技術文件

https://michaelchen.tech/blog/why-or-why-not-using-python-for-algorithms/


[6] 輕鬆學習 Python:資料結構. 利用資料結構儲存多筆資料 | by Yao-Jen Kuo | 數據交點 | Medium

https://medium.com/datainpoint/python-essentials-data-structures-4ba25f2deaf5

-----

[7] 6 資料容器一

https://bookdown.org/tonykuoyj/hello-py/containers-1.html


[8] 8 資料容器二

https://bookdown.org/tonykuoyj/hello-py/containers-2.html


[9] Python 初學第九講 — 字典. Dictionary,另一個存資料的好方法 | by 陳子晴 | ccClub | Medium

https://medium.com/ccclub/ccclub-python-for-beginners-tutorial-533b8d8d96f3


[10] Data Structures in Python | List, Tuple, Dict, Sets, Stack, Queue | Edureka

https://www.edureka.co/blog/data-structures-in-python/

-----

補充:

[11] 5. Data Structures — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/datastructures.html

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(三):Python

 Colab(三):Python

2021/03/09

前言:

本文簡單介紹了 Python 的由來、特性、發展。並提供想要進一步深入的參考資料。

-----

Summary:

Python 的原意是蟒蛇,但 Python 這個語言則是來自一個叫 Monty Python 的團體 [1] - [3]。Python 是直譯式、膠合、物件導向的語言,結合以上三個特性,使 Python 成為同時受初學者與專家歡迎的語言 [4] - [7]。Python 有豐富的內建與外部擴充的函式庫,可用於統計、影像處理、機器學習、深度學習等 [8] - [12]。本文另外提供一些網路上的文章與電子書作為進階的參考 [13] - [15]。

-----


https://pixabay.com/zh/photos/snake-python-serpent-scales-543243/

-----

一、Python 命名的由來。

-----

Python 在希臘神話中,是一隻被 Apollo 太陽神殺掉的巨蟒。英式發音讀為「派森」,美式發音讀為「派三」。如果你對哈利波特第一集還有印象,哈利在他的表弟生日時,到動物園參觀,就跟裡面的一隻 python 對話過。國人常用的是美式發音,但由於 Python 這一詞來自 BBC,所以應該就還是讀為「派森」比較適合。

Python 的命名,來自「Monty Python's Flying Circus」,這是一系列英國 BBC 的超現實主義電視喜劇,不是馬戲團。據說「Monty」這個名字是 Monty Python 為了諷刺二戰英雄蒙哥馬利將軍(Field Marshal Lord Montgomery)。他們想要為這個名字找聽起來比較滑稽的姓,所以選了「Python」[2]。

Python 的創始人 Guido van Rossum 說:「 I chose Python as a working title for the project, being in a slightly irreverent mood (and a big fan of Monty Python's Flying Circus).」[2], [3]。我選 Python 作為專案的工作名稱,是因為當時有點想要搞笑(而且我是《蒙提· 派森的飛行馬戲團》的頭號粉絲)。

以上就是 Python 之所以為 Python 的簡短歷史。

-----

二、Python 的特性。

-----

Python 有幾個基本特性,它是直譯式語言、膠合語言、以及物件導向語言。

直譯式語言一行一行執行,有錯誤可以立刻發現,立刻改正,有助於初學者上手。膠合語言是因為 Python 在設計之初,就定位為協助程式設計師過來管理電腦系統,所以容易整合各種不同語言的程式與設定 [4]。

另外 Python 跟 C++、Java 一樣,都是物件導向的語言,而非像 C 一樣,是程序導向的語言。物件導向有封裝、繼承、多型等種種好的性質。

以上三個特性,使得 Python 廣受初學者與專家的歡迎,為 Python 開發的函式庫也越來越多,是一個正向的循環,所以 Python 的使用者也越來越多 [5] - [7]。

-----

三、Python 的保留字。

-----

在 Python 的環境下,執行以下兩行指令,

import keyword

keyword.kwlist

可以得到目前版本的保留字。

['False',  'None',  'True',  'and',  'as',  'assert',  'async',  'await',  'break',  'class',  'continue',  'def',  'del',  'elif',  'else',  'except',  'finally',  'for',  'from',  'global',  'if',  'import',  'in',  'is',  'lambda',  'nonlocal',  'not',  'or',  'pass',  'raise',  'return',  'try',  'while',  'with',  'yield'] [8]。

保留字是程式語言中最基本的部分,以下簡單分類,作為參考。

函式:def、class、return、yield、lambda、from、import。

變數:global、nonlocal、as、del。

邏輯:False、None、True、and、not、or、in、is、assert。

分支:if、else、elif。

迴圈:for、while、continue、break。

除錯:try、except、finally、raise。

其他:async、await、pass、with。


函式:一個程式,由一堆函式所組成,如果只有一個函式,那這個程式就是主函式 main。一個函式,要呼叫,或使用其他函式,可以透過 import 與 from。一個函式,則從 def 開始,到 return 或 yield 結束。class 裡面的 del,叫做 method。

變數:函式裡面主要處理資料,最簡單的資料型態是變數,變數可以是 global 或 nonlocal。如果沒有特別聲明,則是 local。

邏輯:邏輯值是運算的結果,也可以是變數。

分支:如果沒有分支,則函式內部是一條一條代碼,或者說是一個一個指令,循序執行。

迴圈:如果有一段程式會重複幾次執行,可以使用迴圈。

除錯:同字面上的意義,就是可以幫忙除錯。

其他:不在上面的功能,歸於其他。


程式的分解,就如同上面所述,你只要把程式要做的事,分解成上面的指令即可。

-----

四、庫。

-----

庫,指的是一堆函式的集合。

除了 35 個保留字之外,Python 還有 69 個內建函式,是函式庫中最常用的 [9],繼續延伸,則是標準的函式庫 [10]。

外部擴充的話,除了最受歡迎的 NumPy [11]、SciPy,還有機器學習的函式庫 Scikit-learn。它需要 Python (>= 2.7 or >= 3.3)、NumPy (>= 1.8.2)、SciPy (>= 0.13.3) 。MILK、Ramp、Bob 則是另外的機器學習的函式庫 [12]。

跟 SciPy 不同,Scipy packages 包含 Numpy、SciPy、Matplotlib、IPython、Sympy、Pandas。Matplotlib 用於繪圖,Pandas 用於資料庫。

深度學習有 Keras、TensorFlow、PyTorch、Caffe2、Chainer、Theano、PyBrain、Hebel。NTLK、Gensim 可用於 NLP。

以上是一些常見的內建、內部、與外部的函式庫。可以用 !pip list 觀察 Colab 已經預裝了哪些函式庫。

-----

五、深入 Python。

-----

網路上有豐富的 Python 資源,這裡簡單列出五十篇文章 [13]、一本免費下載的電子書(我有下載)[14]、15 本免費下載的電子書(我沒有下載)[15],作為繼續深入的參考。

-----

◎ 實作練習

-----

4 基本資料類型 [16]。

5 流程控制 [17]。

7 For 迴圈 [18]。

9 while 迴圈 [19]。

-----

誤:

lucky_number = input("請輸入你的幸運數字:")

print("我的幸運數字是 {}.format(lucky_number)")

正:

lucky_number = input("請輸入你的幸運數字:")

print("我的幸運數字是 {}.".format(lucky_number))

-----

誤:

starrings = ["Jennifer Aniston", "Courteney Cox", "Lisa Kudrow", "Matt LeBlanc", "Matthew Perry", "David Schwimmer"]

for starring in starrings:

    print starring

正:

starrings = ["Jennifer Aniston", "Courteney Cox", "Lisa Kudrow", "Matt LeBlanc", "Matthew Perry", "David Schwimmer"]

for starring in starrings:

    print(starring)

-----

誤:

starrings = ["Jennifer Aniston", "Courteney Cox", "Lisa Kudrow", "Matt LeBlanc", "Matthew Perry", "David Schwimmer"]

for i in range(len(starrings)):

    print starrings[i]

正:

starrings = ["Jennifer Aniston", "Courteney Cox", "Lisa Kudrow", "Matt LeBlanc", "Matthew Perry", "David Schwimmer"]

for i in range(len(starrings)):

    print(starrings[i])

-----

誤:

starrings = ["Jennifer Aniston", "Courteney Cox", "Lisa Kudrow", "Matt LeBlanc", "Matthew Perry", "David Schwimmer"]

i = 0

while i < 6:

    print starrings[i]

    i += 1

正:

starrings = ["Jennifer Aniston", "Courteney Cox", "Lisa Kudrow", "Matt LeBlanc", "Matthew Perry", "David Schwimmer"]

i = 0

while i < 6:

    print(starrings[i])

    i += 1

-----

誤:

from random import choice


coin_flips = [] # 建立一個空的清單放置每一次投擲的結果

coin = ["Head", "Tail"]


while coin_flips.count("Head") < 3:

    coin_flips.append(choice(coin))


print coin_flips # 印出每次投擲的紀錄

print len(coin_flips) # 總共投擲了幾次

正:

from random import choice


coin_flips = [] # 建立一個空的清單放置每一次投擲的結果

coin = ["Head", "Tail"]


while coin_flips.count("Head") < 3:

    coin_flips.append(choice(coin))


print(coin_flips) # 印出每次投擲的紀錄

print(len(coin_flips)) # 總共投擲了幾次

-----

References

[1] Monty Python and Robin Hood | Fafner's 遁世居

https://fafner-hideaway.blogspot.com/2010/05/monty-python-and-robin-hood.html


[2] Python 不是大蟒蛇、Java 就是一杯咖啡,程式語言都是如何命名的? | TechOrange

https://buzzorange.com/techorange/2016/03/14/how-do-you-name-your-language/


[3] Foreword for "Programming Python" (1st ed.) | Python.org

https://www.python.org/doc/essays/foreword/

-----

[4] 什麼是Python - Python

https://nkust.gitbook.io/python/


[5] Hello Python!|Python入門詳細介紹. 完整的Python介紹與使用,對想進入Python及Data… | by MAPE Academy | Python4U | Medium

https://medium.com/python4u/hello-python-509eabe5f5b1


[6] 一小時Python入門-part 1 - 寫點科普 Kopuchat

https://kopu.chat/2017/01/18/%E4%B8%80%E5%B0%8F%E6%99%82python%E5%85%A5%E9%96%80-part-1/


[7] 一小時Python入門-part 2 - 寫點科普 Kopuchat

https://kopu.chat/2017/01/18/%E4%B8%80%E5%B0%8F%E6%99%82python%E5%85%A5%E9%96%80-part-2/

-----

[8] Python保留字(關鍵字)一覽表 - tw511教學網

https://tw511.com/a/01/3236.html


[9] Built-in Functions — Python 3.9.2 documentation

https://docs.python.org/3/library/functions.html


[10] The Python Standard Library — Python 3.9.2 documentation

https://docs.python.org/3/library/


[11] 認識 Python 科學運算套件. 與 NumPy 初次見面 | by Yao-Jen Kuo | Pyradise | Medium

https://medium.com/pyradise/%E8%AA%8D%E8%AD%98-python-%E7%A7%91%E5%AD%B8%E9%81%8B%E7%AE%97%E5%A5%97%E4%BB%B6-c4e59f1d8ecc


[12] 34 Open-Source Python Libraries You Should Know About

https://www.mygreatlearning.com/blog/open-source-python-libraries/

-----

[13] Learn Python from Top 50 Articles for the Past Year (v.2019) | by Mybridge | Mybridge for Professionals

https://medium.mybridge.co/learn-python-from-top-50-articles-for-the-past-year-v-2019-3225f4643d9c


[14] Free Python Programming Book

https://books.goalkicker.com/PythonBook/


[15] 15 Free eBooks to Learn Python. Want to learn Python but can’t be… | by Brandon Morelli | codeburst

https://codeburst.io/15-free-ebooks-to-learn-python-c299943f9f2c


[16] 4 基本資料類型

https://bookdown.org/tonykuoyj/hello-py/section-4.html


[17] 5 流程控制

https://bookdown.org/tonykuoyj/hello-py/ifelse.html


[18] 7 For 迴圈

https://bookdown.org/tonykuoyj/hello-py/for-loop.html


[19] 9 while 迴圈

https://bookdown.org/tonykuoyj/hello-py/while-loop.html

-----

補充:

[20] 3. An Informal Introduction to Python — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/introduction.html


[21] 4. More Control Flow Tools — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/controlflow.html

-----

# Python 程式設計

http://yltang.net/tutorial/python/0/


Python Documentation contents — Python 3.9.2 documentation

https://docs.python.org/3/contents.html


Python - 維基百科,自由的百科全書

https://zh.wikipedia.org/wiki/Python


Python (programming language) - Wikipedia

https://en.wikipedia.org/wiki/Python_(programming_language)


# 日文

Python - Wikipedia

https://ja.wikipedia.org/wiki/Python


# 韓文

파이썬 - 위키백과, 우리 모두의 백과사전

https://ko.wikipedia.org/wiki/%ED%8C%8C%EC%9D%B4%EC%8D%AC


Welcome to Python.org

https://www.python.org/

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(二):Jupyter Notebook

 Colab(二):Jupyter Notebook

2021/03/10

-----


https://pixabay.com/zh/photos/jupiter-monde-planet-starry-sky-11101/

-----

一、Notebook:

-----

含 code cell 跟 text cell 兩部分。code cell 會再呼叫互動式的直譯核心,以 Python 為例,是 IPython。

-----

二、Jupyter Notebook:

-----

支援 Julia、Python、R,以及更多其他的語言。快速鍵 [5]。

-----

三、Colab:

-----

由 Google 代管的 Jupyter Notebook。

-----

以上知道一下就好了。Colab 還蠻好用的,有問題時再 google 即可。本篇沒有實作。

-----

References

[1] Project Jupyter | Home

https://jupyter.org/


[2] Install and Use — Jupyter Documentation 4.1.1 alpha documentation

https://jupyter.readthedocs.io/en/latest/install.html


[3] The Jupyter Notebook — Jupyter Notebook 6.2.0 documentation

https://jupyter-notebook.readthedocs.io/en/stable/


[4] Jupyter Notebook: An Introduction – Real Python

https://realpython.com/jupyter-notebook-introduction/


[5] Jupyter Notebook Keyboard Shortcuts by weidadeyue - Cheatography.com

https://cheatography.com/weidadeyue/cheat-sheets/jupyter-notebook/pdf_bw/


[6] Jupyter Notebook 完整介紹、安裝及使用說明. Python 開發環境介紹 - Jupyter Notebook 快速入門指南… | by Coding Lab | AI for K-12 | Medium

https://medium.com/ai-for-k12/jupyter-notebook-%E5%AE%8C%E6%95%B4%E4%BB%8B%E7%B4%B9-%E5%AE%89%E8%A3%9D%E5%8F%8A%E4%BD%BF%E7%94%A8%E8%AA%AA%E6%98%8E-846b5432f044


[7] Jupyter Notebook介紹及安裝說明 - Python4U - Medium

https://medium.com/python4u/jupyter-notebook%E5%AE%8C%E6%95%B4%E4%BB%8B%E7%B4%B9%E5%8F%8A%E5%AE%89%E8%A3%9D%E8%AA%AA%E6%98%8E-b8fcadba15f


[8] 人工智慧 - 使用 Jupyter Notebook | Microsoft Docs

https://docs.microsoft.com/zh-tw/archive/msdn-magazine/2018/february/artificially-intelligent-using-jupyter-notebooks

-----

補充:

[9] 2. Using the Python Interpreter — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/interpreter.html

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Colab(一):啟動

Colab(一):啟動

2020/12/27

前言:

本文蒐集了一些 Colab 的入門資料,以便開始在雲端寫作 Python 程式,並實做機器學習與深度學習專案。作為系列文章的第一篇,只選了幾個最基本的主題介紹。主要是設定工作環境,特別是網路硬碟。

-----

Summary:

Colab [1] 是 Google 提供的雲端 Python 工作環境 [2] - [4],並有免費的 GPU 可以使用 [5],檔案可以存放在 Google Drive 或是 Github [6]。一開始可以先察看 Colab 使用的 Python 版本 [7], [8]。如果要使用自己的 Google Drive 存取資料以便進行機器學習專案,要先登入自己的 Google Account 取得驗證碼 [8], [9]。讀者可以自行練習輸入些簡單的程式碼 [10]。

-----


https://pixabay.com/zh/photos/lab-research-chemistry-test-217043/

-----

一、啟動 Colab。

-----

開始頁面 [1]。


右下角的藍字,新增筆記本。

-----

二、切換至英文。切換至 GPU。

-----


上方的,說明,查看英文版本。

單純使用 Python 的話,不用切換至 GPU 模式。如果要切換,於上方 Runtime、Change runtime type,由 None 改為 GPU 即可。

-----

三、察看目前 Python 的版本。

-----

首先在畫面的左上角 + Code。

有兩個方法。

方法一 [7]。:!python -V。可得 Python 3.7.10。

方法二 [8]。:import sys; print(sys.version_info)。可得 sys.version_info(major=3, minor=7, micro=10, releaselevel='final', serial=0)。

-----

四、使用 Google Drive。

-----

方法一:[8]。

from google.colab import drive

drive.mount('/content/drive/')

# 點入系統提供的連結之後,登入自己的帳戶,會得到一組授權碼,將授權碼輸入後,即可存取自己的 Google drive。

!ls '/content/drive/My Drive/'

方法二:[9]。

-----

五、快速上手 [10]。

-----

1. 在 # 之後加上註解。

2. 用 print( 1 + 1 ) 輸出數學運算。

3. help(print)。

4. help()。

-----

六、存檔。

-----

可以把檔案存在 Google Drive 或 Github,也可以在網路上分享以便協同工作 [6]。

-----

◎ 實作練習

-----

1. 檢視 Python 版本 [7]。

2. 檢視 Google Drive 有哪些檔案 [8]。

3. 快速上手 [10]。

4. 存檔 [6]。

-----

References

[1] 歡迎使用 Colaboratory - Colaboratory

https://colab.research.google.com/


# 24K claps

[2] Google Colab Free GPU Tutorial. Now you can develop deep learning… | by fuat | Deep Learning Turkey | Medium

https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d


# 3.2K claps

[3] Getting Started With Google Colab | by Anne Bonner | Towards Data Science

https://towardsdatascience.com/getting-started-with-google-colab-f2fff97f594c


# 2.4K claps

[4] Colab: An easy way to learn and use TensorFlow | by TensorFlow | TensorFlow | Medium

https://medium.com/tensorflow/colab-an-easy-way-to-learn-and-use-tensorflow-d74d1686e309

-----

[5] 如何评价 Google Colab 提供的免费 GPU? - 知乎

https://www.zhihu.com/question/266242493

-----

[6] 推薦Python初學者的好用工具:Google Colab|數位時代

https://www.bnext.com.tw/article/52618/recommand-to-programming-language-learner-python-google-colab


[7] 透過 Google Colaboratory 學習使用 Python 做機器學習等科學計算 | by Eric ShangKuan | Medium

https://medium.com/@ericsk/%E9%80%8F%E9%81%8E-google-colaboratory-%E5%AD%B8%E7%BF%92%E4%BD%BF%E7%94%A8-python-%E5%81%9A%E6%A9%9F%E5%99%A8%E5%AD%B8%E7%BF%92%E7%AD%89%E7%A7%91%E5%AD%B8%E8%A8%88%E7%AE%97-9f92c7bb1f50


[8] 玩具烏托邦: 貴哥的 colab 初學筆記

https://newtoypia.blogspot.com/2019/07/colab.html


[9] GoogleDrive_Tutorial.ipynb - Colaboratory

https://colab.research.google.com/drive/1i41Whco5KIb7EuntKYwTVORAkAwCmlkF

-----

[10] 3 快速上手

https://bookdown.org/tonykuoyj/hello-py/get-started.html

-----

補充:

[11] 1. Whetting Your Appetite — Python 3.9.2 documentation

https://docs.python.org/3/tutorial/appetite.html

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Keras - DenseNet

 Keras - DenseNet

2021/03/21

-----

說明:

# 為本來的註解

## 為新增的註解

-----


-----

courses/densenet-keras.ipynb at master · fastai/courses · GitHub

https://github.com/fastai/courses/blob/master/deeplearning2/densenet-keras.ipynb

-----



Keras - ResNet

 Keras - ResNet

2021/03/21

-----

說明:

# 為本來的註解

## 為新增的註解

-----

## ResNet - 34

#coding=utf-8

from keras.models import Model

from keras.layers import Input,Dense,Dropout,BatchNormalization,Conv2D,MaxPooling2D,AveragePooling2D,concatenate,Activation,ZeroPadding2D

from keras.layers import add,Flatten

#from keras.layers.convolutional import Conv2D,MaxPooling2D,AveragePooling2D

import numpy as np

seed = 7

np.random.seed(seed)

 

def Conv2d_BN(x, nb_filter,kernel_size, strides=(1,1), padding='same',name=None):

    if name is not None:

        bn_name = name + '_bn'

        conv_name = name + '_conv'

    else:

        bn_name = None

        conv_name = None

 

    x = Conv2D(nb_filter,kernel_size,padding=padding,strides=strides,activation='relu',name=conv_name)(x)

    x = BatchNormalization(axis=3,name=bn_name)(x)

    return x

 

def Conv_Block(inpt,nb_filter,kernel_size,strides=(1,1), with_conv_shortcut=False):

    x = Conv2d_BN(inpt,nb_filter=nb_filter,kernel_size=kernel_size,strides=strides,padding='same')

    x = Conv2d_BN(x, nb_filter=nb_filter, kernel_size=kernel_size,padding='same')

    if with_conv_shortcut:

        shortcut = Conv2d_BN(inpt,nb_filter=nb_filter,strides=strides,kernel_size=kernel_size)

        x = add([x,shortcut])

        return x

    else:

        x = add([x,inpt])

        return x

 

inpt = Input(shape=(224,224,3))

x = ZeroPadding2D((3,3))(inpt)

x = Conv2d_BN(x,nb_filter=64,kernel_size=(7,7),strides=(2,2),padding='valid')

x = MaxPooling2D(pool_size=(3,3),strides=(2,2),padding='same')(x)

#(56,56,64)

x = Conv_Block(x,nb_filter=64,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=64,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=64,kernel_size=(3,3))

#(28,28,128)

x = Conv_Block(x,nb_filter=128,kernel_size=(3,3),strides=(2,2),with_conv_shortcut=True)

x = Conv_Block(x,nb_filter=128,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=128,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=128,kernel_size=(3,3))

#(14,14,256)

x = Conv_Block(x,nb_filter=256,kernel_size=(3,3),strides=(2,2),with_conv_shortcut=True)

x = Conv_Block(x,nb_filter=256,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=256,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=256,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=256,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=256,kernel_size=(3,3))

#(7,7,512)

x = Conv_Block(x,nb_filter=512,kernel_size=(3,3),strides=(2,2),with_conv_shortcut=True)

x = Conv_Block(x,nb_filter=512,kernel_size=(3,3))

x = Conv_Block(x,nb_filter=512,kernel_size=(3,3))

x = AveragePooling2D(pool_size=(7,7))(x)

x = Flatten()(x)

x = Dense(1000,activation='softmax')(x)

 

model = Model(inputs=inpt,outputs=x)

model.compile(loss='categorical_crossentropy',optimizer='sgd',metrics=['accuracy'])

model.summary()


-----

————————————————

版权声明:本文为CSDN博主「wmy199216」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/wmy199216/article/details/71171401

-----

Keras - NIN

 Keras - NIN

2021/03/21

-----

說明:

# 為本來的註解

## 為新增的註解

-----


-----

Network in Network(NIN) with Keras | Kaggle

https://www.kaggle.com/bingdiaoxiaomao/network-in-network-nin-with-keras

-----

Saturday, March 20, 2021

Keras - AlexNet

 Keras - AlexNet

2021/03/20

-----

說明:

# 為本來的註解

## 為新增的註解

-----

## AlexNet


#coding=utf-8

from keras.models import Sequential

from keras.layers import Dense,Flatten,Dropout

## AlexNet 架構與 LeNet 不同,但程式只多了 Dropout 一種層。

## https://keras.io/api/layers/regularization_layers/dropout/

from keras.layers.convolutional import Conv2D,MaxPooling2D

from keras.utils.np_utils import to_categorical

import numpy as np

seed = 7

np.random.seed(seed)

 

model = Sequential()

model.add(Conv2D(96,(11,11),strides=(4,4),input_shape=(227,227,3),padding='valid',activation='relu',kernel_initializer='uniform'))

model.add(MaxPooling2D(pool_size=(3,3),strides=(2,2)))

model.add(Conv2D(256,(5,5),strides=(1,1),padding='same',activation='relu',kernel_initializer='uniform'))

model.add(MaxPooling2D(pool_size=(3,3),strides=(2,2)))

model.add(Conv2D(384,(3,3),strides=(1,1),padding='same',activation='relu',kernel_initializer='uniform'))

model.add(Conv2D(384,(3,3),strides=(1,1),padding='same',activation='relu',kernel_initializer='uniform'))

model.add(Conv2D(256,(3,3),strides=(1,1),padding='same',activation='relu',kernel_initializer='uniform'))

model.add(MaxPooling2D(pool_size=(3,3),strides=(2,2)))

model.add(Flatten())

model.add(Dense(4096,activation='relu'))

model.add(Dropout(0.5))

model.add(Dense(4096,activation='relu'))

model.add(Dropout(0.5))

model.add(Dense(1000,activation='softmax'))

model.compile(loss='categorical_crossentropy',optimizer='sgd',metrics=['accuracy'])

model.summary()

-----

## ZFNet

model.add(Conv2D(96,(7,7),strides=(2,2),input_shape=(224,224,3),padding='valid',activation='relu',kernel_initializer='uniform')) 

## ZFNet 只有此行與 AlexNet 不同(?)。

-----

————————————————

版权声明:本文为CSDN博主「wmy199216」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/wmy199216/article/details/71171401

-----

Keras - LeNet

 Keras - LeNet

2021/03/20

-----

說明:

# 為本來的註解

## 為新增的註解

-----

## LeNet

#coding=utf-8

## utf-8 平衡 unicode 與 ASCII,且效率較 unicode 高。

## https://zh.wikipedia.org/wiki/UTF-8 

from keras.models import Sequential

## 一個空的網路,可以後續添加各種層。method 則有好幾個預設的可以使用。add()、pop()、summary() 等等。

## https://keras-cn.readthedocs.io/en/latest/getting_started/sequential_model/

## https://keras-cn.readthedocs.io/en/latest/models/sequential/

## https://keras.io/zh/getting-started/sequential-model-guide/

## https://keras.io/guides/sequential_model/

## https://keras.io/api/models/sequential/

from keras.layers import Dense,Flatten

## Dense 是全連接層,進 Dense 之前要先進 Flatten 展平。

## https://keras.io/api/layers/reshaping_layers/flatten/

from keras.layers.convolutional import Conv2D,MaxPooling2D

from keras.utils.np_utils import to_categorical

import cPickle

## cPickle。pickle 是 Python 的標準函式庫之一。cPickle 是 C 語言的版本。序列化,主要有 load() 與 dump() 兩個函數。

## https://docs.python.org/3/library/pickle.html

## https://blog.csdn.net/dcrmg/article/details/78180692

import gzip

## gzip 是 Python 的標準函式庫之一。

## https://docs.python.org/zh-tw/3/library/gzip.html

import numpy as np

seed = 7

np.random.seed(seed)

 

data = gzip.open(r'/media/wmy/document/BigData/kaggle/Digit Recognizer/mnist.pkl.gz')

train_set,valid_set,test_set = cPickle.load(data)

## cPickle.load(data)。將原始的資料集序列化之後,載入記憶體。

#train_x is [0,1]

train_x = train_set[0].reshape((-1,28,28,1))

## 「newshape int or tuple of ints。The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.」-1 表示要轉換資料長度未定,格式則根據後續的設定轉換。以此例而言。-1 表示 train_set[0],也就是 train_x 的長度不知道。反正就是把全部的資料轉成 28 x 28 x 1 就對了。

## https://numpy.org/doc/stable/reference/generated/numpy.reshape.html

## https://blog.csdn.net/wld914674505/article/details/80460042

train_y = to_categorical(train_set[1])

 

valid_x = valid_set[0].reshape((-1,28,28,1))

valid_y = to_categorical(valid_set[1])

 

test_x = test_set[0].reshape((-1,28,28,1))

test_y = to_categorical(test_set[1])

 

model = Sequential()

model.add(Conv2D(32,(5,5),strides=(1,1),input_shape=(28,28,1),padding='valid',activation='relu',kernel_initializer='uniform'))

## kernel_initializer。uniform 似乎是舊版的參數。不在說明文檔裡面。

## https://keras.io/zh/initializers/

## https://zh.wikipedia.org/wiki/%E9%80%A3%E7%BA%8C%E5%9E%8B%E5%9D%87%E5%8B%BB%E5%88%86%E5%B8%83

model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(64,(5,5),strides=(1,1),padding='valid',activation='relu',kernel_initializer='uniform'))

## padding。valid:卷積後特徵圖縮小。same:卷積後特徵圖不縮小。

## https://oldpan.me/archives/tf-keras-padding-vaild-same

model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())

model.add(Dense(100,activation='relu'))

model.add(Dense(10,activation='softmax'))

model.compile(optimizer='sgd',loss='categorical_crossentropy',metrics=['accuracy'])

## accuracy。「對於任何分類問題,你都希望將其設置為 metrics = ['accuracy']。評估標準可以是現有標準的編碼標識符,也可以是自定義的評估標準函數。」

## https://keras.io/zh/getting-started/sequential-model-guide/

model.summary()

## model.summary()。用文字顯示模型各層的參數狀態。

## https://blog.csdn.net/ybdesire/article/details/85217688

model.fit(train_x,train_y,validation_data=(valid_x,valid_y),batch_size=20,epochs=20,verbose=2)

## verbose。「verbose = 2 為每個 epoch 輸出一行記錄。」

## https://www.jianshu.com/p/159a9ac413fa

#[0.031825309940411217, 0.98979999780654904]

print model.evaluate(test_x,test_y,batch_size=20,verbose=2)

-----

————————————————

版权声明:本文为CSDN博主「wmy199216」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/wmy199216/article/details/71171401

-----

Friday, March 19, 2021

Python Notebook

 Python Notebook

2021/03/19

-----

Python 筆記本:記錄一些要消化的東西。

-----


Fig.  Python(圖片來源)。

-----

# (18) Learn Python - Full Course for Beginners [Tutorial] - YouTube

https://www.youtube.com/watch?v=rfscVS0vtbw&t=406s

38:00 2021/03/28

-----

# (25) Intermediate Python Programming Course - YouTube

https://www.youtube.com/watch?v=HGOBQPFzWKo

-----

從 Colab 到 Kaggle(目錄)

https://hemingwang.blogspot.com/2021/03/colab_12.html

-----

Sunday, March 07, 2021

深度學習經典論文

深度學習經典論文

2021/01/28

-----

前言:

若將深度學習的核心濃縮成兩個主題:在電腦視覺 Computer Vision(CV)上,可說 CV 就是 ResNet,Ensemble 的 CNN。在自然語言處理 Natural Language Processing(NLP)上,可說 NLP 就是文字向量在垂直上的詞義 word meaning、句法 syntax、語義 semantic 分解與水平上的 Query、Key、Value(QKV)分解。底下以四十篇論文來闡述這個論點。

-----


https://pixabay.com/zh/photos/camera-photographs-souvenir-1130731/

-----

以下是論文閱讀順序的編排:

分成十個階段,選擇四十篇論文,CV 與 NLP 各半,「簡述」十篇深度學習經典論文(LeNet、NIN、ResNet、FCN、YOLO、LSTM、Seq2se2、Attention、ConvS2S、Transformer) 跟延伸的主題(AlexNet、GoogLeNet、DenseNet、PFPNet、Mask R-CNN、Word2vec、Paragraph2vec、Short Attention、ELMo、BERT)。

-----

01A:LeNet。01B:AlexNet(可補充 Dropout)。

02A:NIN(可補充 SENet)。02B:GoogLeNet(可補充 Inception v3,Label smoothing)。

03A:ResNet。03B:DenseNet(可補充 CSPNet,YOLO v4 的骨幹網路)。

04A:FCN。04B:PFPNet(可補充 Faster R-CNN 與之前的論文)。

05A:YOLO(可補充 YOLO v4)。05B:Mask R-CNN(可補充 Faster R-CNN 與之後的論文)。

-----

06A:LSTM。06B:Word2vec(詞義、句法)(可補充 C&W v2)。

07A:Seq2seq。07B:Paragraph2vec(詞義、句法、語義)(可補充 Skip-thought)。

08A:Attention。08B:Short Attention(QKV,水平分解)。

09A:ConvS2S。09B:ELMo(詞義、句法、語義,的垂直分解)(可補充 Context2vec)。

10A:Transformer。10B:BERT(詞義、句法、語義,的垂直分工,可補充 BERT NLP Pipeline)。

-----

Summary:


以下是 CV [1]-[20]。


1998 的 LeNet [1] 是經典的卷積神經網路 Convolutional Neural Network(CNN),架構包含卷積層、機活函數、池化層、全連接層、輸出層、損失函數、梯度下降與反向傳播的介紹。

2012 的 AlexNet [2] 則是第一個大獲成功的 CNN,它的圖片與資料集都比 LeNet 大。除了使用 GPU 加速,也整合了當時許多的技巧,最重要的是 Dropout [3]。Dropout 是以隨機丟棄神經元的訓練方式,使得網路具有多個子網路的平均的加成效果。Dropout 的技巧也被用在 Transformer 上。

NIN [4] 藉著通道間特徵圖的重新融合,不僅提高正確率,它的主要技巧 Conv1 可以用來升降維(增多或減少特徵圖數量)也成為後續神經網路的標準配備。SENet [5] 也探討通道間的特徵圖,但它不是如 NIN 的重新融合,而是就單一特徵圖整張的值進行放大或縮小。

GoogLeNet [6] 是 AlexNet 之後成功的深層網路,它運用 NIN 的 Conv1 將 5x5、3x3、1x1、Maxpooling 四種特徵圖重新融合並持續加深,獲得了 AlexNet 之後,新的成功。GoogLeNet 又可稱為 Inception v1。Inception v3 [7] 有一個 Label Smoothing 的技巧,有正規化的功能,可以減少過度擬合,Label Smoothing 的技巧也被用在 Transformer 上。

ResNet [8] - [12] 可說是 CNN 的核心。ResNet v1 [8] 加上 identity mapping,成功地將 VGGNet 的十九層推進到百層,但無法到千層。ResNet-D [9] 則加上 Dropout 的技巧隨機丟棄一些卷積層,成功地將網路推進到千層。ResNet v2 [10] 則是將 ReLU 搬到 identity mapping 之外,不需使用 Dropout 的技巧,也可以將網路推進到千層。ResNet-E [11] 分析了 ResNet v2,發現它其實是多的淺層網路的 ensemble。ResNet-V [12] 將 ResNet 的損失函數可視化,發現比起 VGGNet 等傳統 CNN,ResNet 的損失函數平化許多。這是因為 ensemble 的平均所造成。Dropout 也是一種 ensemble。

DenseNet [13] 有別於 ResNet 的 ensemble,它將特徵圖在後續的層重新平均,所以損失函數也呈現平滑化。DenseNet 與 ResNet 的效果接近。CFPNet [14] 減少特徵圖的計算,可以加速 ResNet 與 DenseNet 並取得接近的正確率,CFPNet 是 YOLO v4 的骨幹網路。

以上,LeNet、NIN、ResNet 是 CNN 的三個階段性演進。

FCN [15] 全卷積網路是第一個成功的語義分割網路,有別於 CNN 主要是圖片分類,FCN 的功能是像素分類,屬於 CNN 的應用。全卷積網路不需要固定輸入圖片的大小。

PFPNet [16] 是基於 FCN 的全景分割。物件偵測(以 Faster R-CNN 為例)加上語義分割(以 FCN 為例)是實例分割(以 Mask R-CNN 為例)。全景分割(以 PFPNet 為例)則是語義分割(以 FCN 為例)加上實例分割(以 Mask R-CNN 為例)。

YOLO [17] 是第一個成功的 one-stage 物件偵測,快,但是準確率不高。到 YOLO v4 [18] 的時候,快,而且準確率高。Mask R-CNN [19] 則是基於 two-stage 物件偵測的 Faster R-CNN [20] 上的實例偵測。它使用 RoIAlign 確定像素在池化前的真正位置,提高了正確率。

-----

以下是 NLP [21]-[40]。 

LSTM [21] 用來處理時序資料,若時序資料是文字,則文字需要用 Word Embedding [22] - [26] 的技巧先將文字轉成向量,才可以用 LSTM 處理。

Word2vec [22] - [24] 是經典的詞向量技巧。Word2vec 1 [22] 主要是多字預測一字的 CBOW 與一字預測多字的 skip-gram。訓練技巧在 Word2vec 2 [23] 提到有 Negative Sampling 減少不需要的取樣以及 Hierarchical Softmax 重組預測路徑來改善 Word2vec 的訓練。Word2vec 3 [24] 則是簡易論文版本。C&W v1 [25] 與 C&W v2 [26] 也是詞向量的方法。其中 C&W v2 用 window approach 在語義上的任務效能較差,因此論文作者又推出 sentence approach 的版本,此結果說明了 Sentence Embedding 的必要性。

Seq2seq 1 [27] 與 Seq2seq 2 [ 28] 是基於 LSTM(或類似的 GRU)單元的模型,主要用途也是機器翻譯。優於 LSTM 的地方在於整句讀完再輸出,避免斷章取義的缺點。

Paragraph2vec [29] 是 Sentence Embedding 句向量的方法。跟 Word2vec 類似,只是整個段落會變成一個 id 參與訓練,因此 id 就會獲得一個句向量。此方法不算實用,後續的 Skip-thought [30] 基於 Seq2seq 的架構,只是輸入句可以同時預測前一個句子與後一個句子,如此訓練效果較佳。

Attention [31] - [33] 比起 Seq2seq 將句子壓縮成單一向量的粗糙作法,它的每個輸出字都會考慮輸入句的每個字的權重。Attention 1 [31] 考慮的是整個輸入句,Visual Attention [32] 將 Attention 的概念用在圖片文字的轉換上。Attention 2 [33] 則是在 Attention 1 的 Global Attention 上,又增加了 Local Attention。

Short Attention [34] 則是在 Memory Network 的基礎上,仔細探討詞向量如何分解成 Query、Key、Value 三個向量。Key 類似 index,Value 是實際的內容,Query 則是下一個字的預測的機率分布。QKV 被使用於 ConvS2S 與 Transformer。

ConvS2S [35] 不使用傳統的 LSTM,而是用一維的 CNN 來處理文字向量,因此可以用 GPU 加速。QKV 的分解也改善了結果。

ELMo [36] 是 Context2vec [37] 的較佳論文。可以改善一字多義的語義級別的 NLP 任務。它先在預訓練層級將 Word Meaning、Syntax、Semantic 三個層級的向量串接起來,然後在實際的任務訓練出個別的權重。

Transformer [38] 與 ConvS2S 架構上類似,都是 Source-Output-Target Relational Model(STORM)。最大的差別是 Transformer 不用卷積,並且在 Encoder 與 Decoder 兩端都先使用全連接的 self-attention,可以精確地理解每個字在句子中代表哪個其他的字。

BERT [39] 使用雙向的 Transformer Encoder 的模型先進行預訓練。預訓練有兩個方法,克漏字類似 CBOW,預測缺少的字,以及下個句子預測,類似 Skip-gram。後續再加上簡單的線性輸出層,進行四種主要的 NLP 任務。BERT NLP [40] 則是用實驗分析 BERT 在詞向量的輸入後,BERT 的低層主要實現 Syntax 的功能,高層主要實現 Semantic 的功能。

-----

結語:

Summary 的內容,簡單以四十篇論文,總結了深度學習的機器視覺與自然語言處理的演進,核心我們再說一次::在電腦視覺 Computer Vision(CV)上,可說 CV 就是 ResNet,Ensemble 的 CNN。在自然語言處理 Natural Language Processing(NLP)上,可說 NLP 就是文字向量在垂直上的詞義 word meaning、句法 syntax、語義 semantic 分解與水平上的 Query、Key、Value(QKV)分解。

-----

References


# 01A

[1] LeNet。

LeCun, Yann, et al. "Gradient-based learning applied to document recognition." Proceedings of the IEEE 86.11 (1998): 2278-2324.

http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf


# 01B

[2] AlexNet。(Dropout)。

Krizhevsky, Alex, Ilya Sutskever, and Geoffrey E. Hinton. "Imagenet classification with deep convolutional neural networks." Advances in neural information processing systems 25 (2012): 1097-1105.

https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf

-----

[3] Dropout。

Srivastava, Nitish, et al. "Dropout: a simple way to prevent neural networks from overfitting." The journal of machine learning research 15.1 (2014): 1929-1958.

https://www.jmlr.org/papers/volume15/srivastava14a/srivastava14a.pdf


# 02A

[4] NIN。

Lin, Min, Qiang Chen, and Shuicheng Yan. "Network in network." arXiv preprint arXiv:1312.4400 (2013).

https://arxiv.org/pdf/1312.4400.pdf


[5] SENet。

Hu, Jie, Li Shen, and Gang Sun. "Squeeze-and-excitation networks." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018.

https://openaccess.thecvf.com/content_cvpr_2018/papers/Hu_Squeeze-and-Excitation_Networks_CVPR_2018_paper.pdf


# 02B

[6] GoogLeNet。(Inception 系列,到 v3 時有 Label Smoothing)。

Szegedy, Christian, et al. "Going deeper with convolutions." Proceedings of the IEEE conference on computer vision and pattern recognition. 2015.

https://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Szegedy_Going_Deeper_With_2015_CVPR_paper.pdf


[7] Inception v3。

Szegedy, Christian, et al. "Rethinking the inception architecture for computer vision." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.

https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Szegedy_Rethinking_the_Inception_CVPR_2016_paper.pdf

-----

# 03A

[8] ResNet v1。

He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.

https://openaccess.thecvf.com/content_cvpr_2016/papers/He_Deep_Residual_Learning_CVPR_2016_paper.pdf


[9] ResNet-D。

Huang, Gao, et al. "Deep networks with stochastic depth." European conference on computer vision. Springer, Cham, 2016.

https://arxiv.org/pdf/1603.09382.pdf


[10] ResNet v2。

He, Kaiming, et al. "Identity mappings in deep residual networks." European conference on computer vision. Springer, Cham, 2016.

https://arxiv.org/pdf/1603.05027.pdf


[11] ResNet-E。

Veit, Andreas, Michael J. Wilber, and Serge Belongie. "Residual networks behave like ensembles of relatively shallow networks." Advances in neural information processing systems. 2016.

https://papers.nips.cc/paper/2016/file/37bc2f75bf1bcfe8450a1a41c200364c-Paper.pdf


[12] ResNet-V。

Li, Hao, et al. "Visualizing the loss landscape of neural nets." Advances in Neural Information Processing Systems. 2018.

https://papers.nips.cc/paper/2018/file/a41b3bb3e6b050b6c9067c67f663b915-Paper.pdf


# 03B

[13] DenseNet。

Huang, Gao, et al. "Densely connected convolutional networks." Proceedings of the IEEE conference on computer vision and pattern recognition. 2017.

https://openaccess.thecvf.com/content_cvpr_2017/papers/Huang_Densely_Connected_Convolutional_CVPR_2017_paper.pdf


[14] CSPNet。

Wang, Chien-Yao, et al. "CSPNet: A new backbone that can enhance learning capability of cnn." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops. 2020.

https://openaccess.thecvf.com/content_CVPRW_2020/papers/w28/Wang_CSPNet_A_New_Backbone_That_Can_Enhance_Learning_Capability_of_CVPRW_2020_paper.pdf


# 04A

[15] FCN。

Long, Jonathan, Evan Shelhamer, and Trevor Darrell. "Fully convolutional networks for semantic segmentation." Proceedings of the IEEE conference on computer vision and pattern recognition. 2015.

https://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Long_Fully_Convolutional_Networks_2015_CVPR_paper.pdf


# 04B

[16] PFPNet。

Kirillov, Alexander, et al. "Panoptic feature pyramid networks." Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2019.

https://openaccess.thecvf.com/content_CVPR_2019/papers/Kirillov_Panoptic_Feature_Pyramid_Networks_CVPR_2019_paper.pdf


# 05A

[17] YOLO。被引用 12295 次。

Redmon, Joseph, et al. "You only look once: Unified, real-time object detection." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.

https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Redmon_You_Only_Look_CVPR_2016_paper.pdf


[18] YOLOv4。

Bochkovskiy, Alexey, Chien-Yao Wang, and Hong-Yuan Mark Liao. "YOLOv4: Optimal Speed and Accuracy of Object Detection." arXiv preprint arXiv:2004.10934 (2020).

https://arxiv.org/pdf/2004.10934.pdf


# 05B

[19] Mask R-CNN。

He, Kaiming, et al. "Mask r-cnn." Proceedings of the IEEE international conference on computer vision. 2017.

https://openaccess.thecvf.com/content_ICCV_2017/papers/He_Mask_R-CNN_ICCV_2017_paper.pdf


[20] Faster R-CNN。

Ren, Shaoqing, et al. "Faster r-cnn: Towards real-time object detection with region proposal networks." arXiv preprint arXiv:1506.01497 (2015).

https://arxiv.org/pdf/1506.01497.pdf


# 06A

[21] LSTM。

Hochreiter, Sepp, and Jürgen Schmidhuber. "Long short-term memory." Neural computation 9.8 (1997): 1735-1780.

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.676.4320&rep=rep1&type=pdf


# 06B

[22] Word2vec 1。

Mikolov, Tomas, et al. "Efficient estimation of word representations in vector space." arXiv preprint arXiv:1301.3781 (2013).

https://arxiv.org/pdf/1301.3781.pdf


[23] Word2vec 2。

Mikolov, Tomas, et al. "Distributed representations of words and phrases and their compositionality." Advances in neural information processing systems. 2013.

https://papers.nips.cc/paper/2013/file/9aa42b31882ec039965f3c4923ce901b-Paper.pdf


[24] Word2vec 3。

Rong, Xin. "word2vec parameter learning explained." arXiv preprint arXiv:1411.2738 (2014).

https://arxiv.org/pdf/1411.2738.pdf


[25] C&W v1。

Collobert, Ronan, and Jason Weston. "A unified architecture for natural language processing: Deep neural networks with multitask learning." Proceedings of the 25th international conference on Machine learning. 2008.

http://www.cs.columbia.edu/~smaskey/CS6998-Fall2012/supportmaterial/colbert_dbn_nlp.pdf


[26] C&W v2。

Collobert, Ronan, et al. "Natural language processing (almost) from scratch." Journal of machine learning research 12.ARTICLE (2011): 2493-2537.

https://www.jmlr.org/papers/volume12/collobert11a/collobert11a.pdf


# 07A

[27] Seq2seq 1。

Sutskever, Ilya, Oriol Vinyals, and Quoc V. Le. "Sequence to sequence learning with neural networks." Advances in neural information processing systems. 2014.

http://papers.nips.cc/paper/5346-sequence-to-sequence-learning-with-neural-networks.pdf


[28] Seq2seq 2。

Cho, Kyunghyun, et al. "Learning phrase representations using RNN encoder-decoder for statistical machine translation." arXiv preprint arXiv:1406.1078 (2014).

https://arxiv.org/pdf/1406.1078.pdf


# 07B

[29] Paragraph2vec。

Le, Quoc, and Tomas Mikolov. "Distributed representations of sentences and documents." International conference on machine learning. 2014.

http://proceedings.mlr.press/v32/le14.pdf


[30] Skip-thought。

Kiros, Ryan, et al. "Skip-thought vectors." arXiv preprint arXiv:1506.06726 (2015).

https://arxiv.org/pdf/1506.06726.pdf


# 08A

[31] Attention 1。

Bahdanau, Dzmitry, Kyunghyun Cho, and Yoshua Bengio. "Neural machine translation by jointly learning to align and translate." arXiv preprint arXiv:1409.0473 (2014).

https://arxiv.org/pdf/1409.0473.pdf


[32] Visual Attention。

Xu, Kelvin, et al. "Show, attend and tell: Neural image caption generation with visual attention." International conference on machine learning. 2015.

http://proceedings.mlr.press/v37/xuc15.pdf


[33] Attention 2。

Luong, Minh-Thang, Hieu Pham, and Christopher D. Manning. "Effective approaches to attention-based neural machine translation." arXiv preprint arXiv:1508.04025 (2015).

https://arxiv.org/pdf/1508.04025.pdf


# 08B

[34] Short Attention。

Daniluk, Michał, et al. "Frustratingly short attention spans in neural language modeling." arXiv preprint arXiv:1702.04521 (2017).

https://arxiv.org/pdf/1702.04521.pdf


# 09A

[35] ConvS2S。

Gehring, Jonas, et al. "Convolutional sequence to sequence learning." arXiv preprint arXiv:1705.03122 (2017).

https://arxiv.org/pdf/1705.03122.pdf


# 09B

[36] ELMo。

Peters, Matthew E., et al. "Deep contextualized word representations." arXiv preprint arXiv:1802.05365 (2018).

https://arxiv.org/pdf/1802.05365.pdf


[37] Context2vec。被引用 312 次。

Melamud, Oren, Jacob Goldberger, and Ido Dagan. "context2vec: Learning generic context embedding with bidirectional lstm." Proceedings of the 20th SIGNLL conference on computational natural language learning. 2016.

https://www.aclweb.org/anthology/K16-1006.pdf


# 10A

[38] Transformer。

Vaswani, Ashish, et al. "Attention is all you need." Advances in neural information processing systems. 2017.

https://papers.nips.cc/paper/7181-attention-is-all-you-need.pdf


# 10B

[39] BERT。

Devlin, Jacob, et al. "Bert: Pre-training of deep bidirectional transformers for language understanding." arXiv preprint arXiv:1810.04805 (2018).

https://arxiv.org/pdf/1810.04805.pdf


[40] BERT NLP Pipeline。

Tenney, Ian, Dipanjan Das, and Ellie Pavlick. "BERT rediscovers the classical NLP pipeline." arXiv preprint arXiv:1905.05950 (2019).

https://arxiv.org/pdf/1905.05950.pdf

-----