<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          11k Star!登上 Github 熱榜前三的神經(jīng)搜索框架!

          共 4974字,需瀏覽 10分鐘

           ·

          2021-09-28 11:27

          【導語】:云原生的神經(jīng)搜索框架。

          簡介

          Jina 是一個神經(jīng)搜索框架,簡單快速,可以在幾分鐘內(nèi)構(gòu)建 SOTA 和可擴展的深度學習搜索應用程序。

          • 支持幾乎所有的數(shù)據(jù)類型-支持對任何類型的非結(jié)構(gòu)化數(shù)據(jù)進行大規(guī)模索引和查詢,比如視頻、圖片、文本、音樂、源代碼、PDF等。
          • 快速和云原生-分布式架構(gòu),具有可擴展性,支持云原生、容器化、并行、分片、異步調(diào)度、HTTP/gRPC/WebSocket 協(xié)議。
          • 高效快速-幾分鐘內(nèi)就可以構(gòu)建一個深度學習搜索系統(tǒng)。

          項目地址:

          https://github.com/jina-ai/jina

          安裝

          • 通過 PyPI 安裝:
          pip install jina
          • 通過 Conda 安裝:
          conda install jina -c conda-forge
          • 通過 Docker 安裝:
          docker run jinaai/jina:latest

          官方例子

          圖片搜索

          構(gòu)建命令:

          jina hello fashion



          這個過程會下載 Fashion-MNIST 訓練和測試數(shù)據(jù)集,并訓練集中索引 60,000 張圖像。然后從測試集中隨機抽取圖像作為查詢,整個過程大約需要1分鐘。

          聊天機器人

          構(gòu)建命令:

          pip install "jina[demo]"
          jina hello chatbot



          這會下載 CovidQA 數(shù)據(jù)集并告訴 Jina 使用 MPNet 索引 418 個問答集。索引過程在 CPU 上大約需要 1 分鐘。然后它會打開一個網(wǎng)頁,可以在其中輸入問題并詢問 Jina。

          構(gòu)建

          Document、Executor 和 Flow 是 Jina 中的三個基本概念。利用這三個組件,就可以構(gòu)建一個應用程序。

          • ?? Document 是 Jina 中的基本數(shù)據(jù)類型;
          • ?? Executor 是 Jina 處理 Documents 的方式;
          • ?? Flow 是 Jina 精簡和分配 Executor 的方式。

          1. 復制以下最小示例并運行

          import numpy as np
          from jina import Document, DocumentArray, Executor, Flow, requests

          class CharEmbed(Executor):  # a simple character embedding with mean-pooling
              offset = 32  # letter `a`
              dim = 127 - offset + 1  # last pos reserved for `UNK`
              char_embd = np.eye(dim) * 1  # one-hot embedding for all chars

              @requests
              def foo(self, docs: DocumentArray, **kwargs):
                  for d in docs:
                      r_emb = [ord(c) - self.offset if self.offset <= ord(c) <= 127 else (self.dim - 1) for c in d.text]
                      d.embedding = self.char_embd[r_emb, :].mean(axis=0)  # average pooling

          class Indexer(Executor):
              _docs = DocumentArray()  # for storing all documents in memory

              @requests(on='/index')
              def foo(self, docs: DocumentArray, **kwargs):
                  self._docs.extend(docs)  # extend stored `docs`

              @requests(on='/search')
              def bar(self, docs: DocumentArray, **kwargs):
                   docs.match(self._docs, metric='euclidean')

          f = Flow(port_expose=12345, protocol='http', cors=True).add(uses=CharEmbed, parallel=2).add(uses=Indexer)  # build a Flow, with 2 parallel CharEmbed, tho unnecessary
          with f:
              f.post('/index', (Document(text=t.strip()) for t in open(__file__) if t.strip()))  # index all lines of _this_ file
              f.block()  # block for listening request

          2. 在瀏覽器中打開(http://localhost:12345/docs),點擊 /search 并輸入以下文本,點擊 Execute 按鈕:

          {"data": [{"text""@requests(on=something)"}]}


          3. 不喜歡 GUI 也可以使用 Python 命令行來做。保持步驟 1 的服務運行,通過 Python 創(chuàng)建客戶端:

          from jina import Client, Document
          from jina.types.request import Response


          def print_matches(resp: Response):  # the callback function invoked when task is done
              for idx, d in enumerate(resp.docs[0].matches[:3]):  # print top-3 matches
                  print(f'[{idx}]{d.scores["euclidean"].value:2f}: "{d.text}"')


          c = Client(protocol='http', port=12345)  # connect to localhost:12345
          c.post('/search', Document(text='request(on=something)'), on_done=print_matches)

          打印如下結(jié)果:

          Client@1608[S]:connected to the gateway at localhost:12345!
          [0]0.168526: "@requests(on='/index')"
          [1]0.181676: "@requests(on='/search')"
          [2]0.218218: "from jina import Document, DocumentArray, Executor, Flow, requests"
          Python貓技術(shù)交流群開放啦!群里既有國內(nèi)一二線大廠在職員工,也有國內(nèi)外高校在讀學生,既有十多年碼齡的編程老鳥,也有中小學剛剛?cè)腴T的新人,學習氛圍良好!想入群的同學,請在公號內(nèi)回復『交流群』,獲取貓哥的微信(謝絕廣告黨,非誠勿擾?。?/span>~


          還不過癮?試試它們




          CPython 有 GIL 是因為當年設(shè)計的人偷懶嗎?

          Python 實現(xiàn)定時任務的八種方案!

          一個小破網(wǎng)站,居然比 Python 官網(wǎng)還牛逼

          Schedule—比 Celery 更輕量級的周期任務調(diào)度工具

          Python對象的身份迷思:從全體公民到萬物皆數(shù)

          Python 性能測試工具 Locust 極簡入門


          如果你覺得本文有幫助
          請慷慨分享點贊,感謝啦!
          瀏覽 49
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日韩欧美高清dvd碟片 | 日韩精品第一页 | 免费成人黄色电影网站 | 日批视频免费播放 | 欧美mv日韩mv国产网站 |