Building a high-performance, scalable ML & NLP platform with Python, Sheer El Showk

Pôle Systematic Paris-Region
Pôle Systematic Paris-RegionPôle Systematic Paris-Region
Building a high-performance, scalable
ML & NLP platform with Python
Sheer El Showk
CTO, Lore Ai
www.lore.ai
Lore is a small startup focused on developing and applying
machine-learning techniques to solve a wide array of business
problems.
We are product-focused but we also provide consulting services
(because building and selling products is hard!)
We are self-funded so we need to be cost-effective but also flexible and scalable.
- Need to be ready to pivot if product is not working
- Need to support both consulting work and product development
Over time developed a complex but modular stack:
- ML & NLP tools/services
- Standard web-stack: DB, caching, API servers, web servers
- Fully scalable (all components can be parallelized)
This has allowed us to develop & maintain several products:
- A chatbot
- A content-based recommender engine
- Our flagship product, Salient, a powerful document analysis engine
The Task
Client Data
Convert &
Parse
ML/NLP Services
-Question-Answering
-Document Similarity
-Information extraction
NLP Processing
Annotated
Documents
Entity Linking
Client
Knowledge Graph
Upload Docs
ETL
Web/API
Servers
Client
NLP Pipeline
-Grammar parsing
-Parts-of-speech
-Entities (people,etc..)
Knowledge Graph
Applications
● Contract Management: automate labelling database of contracts (PDFs, word, OCR)
○ Contract type, expiration date, other parties, important clauses, etc..
● Analyze news
○ Build a database of product releases or funding rounds from press releases
○ Find companies fitting a profile -- competitors, acquisition, investors, etc..
● Patent and Policy Document Analysis
○ Build an ontology and network linking concepts and content
The Challenges
Lore’s stack has all the normal challenges of developing a
large web/business application in python.
The addition of ML/NLP brings additional challenges
whose solutions are less well known.
Scalability
● Some use cases require processing millions of documents
○ E.g. we have a news DB with 4 million articles in it
● Python considered “slow” and not scalable (hard to parallelize)
○ Java preferred language of enterprise
● ML brings new problems:
○ Need models to be very performant
○ Parallelizing harder: need to share models/data between servers
Maintainability
● Mixing many different technologies
○ ML/compute stack: theano, gensim, spaCy, etc..
○ Web stack: django, celery, mysql, etc..
● Multiple servers/services can mean expensive/difficult devops.
● Large code base with different kinds of code (JS/web vs ML/NLP) make it hard to
coordinate between developers.
Flexibility
● Business requirements change very quickly
○ Need to provide a wide range of services from same platform
○ Need to be able to easily upgrade/improve parts of system
● Agility often requires integrating existing off-the-shelf solutions to solve non-core tasks.
● Easy to deploy or scale a deployment.
Where we Started
Where we started...
➔ Monolithic python-based server + PHP UI
➔ MySQL DB backend
➔ Hard coded dependence on target document set.
➔ Basic off-the-shelf NLP tools
◆ NLTK, etc..
➔ Serial pipeline
➔ No redundancy or scalability
➔ Hard to install/maintain (all manual)
A few pivots and consulting gigs later...
The new stack...
Mongo
Cluster
MySQL
(soon
ElasticSearch)
Minio
(distributed blob
storage)
Input
Processor
Service
Broker
Load
Balancer
NLP
Services
Django
Web
Web
scrapers
Pipeline
Logging
Cron-jobs
KG
Service
Entity
Generator
➔ Kubernetes & docker for devops
➔ Celery for parallelization
➔ Micro-services Architecure
➔ In-house NLP engine
➔ Distributed data stores:
◆ Mongo, Minio, Redis
➔ Very modular, re-usable
➔ Rapid deployment (even cluster)
Django
API
Celery Workers
Redis
(distributed
caching)
What we learned along the
way...
Lessons
● Devops: kubernetes, docker, docker-compose
● Parallelization: celery, dask, joblib,...
● Modularity: (stateless) microservices architecture
● Persistence: scalable distributed caching/persistence (redis, mongo, ES,...)
● Future-proofing: wrapper patterns
● Performance: cython or pythran for bottleneck code
Docker & Kubernetes
Dockerize early, dockerize often
1. Uniform environment between devs
a. Use ipython to develop in stack
2. Easy to add services
a. Solve dev problems using devops!
3. Fast, consistent deploy to production
a. Deploying our stack is rate-limited by
download speed :-)
4. Cut costs by running on bare metal
a. Run your own “AWS” with k8ns
type
AWS
(reserved)
Hetzner
(bare metal)
16 threads
64 gb ram
$360/mo
(no storage)
$70/mo
(1tb ssd)
GPU server
$450/mo
(K80)
$120/mo
(1080)
Celery for Parallelization
10 minute parallelization
● Many interesting options for parallelization:
○ Dask.distributed, joblib, celery, ipython
● Celery “complicated” -- requires Redis/RabbitMQ, etc..
○ Very easy with docker/kubernetes
○ NOTE: Redis has much lower latency
● Transparent parallelization
○ Wrap “entry-point” functions in a task and Bob’s your uncle.
● Lots of fancy features but don’t need to use them until you need them.
Stateless Microservices
Unlimited Scalability and Flexibility
● High level analog of an Abstract Base Class
● Split codebase into independent microservices
○ Each microservices handles one kind of thing: NLP, logging, DB persistence, etc…
○ Wrap underlying service abstractly: redis→ kv_cache, minio → kv_store, mysql → sql_db
● Applications can include multiple microservices talking to each other
● Microservices should be stateless
○ All state (caching, persistence, etc..) should be handled by external services (DB, redis, etc..)
● Microservices encapsulate underlying implementation of a service
● Microservices are not micro-servers: services are just APIs within an API.
○ Should not be tied to an interface (REST, JSON, etc..)
NLP ServiceNLP Service
Distributed Persistence
Let others do the hard work
● All persistence handled by “layers” of persistence
services.
○ Layering helps performance
● Persistent services accessed via “wrappers” (see next
slide) for easy replacement.
● “State” of services managed by distributed cache
○ ML models can be shared by workers using e.g. Redis
(caching) and Minio (persistence)
● Different types of persistence for different problems:
○ Mongo stores JSON, Minio stores blobs, mysql stores
tables
Minio
(distributed blob
storage)
Redis
(distributed
caching)
cache
save
Neural
network
NLP Service
create/
train
Design Patterns
Wrapper Pattern
● Wrap access to all external services (db,
logging, etc..)
● Easy to swap in new versions
○ MySQL vs Postgres, etc.
● Easily add logging, performance, etc..
● Insert custom logic to modify the behavior, eg
○ Manually shard/replicate DBs
○ Add new logging destinations
● This pattern has saved us countless hours of
refactoring!
Examples
● Local → Centralized logging & config with just
a few lines of code.
● Migrating from NLTK to better (in-house) NLP
● Restricting user access to DB by transparently
replacing tables with views.
Performance
● Use native types correctly:
○ set vs list, iteritems vs items
● Pythonic code is almost always faster.
● Use %timeit to test code snippets everywhere
● Beware of hidden memory allocation
● For critical bottlenecks use:
○ Pythran (very easy but limited coverage)
○ Cython (harder, but more flexible)
● For ML use generators to stream data from
disk/db (see gensim).
● Know your times
Performance (II)
Example
Classifying (short) documents
● Initial rate: 2k docs/sec
● Initial Profiling:
○ Db read rate: 250k docs/s
○ Feature generation 2k docs/s
○ Classification 10k docs/s
● Feature generation involves for-loops &
complex logic.
Fixes
● Refactored feature generation:
○ Extract features in list comprehensions
○ Convert to vectors in Pythran code
● New times
○ Python part: 10k docs/s
○ Pythran: 40k docs/s
● Fix memory allocation in classifier: 50k docs/s
● New times: ~10k docs/s
● Going forward: cache features in Mongo?
Further Reading...
● Radim Řehůřek (gensim):
“Does Python Stand a Chance in Today’s World of Data Science”
(https://youtu.be/jfbgt3KjWFQ)
● High Performance Python (O’Reilly)
○ “Lessons from the Field” (chapter 12)
● Fluent Python (O’Reilly)
● Latency Numbers Every Programmer Should Know
https://gist.github.com/jboner/2841832
Bye!
Open Problems
● Cores vs RAM
○ Many models require lots of RAM (models can be Gbs in size).
○ Models read-only but because of python GIL hard to share memory between “processes/threads”
○ Use “sharedmem” module?
● Generating models from terabytes of data?
○ “Embedding models” can capture interesting information from huge amounts of data
○ Train very quickly (millions words/sec per server)
○ How can we distribute parameters/data between large number of workers?
1 of 27

Recommended

From Python to smartphones: neural nets @ Saint-Gobain, François Sausset by
From Python to smartphones: neural nets @ Saint-Gobain, François SaussetFrom Python to smartphones: neural nets @ Saint-Gobain, François Sausset
From Python to smartphones: neural nets @ Saint-Gobain, François SaussetPôle Systematic Paris-Region
404 views7 slides
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and... by
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Pôle Systematic Paris-Region
2.3K views57 slides
Designing and coding for cloud-native applications using Python, Harjinder Mi... by
Designing and coding for cloud-native applications using Python, Harjinder Mi...Designing and coding for cloud-native applications using Python, Harjinder Mi...
Designing and coding for cloud-native applications using Python, Harjinder Mi...Pôle Systematic Paris-Region
653 views33 slides
Is Python still production ready ? Ludovic Gasc by
Is Python still production ready ? Ludovic GascIs Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic GascPôle Systematic Paris-Region
649 views68 slides
Ways to generate PDF from Python Web applications, Gaël Le Mignot by
Ways to generate PDF from Python Web applications, Gaël Le MignotWays to generate PDF from Python Web applications, Gaël Le Mignot
Ways to generate PDF from Python Web applications, Gaël Le MignotPôle Systematic Paris-Region
1.7K views21 slides
GPU Computing for Data Science by
GPU Computing for Data Science GPU Computing for Data Science
GPU Computing for Data Science Domino Data Lab
33.5K views34 slides

More Related Content

What's hot

Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011) by
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Fabrice Bernhard
3.8K views52 slides
SciPipe - A light-weight workflow library inspired by flow-based programming by
SciPipe - A light-weight workflow library inspired by flow-based programmingSciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programmingSamuel Lampa
1.4K views14 slides
Pulumi. Modern Infrastructure as Code. by
Pulumi. Modern Infrastructure as Code.Pulumi. Modern Infrastructure as Code.
Pulumi. Modern Infrastructure as Code.Yurii Bychenok
692 views16 slides
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)? by
Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)?Jonas Hecht
1.8K views65 slides
Are you using an opensource library? There's a good chance you are vulnerable... by
Are you using an opensource library? There's a good chance you are vulnerable...Are you using an opensource library? There's a good chance you are vulnerable...
Are you using an opensource library? There's a good chance you are vulnerable...Codemotion
73 views20 slides
Deep Learning with GPUs in Production - AI By the Bay by
Deep Learning with GPUs in Production - AI By the BayDeep Learning with GPUs in Production - AI By the Bay
Deep Learning with GPUs in Production - AI By the BayAdam Gibson
4.8K views15 slides

