I'm Feeling Lucky
Yogesh Haribhau Kulkarni
AI Advisor (Helping organizations in their AI journeys) | PhD (Geometric Modeling) | Tech Columnist (Marathi)
You don't have to be lucky anymore if you wish to have a precise search result.?
We all are familiar with keyword based search. It works well for structured data, like, if you want to know actors names from a particular movie, such information is typically stored against the movie name/id. Almost like a table. But nowadays, we have more and more data of various types, including unstructured data, and thus searches are different now, like, searching within videos, finding similar shapes, etc. That's Neural Search. E.g. it would let you search through YouTube videos describing the scene you remember, making it more flexible and convenient than traditional keyword-based Search.
Such neural search is being made available by Jina AI. It is a cloud-native, open source, cross/multi-modal, data type-agnostic neural search engine which offers anything-to-anything search, ie. Text-to-text, image-to-image, video-to-video, or whatever else you can feed it.
Concepts
Lets understand some basic concepts/components in Jina AI.?
Modality:
Jina AI ecosystem consists of:
Jina consists of following components:
We can understand these concepts better with an example.
Example
Let’s implement a simple Neural Search service to demonstrate searching a similar image, based on human perception (Source:[4]). Dataset used is `Totally-Looks-Like Dataset` (Source: [5]). Here are a couple of pairs out of 6016 image pairs.
Lets define a few Executors and then compose them into a sequential pipeline?called, Flow.
Executor to pre-process input images :
from docarray import Document, DocumentArra
from jina import Executor, Flow, requests
class PreprocImg(Executor):
??@requests
??async def foo(self, docs: DocumentArray, **kwargs):
????for d in docs:
??????(
????????d.load_uri_to_image_tensor(200, 200)?# load
????????.set_image_tensor_normalization()?# normalize color
????????.set_image_tensor_channel_axis(
??????????-1, 0
????????)?# switch color axis for the PyTorch model later
??????)
Executor to embed preprocessed images via Resnet.
领英推荐
class EmbedImg(Executor)
??def __init__(self, **kwargs):
????super().__init__(**kwargs)
????import torchvision
????self.model = torchvision.models.resnet50(pretrained=True)
??@requests
??async def foo(self, docs: DocumentArray, **kwargs):
????docs.embed(self.model):
Executor to perform matching:
class MatchImg(Executor)
??_da = DocumentArray()
??@requests(on='/index')
??async def index(self, docs: DocumentArray, **kwargs):
????self._da.extend(docs)
????docs.clear()?# clear content to save bandwidth
??@requests(on='/search')
??async def foo(self, docs: DocumentArray, **kwargs):
????docs.match(self._da, limit=9)
????del docs[...][:, ('embedding', 'tensor')]?# save bandwidth, not needed:
Use the Flow to connect all the Executors and use `plot` to visualize it.
f = Flow(port_expose=12345).add(uses=PreprocImg).add(uses=EmbedImg, replicas=3).add(uses=MatchImg
f.plot('flow.svg'))
Get the data, download image dataset and pass them to the Flow defined above:
index_data = DocumentArray.pull('demo-leftda', show_progress=True)
Using Flow `f` index the documents
with f
??f.post(
????'/index',
????index_data,
????show_progress=True,
????request_size=8,
??)
??f.block():
Search-able data and corresponding service is ready now. Use a Python client to access the service.
from jina import Clien
c = Client(port=12345)?# connect to localhost:12345
print(c.post('/search', index_data[0])['@m'])?# '@m' is the matches-selectort
To access the service on a web browser, we can use this URL: `https://0.0.0.0:12345/docs`.
Straight-forward, isn't it?
More code-level examples can be seen at github.
Fascinating!!
Conclusion
Humans think multi-modal. We have description, visuals, sound (and may be, smell and taste also) etc in our minds while looking for something specific. Can AI (Artificial Intelligence) be as effectives as humans? As more and more data-types get merged like demonstrated above, though for a narrow task of `search`, we are getting more closer to Human Intelligence, ie towards AGI (Artificial General Intelligence), isn't it?
Give Jina AI a try and feel free to share your comments...
References
Senior Product Marketing Manager
2 年Thank you for taking the time to create such an insightful and well-crafted article. Your efforts are greatly appreciated.
Enterprise AI | ex-McKinsey, Microsoft | entrepreneur, CEO, investor
2 年Fady El-Rukby
Driving Customer Value | Supply Chain Management | Transforming Businesses | Contract Lifecycle Management
2 年Fantastic Yogesh Sir. Lucid explanation of the concept. Love to read your articles.