Talk given by Dr. Han Xiao at LF OSS EU 2019 Summit (LF AI track). GNES source code is available at https://github.com/gnes-ai/gnes/ More information can be found in Han's blog: https://hanxiao.github.io
4. hxiao87 hanxiao @hxiao
GNES is Generic Neural Elastic Search
4
GNES [jee-nes] is a cloud-native semantic search system based on deep neural networks.
GNES enables large-scale index and semantic search for text-to-text, image-to-image,
video-to-video and any-to-any content form.
Cloud-Native
Semantic Search based
on DNN
End2End Generic
Solution
9. hxiao87 hanxiao @hxiao
Preliminaries: Neural, Elastic, and Search
9
Find semantic similar text in large database
■ Microservices are a software development technique—a variant of the
service-oriented architecture (SOA) architectural style that structures an
application as a collection of loosely coupled services.
■ Microservices - also known as the microservice architecture - is an architectural
style that structures an application as a collection of services that are.
■ Microservices architecture is a term used to describe the practice of breaking up
an application into a series of smaller, more specialised parts, each of which
communicate with one another across common interfaces such as APIs and REST
interfaces like HTTP.
10. hxiao87 hanxiao @hxiao
Preliminaries: Neural, Elastic, and Search
10
Find semantic similar text in a large database
How to quantize the semantics?
Does it work on super-long
/short document as well?
How to define similarity?
How to store the semantics?
Vector representation of the doc
Vector indexing, e.g. Faiss
Distance metrics (L2, Hamming, etc)
Segment long document into sentences
State-of-the-art NLP model
Faster, lighter and
distributed database
Domain/app-specific
preprocessing
11. hxiao87 hanxiao @hxiao
Preliminaries: Neural, Elastic, and Search
11
Find semantic similar text, image, video in a large database
How to quantize the semantics?
Does it work on large/small
image, long/short video as
well?
How to define similarity?
How to store the semantics?
Vector representation of the image/video
Vector indexing, e.g. Faiss
Distance metrics (L2, Hamming, etc)
Segment image/video into patches
State-of-the-art CV model
Faster, lighter and
distributed database
Domain/app-specific
preprocessing
12. hxiao87 hanxiao @hxiao
Preliminaries: Neural, Elastic, and Search
12
Find semantic similar text, image, video in a large database
How to quantize the semantics?
Does it work on large/small
image, long/short video as
well?
How to define similarity?
How to store the semantics?
Vector representation of the doc
Vector indexing, e.g. Faiss
Distance metrics (L2, Hamming, etc)
Segment image/video into patches
State-of-the-art CV model
Faster, lighter and
distributed database
Domain/app-specific
preprocessing
Encoder
Indexer
Preprocessor
13. A good neural search is only possible
when document and query are comparable semantic units.
17. hxiao87 hanxiao @hxiao
Runtime in GNES
17
Typical ML system
Typical search system
GNES
Train Inference
QueryIndex
Train Index Query
Train-time is not for everyone. Most users will just use our
pretrained model from GNES Hub.
Train
Runtime
20. hxiao87 hanxiao @hxiao
Four fundamental microservices
To summarize, we have four fundamental components in GNES:
- Preprocessor: transforming a real-world object to a list of workable semantic units, aka
chunk;
- Encoder: representing chunks with vector representation;
- Indexer: storing the vectors into memory/disk that allows fast-access;
- Router: forwarding messages between microservices: e.g. batching, mapping, reducing
20
Train Index Query
21. Which (microservice) does what (logic) at when (runtime)
Understanding how GNES works is basically to know
and design the corresponding workflow
24. hxiao87 hanxiao @hxiao 24
Highlights
Cloud-native: GNES is all-in-microservice: encoder, indexer, preprocessor and router are all
running statelessly and independently in their own containers. Scaling, load-balancing, automated
recovering, they come off-the-shelf in GNES.
Encoder IndexerPreprocessor
Monolith: everything coupled in one process Encoder
Indexer
Preprocessor
GNES microservice architecture
30. hxiao87 hanxiao @hxiao
With vs. Without Code/Model Separation
30
Change on model
Encoder
Update encoder.py Rebuild the project
into package
Online
Deploy the new package
Change on model
Encoder
YAML
Update YAML
Online
Old version
Offline the old version
Serve users
Rollout and serve users
✓ Immutable codebase
✓ Minimum rollout time
✓ Version-controlled model
✓ Ease AB test, side-by-side
comparison
32. hxiao87 hanxiao @hxiao
Challenges to AI OSS maintainers
32
What is the most sustainable way to incorporate latest NLP/CV/AI model into a framework?
As the developer of bert-as-service (one of the most popular AI OSS in 2018), I was often asked
by the community
“Han, can you support model X and make it X-as-a-service?”
33. hxiao87 hanxiao @hxiao
Challenges to AI OSS maintainers
Popular design philosophy of an AI framework:
- Rewrite the code and claim it better than the original one
- Wrap the code (e.g. C-> Python) and provide better interface
33
bert-as-service
34. hxiao87 hanxiao @hxiao
Not sustainable because you can't match the speed of AI
34
AI development nowadays
You as a OSS maintainer
35. hxiao87 hanxiao @hxiao
Not sustainable because you can't handle the dependencies
- dependencies: packages or libraries required to run the algorithm,
e.g. ffmpeg, libcuda, tensorflow;
- codes: the implementation of the logic, can be written in Python, C,
Java, Scala with the help of Tensorflow, Pytorch, etc;
- a small config file: the arguments abstracted from the logic for
better flexibility during training and inference. For example,
batch_size, index_strategy, and model_path;
- big data files: the serialization of the model structure the learned
parameters, e.g. a pretrained VGG/BERT model.
35
Four pieces required to
run an AI model
42. Demo: Build a Poem Semantic Search
https://github.com/gnes-ai/demo-poems-ir
42
43. hxiao87 hanxiao @hxiao
Demo: Build a Poem Semantic Search
43
Steps:
1. Define the workflow
a. What microserivces do I need
b. How should they connect with each other
2. Specify each microservice
a. Yaml config
b. additional python files/ Dockerfile
Preprocessor EncoderVector-Indexer Doc-IndexerRouter
Encoder
45. hxiao87 hanxiao @hxiao
Specify each component
All microservice start with a base image: gnes/gnes:latest-alpine
Encoder design:
- use Pytorch-transformer
- need GPU and cuda support
- need to download pretrained model in advance
- config the encoder and pooling strategy
45
56. hxiao87 hanxiao @hxiao
GNES Flow to GNES is Keras to Tensorflow
56
Motivation
- a readable and brief idiom to define pipelines: index, query, train, etc.
- make GNES easier to debug locally
57. hxiao87 hanxiao @hxiao
GNES Flow highlights
- chain multiple add() functions to build a pipeline;
- use self-defined names instead of ports to a service;
- modify a pipeline’s component via set();
- run a pipeline on multiple orchestration layers, e.g. multi-thread, multi-process,
Docker Swarm, Kubernetes;
- serialize/deserialize a pipeline to/from a binary file, a SVG image, Docker
Swarm/Kubernetes config files.
57
61. hxiao87 hanxiao @hxiao
Use the index flow
with flow.build(backend='process') as f:
f.index(txt_file='poems.txt', batch_size=20)
with flow.build(backend='swarm') as f:
f.index(bytes_gen=read_flowers(), batch_size=64)
61
66. 66
GNES is …
- Cloud-native, all-in-microservice
- Generic semantic search solution
using DNN
- Elastic workflow optimized and
tailored for search scenarios
- A different mindset for building
sustainable AI OSS
- Grow with the community
GNES is NOT ...
- Yet another collection of AI
algorithms
- a generic framework for doing every
ML task (e.g. clustering)
68. hxiao87 hanxiao @hxiao
GNES resources
68
Version: v0.0.46
Github: https://github.com/gnes-ai/gnes
5 direct contributors from Tencent
2 community contributors
Homepage: https://gnes.ai
Docs: https://doc.gnes.ai
PyPI: https://pypi.org/project/gnes
Docker Hub: https://cloud.docker.com/u/gnes/repository/docker/gnes/gnes
GNES Board: https://board.gnes.ai
Blog: https://hanxiao.github.io
Call for more contributors!
69. hxiao87 hanxiao @hxiao
My other opensource projects
69
263 6736 1407
Fashion-MNIST
Most popular AI open-source project of 2017 (0.3% chance)
Google Scholar > 1300 publications
165 5808 1174
bert-as-service
Most popular AI open-source project of 2018 (0.22% chance)