What's hot(20)

Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011) by Fabrice Bernhard
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Fabrice Bernhard3.8K views
SciPipe - A light-weight workflow library inspired by flow-based programming by Samuel Lampa
SciPipe - A light-weight workflow library inspired by flow-based programmingSciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programming
Samuel Lampa1.4K views
Pulumi. Modern Infrastructure as Code. by Yurii Bychenok
Pulumi. Modern Infrastructure as Code.Pulumi. Modern Infrastructure as Code.
Pulumi. Modern Infrastructure as Code.
Yurii Bychenok692 views
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)? by Jonas Hecht
Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)?
Jonas Hecht1.8K views
Are you using an opensource library? There's a good chance you are vulnerable... by Codemotion
Are you using an opensource library? There's a good chance you are vulnerable...Are you using an opensource library? There's a good chance you are vulnerable...
Are you using an opensource library? There's a good chance you are vulnerable...
Codemotion73 views
Deep Learning with GPUs in Production - AI By the Bay by Adam Gibson
Deep Learning with GPUs in Production - AI By the BayDeep Learning with GPUs in Production - AI By the Bay
Deep Learning with GPUs in Production - AI By the Bay
Adam Gibson4.8K views
How to write a well-behaved Python command line application by gjcross
How to write a well-behaved Python command line applicationHow to write a well-behaved Python command line application
How to write a well-behaved Python command line application
gjcross16.1K views
C++ on the Web: Run your big 3D game in the browser by Andre Weissflog
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browser
Andre Weissflog49.7K views
Introduction to go, and why it's awesome by Janet Kuo
Introduction to go, and why it's awesomeIntroduction to go, and why it's awesome
Introduction to go, and why it's awesome
Janet Kuo2.6K views
How to rewrite the OS using C by strong type by Kiwamu Okabe
How to rewrite the OS using C by strong typeHow to rewrite the OS using C by strong type
How to rewrite the OS using C by strong type
Kiwamu Okabe3K views
Minko - Build WebGL applications with C++ and asm.js by Minko3D
Minko - Build WebGL applications with C++ and asm.jsMinko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.js
Minko3D8.8K views
Multiplatform C++ on the Web with Emscripten by Chad Austin
Multiplatform C++ on the Web with EmscriptenMultiplatform C++ on the Web with Emscripten
Multiplatform C++ on the Web with Emscripten
Chad Austin21.4K views
20151117 IoT를 위한 서비스 구성과 개발 by 영욱 김
20151117 IoT를 위한 서비스 구성과 개발20151117 IoT를 위한 서비스 구성과 개발
20151117 IoT를 위한 서비스 구성과 개발
영욱 김1.1K views
AddisDev Meetup ii: Golang and Flow-based Programming by Samuel Lampa
AddisDev Meetup ii: Golang and Flow-based ProgrammingAddisDev Meetup ii: Golang and Flow-based Programming
AddisDev Meetup ii: Golang and Flow-based Programming
Samuel Lampa5.1K views
Infrastructure as (real) Code – Manage your K8s resources with Pulumi by inovex GmbH
Infrastructure as (real) Code – Manage your K8s resources with PulumiInfrastructure as (real) Code – Manage your K8s resources with Pulumi
Infrastructure as (real) Code – Manage your K8s resources with Pulumi
inovex GmbH280 views
.NET Core Blimey! Windows Platform User Group, Manchester by citizenmatt
.NET Core Blimey! Windows Platform User Group, Manchester.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt550 views

