くじら公園

プログラミングなど学んだことについて書きます

Deep Learning Specialization(Coursera) - Course 3のメモ

CourseraDeep Learning Specializationの受講メモです。Deep Learning SpecializationはMachine Learningコースを提供するAndrew Ng氏、および氏が創設したdeeplearning.aiが提供する深層学習に関する一連の講義です。以下の5つのコースから構成されています。

  • COURSE 1: Neural Networks and Deep Learning
  • COURSE 2: Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimizationw
  • COURSE 3: Structuring Machine Learning Projects
  • COURSE 4: Convolutional Neural Networks
  • COURSE 5: Sequence Models

今回はCOURSE 3、Structuring Machine Learning Projectsを受講した際の備忘録的なメモです。Deep Learning Specialization全体を受講したうえでのまとめは別途記載する予定です。


COURSE 3: Structuring Machine Learning Projects

COURSE 3は機械学習システムの開発を効率よく進めるためのノウハウなどについての内容でした。COURSE 3の"About this course"には、本コースの内容は現時点でここでしか学べないものばかりであることが強調されていますが、COURSE 3を終えてみて、実際に機械学習を用いたシステムを開発する際の体系立てられたノウハウなど、他の教材ではあまり扱わない内容を学ぶことができました。

本コースは2週構成でした。Week 1ではまず深層学習システムを改善するときの戦略―複数の改善を見込めるアイデアがあるときに、最も有望なものから手をつけるために問題を解析することについて学んだ後、その解析の手段として、数値目標の設け方、human levelのパフォーマンスと学習データ、検証用データ、テスト用データに対するパフォーマンスの比較の仕方などを学びます。Week 2ではそのパフォーマンスを比較する際の方法の一つであるエラー分析の仕方から始まり、学習データと検証・テストデータが同じ分布から得られているかの検証方法などに加え、パフォーマンスの向上が見込める施策として転移学習、multi-task学習、End-to-end学習について学びます。本コースはプログラミングの宿題はなくクイズのみでした。ただしいつもの単発のクイズではなく特定のシナリオを想定したケーススタディとなっていました。

受講期間の公式の見積もりは"2 weeks of study, 3-4 hours/week"となっており、実際に要した時間は凡そ7時間でした。

以下メモです(ただメモを張り付けているだけなので、体裁が崩れていたらすみません…):

Week 1

ビデオ3時間、クイズ30分

内容

