Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Unit testしてますか?
Search
tsho
July 12, 2023
Programming
700
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Unit testしてますか?
2023/7/12 MLOps 勉強会 LT 発表
tsho
July 12, 2023
More Decks by tsho
See All by tsho
20260930_Gemma4_Hands-on
tsho
0
280
Benchmarking Vector Databases: pgvector vs. LanceDB
tsho
0
190
Google IO 2026で進化をとげた Google AI Studio
tsho
0
38
20260321_エンベディングってなに?RAGってなに?エンベディングの説明とGemini Embedding 2 の紹介
tsho
0
310
AI Agentにおける評価指標とAgent GPA
tsho
1
620
Scale SciPy with jax.shard_map - jax.shard_mapで SciPy をスケール
tsho
0
180
Developer Advocate / Community Managerなるには?
tsho
0
910
25/04/12 - Build with AI Hands-on Appendix
tsho
1
110
Other Decks in Programming
See All in Programming
sbt 2.0: takeoff
eed3si9n
0
180
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
270
パスワード再設定メールのURLについて知っておこう
uyuki234
0
200
Groovy as a human and AI friendly programming language
paulk
0
150
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
120
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.1k
AI Augmentation Techniques with Liberty
ivargrimstad
0
230
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.1k
Performance Optimization With LLMs
xleitix
0
230
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
180
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
3
1.3k
最近”作らせてる” ローカルAIアプリの話
akit37
0
530
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
720
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
240
The browser strikes back
jonoalderson
0
1.9k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
The Curse of the Amulet
leimatthew05
3
16k
Visualization
eitanlees
153
17k
First, design no harm
axbom
PRO
2
1.4k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
We Are The Robots
honzajavorek
0
420
sira's awesome portfolio website redesign presentation
elsirapls
0
480
Optimising Largest Contentful Paint
csswizardry
37
4k
Transcript
Unit testしてますか?
自己紹介 名前:tsho (Sho Tanaka) 都内の IT 会社で日本や APAC を中心に ML
のコンサル タントやソリューションを提供。MLOps 勉強会の運営の1 人。 本発表は所属する組織とは関係なく、 個人の見解と調べたことを発表いたします。
話すこと & 対象 初心者 中級者 上級者 データサイエンティスト ◯ ◯ ✕
MLエンジニア/ ソフトウェアエンジニア ◯ △ ✕ エンジニア中級者などは退屈かもしれません。 最近 Python で unittest 書き始めた人の簡単な紹介 (Rspec で test 書い たことあるマン) 最新の話とかではない古くからある話をします。
なんでこの話をするのか? テストの話が本勉強会で少ないな 懇親会とかで話していてテストの話を知らない人が意外といるかな と思ったから
ML Systemsにおけるテスト Figure 1. Elements for ML systems. Adapted from
Hidden Technical Debt in Machine Learning Systems. https://cloud.google.com/architecture/mlops-continuous-delivery-and-automation-pipelines-in-machine-learning
テストのおおまかな種類 継続的にモデルを作り、デプロイしてビジネスに使うためにもテストは必要 大まかなテストの種類 - 単体テスト(Unit test) - 結合テスト(統合テスト) - E2Eテスト
*テストの分け方は人や定義によって多少ことなることが多いです。今回は分け方の議論はしないのでここでこれ以上の話はい たしません
単体テスト(Unit Test) クラスや関数などのプログラムの単位ごとにテストのこと ML systemでいうと - 前処理 - モデリング -
予測 など 上記部分で機能テストをすることに該当します。 テストの種類と技法 - Qiita
Python における Unit Test 標準 library に unittest が入っている -
Pytest など 3rd party の library もありますがここでは触れません。 • Test 用の Python ファイルを作る • Test の関数は ‘test_’ で始める 参考 https://docs.python.org/ja/3/library/unittest.html
〜 〜 実際の例(githubのコードより) 参考 https://github.com/google/gps_building_blocks/blob/master/py/gps_building_blocks/ml/preprocessing/vif_test.py
数ヶ月実施してみて 世間で言われているとおり導入コストは高い ただ、コードが増えていくにつれ、Unite testがあるときにありがたみを感じる(ないとつ らい....)。 テストするためにコードをまとめる癖がつくので可読性もあがる(気がしている)。
補足 同じデータでも必ずしもアウトプットが一致する場合でないケースがあります。 例:モデルの byte データが変わる etc. そういった場合は、mock などを使って、該当の関数、method が呼び出されたか確認 することもできます。
もちろんアウトプットの確認よりゆるいテストになるので、アウトプットの確認ができるなら されたほうがよいと思います。
さいごに MLに限らず、大規模なプロダクトや改善が多いプロダクトで品質を保証するためにUnit testは重要です。 しかし、実装コストは高いのですべての人に薦めるやり方ではありません。 もし興味があれば、すでにつかっているライブラリの単体テストに使えるメソッドなどを確 認して使うのをおすすめします(例、pandas や numpy などの assert
など)。
参考 第21回 MLOps 勉強会 普通のプロダクトのテストと機械学習を含んだプロダクトのテス トの違い Python pandas テストの書き方についてメモ -
c-bata web