Similar to Building a high-performance, scalable ML & NLP platform with Python, Sheer El Showk

AirBNB's ML platform - BigHead by
AirBNB's ML platform - BigHeadAirBNB's ML platform - BigHead
AirBNB's ML platform - BigHeadKarthik Murugesan
1K views54 slides
Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa... by
 Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa... Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa...
Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa...Databricks
35.3K views54 slides
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka by
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka PyCon HK 2018 - Heterogeneous job processing with Apache Kafka
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka Hua Chu
2.3K views36 slides
Scaling symfony apps by
Scaling symfony appsScaling symfony apps
Scaling symfony appsMatteo Moretti
4.5K views83 slides
Scala Days Highlights | BoldRadius by
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusBoldRadius Solutions
1.2K views46 slides
Netflix Open Source Meetup Season 4 Episode 2 by
Netflix Open Source Meetup Season 4 Episode 2Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2aspyker
19.4K views77 slides

Similar to Building a high-performance, scalable ML & NLP platform with Python, Sheer El Showk(20)

Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa... by Databricks
 Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa... Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa...
Bighead: Airbnb’s End-to-End Machine Learning Platform with Krishna Puttaswa...
Databricks35.3K views
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka by Hua Chu
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka PyCon HK 2018 - Heterogeneous job processing with Apache Kafka
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka
Hua Chu2.3K views
Netflix Open Source Meetup Season 4 Episode 2 by aspyker
Netflix Open Source Meetup Season 4 Episode 2Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2
aspyker19.4K views
ML Platform Q1 Meetup: Airbnb's End-to-End Machine Learning Infrastructure by Fei Chen
ML Platform Q1 Meetup: Airbnb's End-to-End Machine Learning InfrastructureML Platform Q1 Meetup: Airbnb's End-to-End Machine Learning Infrastructure
ML Platform Q1 Meetup: Airbnb's End-to-End Machine Learning Infrastructure
Fei Chen3.9K views
Instant developer onboarding with self contained repositories by Yshay Yaacobi
Instant developer onboarding with self contained repositoriesInstant developer onboarding with self contained repositories
Instant developer onboarding with self contained repositories
Yshay Yaacobi157 views
[WSO2Con EU 2018] Architecting for a Container Native Environment by WSO2
[WSO2Con EU 2018] Architecting for a Container Native Environment[WSO2Con EU 2018] Architecting for a Container Native Environment
[WSO2Con EU 2018] Architecting for a Container Native Environment
WSO2185 views
2016_04_04_CNI_Spring_Meeting_Microservices by Jason Varghese
2016_04_04_CNI_Spring_Meeting_Microservices2016_04_04_CNI_Spring_Meeting_Microservices
2016_04_04_CNI_Spring_Meeting_Microservices
Jason Varghese462 views
Commit Conf 2018 - Hotelbeds' journey to a microservice cloud-based architecture by Jordi Puigsegur Figueras
Commit Conf 2018 - Hotelbeds' journey to a microservice cloud-based architectureCommit Conf 2018 - Hotelbeds' journey to a microservice cloud-based architecture
Commit Conf 2018 - Hotelbeds' journey to a microservice cloud-based architecture
Big Data in 200 km/h | AWS Big Data Demystified #1.3 by Omid Vahdaty
Big Data in 200 km/h | AWS Big Data Demystified #1.3  Big Data in 200 km/h | AWS Big Data Demystified #1.3
Big Data in 200 km/h | AWS Big Data Demystified #1.3
Omid Vahdaty473 views
Mongo db transcript by foliba
Mongo db transcriptMongo db transcript
Mongo db transcript
foliba698 views
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story by vanphp
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
vanphp6K views
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English by Omid Vahdaty
AWS big-data-demystified #1.1  | Big Data Architecture Lessons Learned | EnglishAWS big-data-demystified #1.1  | Big Data Architecture Lessons Learned | English
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
Omid Vahdaty1.1K views
AWS Big Data Demystified #1: Big data architecture lessons learned by Omid Vahdaty
AWS Big Data Demystified #1: Big data architecture lessons learned AWS Big Data Demystified #1: Big data architecture lessons learned
AWS Big Data Demystified #1: Big data architecture lessons learned
Omid Vahdaty1.7K views
Not my problem - Delegating responsibility to infrastructure by Yshay Yaacobi
Not my problem - Delegating responsibility to infrastructureNot my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructure
Yshay Yaacobi563 views