ビデオ
  • Introduction to ML Strategy
    • Why ML Strategu?
      • When trying to improve a deep learning system, you often have a lot of ideas or things you could try. And the problem is thatif you choose poorly, it is entirely possible that end up you spending six months charging in some direction only to realize six months that didn't do good.

      • ML strategies: Waysof analyzing a machine learning problem that will point you in the direction of the most promising things to try.

    • Orthogonalization
      • They're very clear-eyed about what to tune in order to try to achive one effect.

      • 画面を調節するためのノブ(knob)がいくつかついている古いテレビによるアナロジー
        • So in this context, orthogonalization refers to that the TV designers had designed the knobs so that each knob kind of dose only one thing. And this makes it muche eisier to tune the TV.

        • 例えばあるノブが画面の縦比と横比の両方を調節するものである場合と、縦比と横比を調節する別個のノブが用意されている場合を比べると、後者の方が画面を調節しやすい、これがOrthogonalization
      • 車によるアナロジー、普通の車はノブとしてハンドルとアクセル(とブレーキ)がある、架空の車として方向と速度を一変に調節できるジョイスティックを二つ持った車を想定すると、普通の車と架空の車のどちらが御するのが容易?
        • 縦軸速度、横軸方向の二軸のチャート、軸方向にだけ制御できる方が全体としての制御が容易
      • MLの文脈で考えてみる
        • Chain of assumption in ML
          • Fit training set well on cost function
          • Fit dev set well on cost function
          • Fit test set well on cost function
          • Performs wekk in real world
        • 上記4つの問題・ステップで取り組むのがOrthogonalization、逆に言えばこれらを混ぜると制御が難しくなる
        • Early stopping: Orthogonalizationに反する
          • This is one knob that is less orthogonalization, because it simultaneously offers two things: * > It offers how well you fit the training set. * > It improves dev set performance.

  • Setting up your goal
    • Single number evaluation metric
      • PrecissionとRecallの例
        • 二つ以上の指標を用いるより一つの指標を用いた方が効率的、この場合はF値を使うべし
        • Dev set + Single real number evaluation metric -> Speed up iterating

    • Satisficing and Optimizing metric
      • 猫分類器の例、accuracyとrunning timeを向上させたいとする
      • この場合はさっきみたいに二つの指標を一つに組み合わせるする代わりに以下のとおり指標を設定する
        • maximize accuracy

        • subject to runningTime < 100ms

      • accuracyがoptimizing metric、running timeがsatisficing metric
      • N metrics: 1 optimizingとN - 1 satisficing(threshold)
    • Train dev/set distribution
      • Choose a dev set and test set to reflect data you expect to get in the future and consider important to do well on.

    • Size of dev and test set
      • Set your test set to be big enough to give high confidence in the overrall performance of your system.

    • When to change dev/test sets and metrics
      • 猫分類器の例
        • Metric: classification error
        • Algorithm A: 3% error, B: 5% error
        • でもAはポルノ画像を猫と間違えてしまう
        • Metricを変更する
          • 元のError: (1 / m{dev}) \sum{i}^m{dev} I {y{prod}^{(i)} \neq y^{(i)}}
          • 改善後のError: (1 / m{dev}) \sum{i}^m{dev} w^{(i)} I {y{prod}^{(i)} \neq y^{(i)}}
            • w^{(i)} = 1 if x^{i} is non-porn else 10
        • これもorthogonalization
          • So far we've only discussed how to define a metric to evaluate classifiers.

          • Worry separately about how to do well on this metric.

      • So my recommendation is, even if you can't define the perfect evaluation metric and dev set, just set something up quickly and use that to drive the speed of your team iteration. And if later down the line you find out that it wasn't a goode one, you have better idea, change it at that time.

  • Comparingto human-level performance
    • Why human level performance?
      • First is that because of advance in DL ML algorithmsare are suddenly working much better and so it has become much more feasible in a lot of application areas for ML algorithms to actually become aompetitive with human-level performance.

      • Second, it turns out that the workflow of designing and building a ML system, the workflow is much more efficient when you're trying to do something that humans can also do.

      • Bayes optimal error: パフォーマンスの理論的な上限値; the very best theoretical function for mapping from x to y
      • 試行するうちにaccについてhuman-levelよりは向上してもBayes errorは越えられない
      • MLがhuman levelより悪いときは:
        • Get labeled data from humans.
        • Gain insight from manual error analysis.
          • Why did a person get this right?
        • Better analysis of bias/variance.
    • Avoidable bias: Human level error as a proxy for Bayes error
      • 猫分類の問題
        • Human: 1%, Training: 8%, dev: 10%のとき、8 - 1 = 7がAvoidable bias、biasにfocusする
        • Human: 7.5%, Training: 8%, dev: 10%のとき、8 - 1 = 05がAvoidable bias、varianceにfocusする
    • Understanding human-level performance
      • レントゲン診断の分類器を作るとき、human levelが以下の場合Bayes errorhはどれ?
        1. Typical human: 3%
        2. Typical doctor: 1%
        3. Experienced doctor: 0.7%
        4. Teams of experienced doctors 0.5%
      • 答えは4、Baues errorは0.5%だから
      • Having an estimate of human-level performance gives you an estimate of Bayes error. And this allows you to more quickly make decisions as to whether you should focus on trying to reduce a bais or trying to reduce the variance of your algorithm.

    • Surpassing human level performance
      • Online ad, recommendation, load approval等structured dataに対してはすでにMLは人を凌駕している
        • これらは人には見切れないほどのデータがある
      • Not natural, perception problemsは逆に人が得意