More from Pôle Systematic Paris-Region

OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na... by
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...Pôle Systematic Paris-Region
686 views39 slides
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ... by
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...Pôle Systematic Paris-Region
293 views24 slides
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ... by
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...Pôle Systematic Paris-Region
349 views38 slides
OSIS19_Cloud : Performance and power management in virtualized data centers, ... by
OSIS19_Cloud : Performance and power management in virtualized data centers, ...OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...Pôle Systematic Paris-Region
288 views27 slides
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ... by
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...Pôle Systematic Paris-Region
271 views30 slides
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt... by
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...Pôle Systematic Paris-Region
229 views9 slides

More from Pôle Systematic Paris-Region(20)

Recently uploaded

20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
23 views73 slides
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTVSplunk
86 views20 slides
Throughput by
ThroughputThroughput
ThroughputMoisés Armani Ramírez
32 views11 slides
Report 2030 Digital Decade by
Report 2030 Digital DecadeReport 2030 Digital Decade
Report 2030 Digital DecadeMassimo Talia
13 views41 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
14 views13 slides
Data-centric AI and the convergence of data and model engineering: opportunit... by
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
29 views40 slides

Recently uploaded(20)

.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk86 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta14 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier29 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10165 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada110 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price12 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman25 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS31 views
.conf Go 2023 - Data analysis as a routine by Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk90 views

Building a high-performance, scalable ML & NLP platform with Python, Sheer El Showk

  • 1. Building a high-performance, scalable ML & NLP platform with Python Sheer El Showk CTO, Lore Ai www.lore.ai
  • 2. Lore is a small startup focused on developing and applying machine-learning techniques to solve a wide array of business problems. We are product-focused but we also provide consulting services (because building and selling products is hard!)
  • 3. We are self-funded so we need to be cost-effective but also flexible and scalable. - Need to be ready to pivot if product is not working - Need to support both consulting work and product development Over time developed a complex but modular stack: - ML & NLP tools/services - Standard web-stack: DB, caching, API servers, web servers - Fully scalable (all components can be parallelized) This has allowed us to develop & maintain several products: - A chatbot - A content-based recommender engine - Our flagship product, Salient, a powerful document analysis engine
  • 5. Client Data Convert & Parse ML/NLP Services -Question-Answering -Document Similarity -Information extraction NLP Processing Annotated Documents Entity Linking Client Knowledge Graph Upload Docs ETL Web/API Servers Client NLP Pipeline -Grammar parsing -Parts-of-speech -Entities (people,etc..) Knowledge Graph
  • 6. Applications ● Contract Management: automate labelling database of contracts (PDFs, word, OCR) ○ Contract type, expiration date, other parties, important clauses, etc.. ● Analyze news ○ Build a database of product releases or funding rounds from press releases ○ Find companies fitting a profile -- competitors, acquisition, investors, etc.. ● Patent and Policy Document Analysis ○ Build an ontology and network linking concepts and content
  • 8. Lore’s stack has all the normal challenges of developing a large web/business application in python. The addition of ML/NLP brings additional challenges whose solutions are less well known.
  • 9. Scalability ● Some use cases require processing millions of documents ○ E.g. we have a news DB with 4 million articles in it ● Python considered “slow” and not scalable (hard to parallelize) ○ Java preferred language of enterprise ● ML brings new problems: ○ Need models to be very performant ○ Parallelizing harder: need to share models/data between servers
  • 10. Maintainability ● Mixing many different technologies ○ ML/compute stack: theano, gensim, spaCy, etc.. ○ Web stack: django, celery, mysql, etc.. ● Multiple servers/services can mean expensive/difficult devops. ● Large code base with different kinds of code (JS/web vs ML/NLP) make it hard to coordinate between developers.
  • 11. Flexibility ● Business requirements change very quickly ○ Need to provide a wide range of services from same platform ○ Need to be able to easily upgrade/improve parts of system ● Agility often requires integrating existing off-the-shelf solutions to solve non-core tasks. ● Easy to deploy or scale a deployment.
  • 13. Where we started... ➔ Monolithic python-based server + PHP UI ➔ MySQL DB backend ➔ Hard coded dependence on target document set. ➔ Basic off-the-shelf NLP tools ◆ NLTK, etc.. ➔ Serial pipeline ➔ No redundancy or scalability ➔ Hard to install/maintain (all manual)
  • 14. A few pivots and consulting gigs later...
  • 15. The new stack... Mongo Cluster MySQL (soon ElasticSearch) Minio (distributed blob storage) Input Processor Service Broker Load Balancer NLP Services Django Web Web scrapers Pipeline Logging Cron-jobs KG Service Entity Generator ➔ Kubernetes & docker for devops ➔ Celery for parallelization ➔ Micro-services Architecure ➔ In-house NLP engine ➔ Distributed data stores: ◆ Mongo, Minio, Redis ➔ Very modular, re-usable ➔ Rapid deployment (even cluster) Django API Celery Workers Redis (distributed caching)
  • 16. What we learned along the way...
  • 17. Lessons ● Devops: kubernetes, docker, docker-compose ● Parallelization: celery, dask, joblib,... ● Modularity: (stateless) microservices architecture ● Persistence: scalable distributed caching/persistence (redis, mongo, ES,...) ● Future-proofing: wrapper patterns ● Performance: cython or pythran for bottleneck code
  • 18. Docker & Kubernetes Dockerize early, dockerize often 1. Uniform environment between devs a. Use ipython to develop in stack 2. Easy to add services a. Solve dev problems using devops! 3. Fast, consistent deploy to production a. Deploying our stack is rate-limited by download speed :-) 4. Cut costs by running on bare metal a. Run your own “AWS” with k8ns type AWS (reserved) Hetzner (bare metal) 16 threads 64 gb ram $360/mo (no storage) $70/mo (1tb ssd) GPU server $450/mo (K80) $120/mo (1080)
  • 19. Celery for Parallelization 10 minute parallelization ● Many interesting options for parallelization: ○ Dask.distributed, joblib, celery, ipython ● Celery “complicated” -- requires Redis/RabbitMQ, etc.. ○ Very easy with docker/kubernetes ○ NOTE: Redis has much lower latency ● Transparent parallelization ○ Wrap “entry-point” functions in a task and Bob’s your uncle. ● Lots of fancy features but don’t need to use them until you need them.
  • 20. Stateless Microservices Unlimited Scalability and Flexibility ● High level analog of an Abstract Base Class ● Split codebase into independent microservices ○ Each microservices handles one kind of thing: NLP, logging, DB persistence, etc… ○ Wrap underlying service abstractly: redis→ kv_cache, minio → kv_store, mysql → sql_db ● Applications can include multiple microservices talking to each other ● Microservices should be stateless ○ All state (caching, persistence, etc..) should be handled by external services (DB, redis, etc..) ● Microservices encapsulate underlying implementation of a service ● Microservices are not micro-servers: services are just APIs within an API. ○ Should not be tied to an interface (REST, JSON, etc..)
  • 21. NLP ServiceNLP Service Distributed Persistence Let others do the hard work ● All persistence handled by “layers” of persistence services. ○ Layering helps performance ● Persistent services accessed via “wrappers” (see next slide) for easy replacement. ● “State” of services managed by distributed cache ○ ML models can be shared by workers using e.g. Redis (caching) and Minio (persistence) ● Different types of persistence for different problems: ○ Mongo stores JSON, Minio stores blobs, mysql stores tables Minio (distributed blob storage) Redis (distributed caching) cache save Neural network NLP Service create/ train
  • 22. Design Patterns Wrapper Pattern ● Wrap access to all external services (db, logging, etc..) ● Easy to swap in new versions ○ MySQL vs Postgres, etc. ● Easily add logging, performance, etc.. ● Insert custom logic to modify the behavior, eg ○ Manually shard/replicate DBs ○ Add new logging destinations ● This pattern has saved us countless hours of refactoring! Examples ● Local → Centralized logging & config with just a few lines of code. ● Migrating from NLTK to better (in-house) NLP ● Restricting user access to DB by transparently replacing tables with views.
  • 23. Performance ● Use native types correctly: ○ set vs list, iteritems vs items ● Pythonic code is almost always faster. ● Use %timeit to test code snippets everywhere ● Beware of hidden memory allocation ● For critical bottlenecks use: ○ Pythran (very easy but limited coverage) ○ Cython (harder, but more flexible) ● For ML use generators to stream data from disk/db (see gensim). ● Know your times
  • 24. Performance (II) Example Classifying (short) documents ● Initial rate: 2k docs/sec ● Initial Profiling: ○ Db read rate: 250k docs/s ○ Feature generation 2k docs/s ○ Classification 10k docs/s ● Feature generation involves for-loops & complex logic. Fixes ● Refactored feature generation: ○ Extract features in list comprehensions ○ Convert to vectors in Pythran code ● New times ○ Python part: 10k docs/s ○ Pythran: 40k docs/s ● Fix memory allocation in classifier: 50k docs/s ● New times: ~10k docs/s ● Going forward: cache features in Mongo?
  • 25. Further Reading... ● Radim Řehůřek (gensim): “Does Python Stand a Chance in Today’s World of Data Science” (https://youtu.be/jfbgt3KjWFQ) ● High Performance Python (O’Reilly) ○ “Lessons from the Field” (chapter 12) ● Fluent Python (O’Reilly) ● Latency Numbers Every Programmer Should Know https://gist.github.com/jboner/2841832
  • 26. Bye!
  • 27. Open Problems ● Cores vs RAM ○ Many models require lots of RAM (models can be Gbs in size). ○ Models read-only but because of python GIL hard to share memory between “processes/threads” ○ Use “sharedmem” module? ● Generating models from terabytes of data? ○ “Embedding models” can capture interesting information from huge amounts of data ○ Train very quickly (millions words/sec per server) ○ How can we distribute parameters/data between large number of workers?