Case Study

今回のExerciseは架空の町のために空を飛んでいる鳥を検知するアルゴリズムを開発するというシナリオで、ビデオ講義で魏トンされたような状況に面した際にどう振る舞うのが適切かを問う形式のクイズになっていた。

所感

  • ビデオが中心なのでいつもより時間がかかった
  • 機械学習や深層学習のテクニックや知識を教えてくれる教材は多くあるけれど、このコースのようにそれらテクニックや知識を持っている上で実際に深層学習を用いたシステムを開発する時のノウハウについてこのように体系立てて学べるリソースは他に思い当たらない

Week 2

ビデオ2時間、Case Study 1時間

内容

ビデオ
  • Error Analysis: Manually examining mistakes that your algorithm is making, can give you insights into what to do next.
    • Look at dev examples to evaluate ideas
      • 例として猫分類器を考える、分類器が犬の写真を誤って猫と分類した。90% acc, 10% err
        • Should you try to make your cat classifier do better on dogs?

        • Error analysis:
          1. Get ~100 mislabeled dev set examples
          2. Count up how many are dogs
        • 結果、5%が犬だった→犬問題に取り組むことで10%のerrを9.5%にできる
      • ceiling(天井)を見つける
        • Upper bound on how much you could improve performance by working on the dog problem

      • Evaluate multiple ideas in parallel
        • 猫分類のideaとして例えば犬を間違える、ライオンとかを間違える、ぼやけた画像を間違える、インスタの画像で間違えるの四つの問題―改善案があるときに、スプレッドシートを開いて画像100枚についてこの四つの問題のどれを被っているか一覧にして、四つのそれぞれが何割くらい発生しているか確認する
    • Cleaning up incorrectly labeled data
      • If you find that your data has some incorrectly labeled examples, what should you do?

      • DL algorithm are quite robust to random errors in the training set. * > If the errors are reasonably random, then it's probably okay to just leave the errors.

      • They are less robust to systematic errors.

      • dev/test setのときは前述のスプレッドシートに"Incorrectly labeld"という問題も加えて吟味する、例えば
        • Overroll dev set error: 10%, errors due incorrect labels: 6%
          • →0.1 * 0.06 * 100でこれを改善することで10%のerrを9.4%に改善できると見積もることができる
        • Goal of dev set is to help you select between two classifiers A and B.

        • もしdev setのIncorrectly labeled dataの割合が大きいときはこの本来の目的を達成できない可能性がある
    • Build your first system quickly, then iterate. 1. Setup dev/test set and metric 2. Build initial system quickly 3. Use bias/variance analysis and error analysis to prioritize next steps

  • Mismatched training and dev/set set
    • Training and testing on different distributions
      • 猫分類器の例、Data from webpagesが200000枚、Data from mobile app(より実環境に近いデータ)が10000枚のとき
        • Option 1: 2つのデータを合わせてシャッフルし、train dev/testに分ける
          • メリット: train, dev/test set from the same distribution
          • デメリット: dev setの多くがwebpage由来
          • So remember that setting up your dev set is telling yout team where to aim the target. And the way you're aiming your target, you're saying spend most of the time optimizing for the web page distribution of images, which is really not what you want.

        • Option 2: trainはweb 200000 + app 5000、devはapp 2500、testはapp 2500
          • こちらのほうがOption 1より推奨される
          • You're telling your team, my dev set has data uploaded from the mobile app and that's the distribution of images you really care about, so let's try to build a ML system that does really well on the mobile app distribution of images.

    • Bias and variance with mismatched data distributions
      • 猫分類器の例、人が分類すると凡そ0%のerr、学習時のerrは1%、devに対するerrが10%のとき、これはvariance problem?
      • 可能性として、training and dev data comes from a different distributions
      • this just refrects that the dev set contains images that are much more difficult to classify accurately.

      • 対策、もう一つデータセットを準備: Training-dev set, same distribution as training set, but not used for training.
      • 再度比較してみたとき、human: 0%, training err: 1%, training-dev err: 9%, dev err: 10%だったらvariance problem
      • 再度比較してみたとき、human: 0%, training err: 1%, training-dev err: 1.5%, dev err: 10%だったらdata mismatch problem
      • 再度比較してみたとき、human: 0%, training err: 10%, training-dev err: 11%, dev err: 12%だったらavoidable bias problem
      • 再度比較してみたとき、human: 0%, training err: 10%, training-dev err: 11%, dev err: 20%だったらavoidable bias problem + data mismatch
      • まとめ
        • Human level <-> Training set err: avoidable bias
        • Training set err <-> Training-dev set err: variance
        • Training-dev set err <-> Dev set err: data mismatch
        • Dev set err <-> Test set err: degree of overfitting to the dev set
      • より一般的なタスクに対する分類器と比較してみるのも一手
        • 例えば車のReaview mirrror speech recognitionを開発している時に、General speech recognitionの分類器と上記四つの尺度で比較してみる
    • Adressing data mismatch
      • Carrying out manual error analysis to try to understand difference between training and dev/test sets.
      • Make training data more similar; or collect more data similar to dev/test sets.
      • データをaugumentするのは手の一つだが、合成データにoverfitしてしまう危険性は含まれている
  • Learning from multiple tasks
    • Transfer learning
      • One of the most powerful ideas in DL is that sometimes you can take knowledge the NN has learned from one task and apply that knowledge to a separate task.

      • pre-trainingとfine-tuning
      • So, when does transfer learning make sense? Transfer learning makes sense when you have a lot of data for the problem you're transfering from and usually relatively less data for the problem you're transfering to. * Task A and B have the same input x. * You have a lot more data for Task A than Task B. * Low level features from A could be helpful for learning B.

    • Multi task learning
      • 例として、写真に車、標識、信号機、...が写っているか検知したい
      • 出力層に検知したいオブジェクトの数だけ(例えば4)ユニットを並べる
      • 損失関数: \sum{i=1}^m \sum{j=4} L(\hat{y}_ji, y_ji)
        • Lは通常のlogistic loss
        • unlike softmax one image can have multiple labels

      • If some of the earlier features in NN can be shared between these different types of objects, then you find that training one NN to do four things results in better performance thant training four completely separate NN to do the four tasks separately.

      • When multi-task learning makes sense? * > Training on a set of tasks that could benefit from having shared lower-level features. * > Usually amount of data you have for each task is quite similar. * > Can train a big enough NN to do well on all the tasks.

      • Multi-task learning enables you to train one NN to do many tasks and this can give you better performance than if you were to do the tasks in isolation.

  • End-to-end deep learning
    • Briefly, there have been some data processing systems or learning systems that require multiple stages of processing, and what E2E DL dose, is it can take all those multiple stages and replae it usually with just a single NN.

    • Pros and cons of E2E DL
      • Pros:
        • Let the data speak
          • (音声認識器の音素(phoneme)を例にとって) I think that phonemes are an artifact created by human linguist. And if you let your learning algorithm whatever representation it wants to learn rather than forcing your learning algorithm to use phonemes as a representation, then its overall performance might end up being better.

        • Less hand-designing of components needed
      • Cons:
        • May need large amount of data.
        • Excludes potentially useful hand-designed components.
          • When you have a ton of data it's less important to hand design things. But when you don't have much data, then having a carefully hand-designed system can actually allow humans to inject a lot of knowledge about the problem into an algorithm deck and that should be very helpful.

    • Key question: Do you have sufficient data to learn a function of the complexity needed to map x to y?
Case Study

自動運転を例に取ったクイズ