基于bert的语义匹配_构建基于BERT的语义搜索系统…针对“星际迷航”

基于bert的语义匹配

If you read my previous article on Towards Data Science you’ll know I’m a bit of a Star Trek nerd. There’s only one thing I like more than Star Trek, and that’s building cool new stuff with AI. So I thought I’d combine the two yet again!

如果您阅读我以前的《迈向数据科学》的文章,您会知道我有点像《星际迷航》的书呆子。 除了星际迷航,我只喜欢一件事,而这正是AI创造的新奇事物。 所以我想我又将两者结合了!

In this tutorial we’re going to build our own search engine to search all the lines from Star Trek: The Next Generation. We’ll be using Jina, a neural search framework which uses deep learning to power our NLP search, though we could easily use it for image, audio or video search if we wanted to.

在本教程中,我们将构建自己的搜索引擎来搜索《 星际迷航:下一代》中的所有文章 。 我们将使用Jina ,这是一个神经搜索框架,该框架使用深度学习为NLP搜索提供支持,但如果愿意,我们可以轻松地将其用于图像,音频或视频搜索。

We’ll cover:

我们将介绍:

  • Basic setup

    基本设定
  • Running a demo of our app (yes, even before we code it)

    运行我们的应用程序的演示(是的,甚至在我们编写代码之前)
  • Using cookiecutter to create project and boilerplate code

    使用cookiecutter创建项目和样板代码
  • Downloading our Star Trek dataset

    下载我们的星际迷航数据集
  • Loading, indexing, and searching our dataset

    加载,索引和搜索我们的数据集
  • A deeper look behind the scenes

    深入了解幕后情况
  • What to do if things go wrong

    如果出问题了该怎么办

If you’re new to AI or search, don’t worry. As long as you have some knowledge of Python and the command line you’ll be fine. If it helps, think of yourself as Lieutenant Commander Data Science.

如果您不熟悉AI或搜索,请不要担心。 只要您对Python和命令行有一定的了解,就可以了。 如果有帮助,可以将自己视为数据科学中尉。

Image for post
Giphy 吉菲

试试看 (Try It Out)

Before going through the trouble of downloading, configuring and testing your search engine, let’s get an idea of the finished product. In this case, it’s exactly the same as what we’re building, but with lines from South Park instead of Star Trek:

在解决下载,配置和测试搜索引擎的麻烦之前,让我们先了解一下成品。 在这种情况下,它与我们正在建造的建筑物完全相同,但是使用的是南方公园的线路,而不是星际迷航:

Image for post
Jinabox Jinabox

Jina has a pre-built Docker image with indexed data from South Park. You can run it with:

Jina有一个预先构建的Docker映像,其中包含来自South Park的索引数据。 您可以使用以下命令运行它:

docker run -p 45678:45678 jinaai/hub.app.distilbert-southpark

After getting Docker up and running, you can start searching for those South Park lines.

在启动并运行Docker之后,您可以开始搜索这些南方公园线。

用Jinabox查询 (Query with Jinabox)

Jinabox is a simple web-based front-end for neural search. You can see it in the graphic at the top of this tutorial.

Jinabox是用于神经搜索的基于Web的简单前端。 您可以在本教程顶部的图形中看到它。

  1. Go to jinabox in your browser

    在浏览器中转到jinabox

  2. Ensure you have the server endpoint set to http://localhost:45678/api/search

    确保将服务器端点设置为http://localhost:45678/api/search

  3. Type a phrase into the search bar and see which South Park lines come up

    在搜索栏中输入短语,看看出现了哪些南方公园线

Note: If it times out the first time, that’s because the query system is still warming up. Try again in a few seconds!

注意:如果第一次超时,那是因为查询系统仍在预热。 请在几秒钟后再试一次!

curl查询 (Query with curl)

Alternatively, you can open your shell and check the results via the RESTful API. The matched results are stored in topkResults.

或者,您可以打开外壳并通过RESTful API检查结果。 匹配的结果存储在topkResults

curl --request POST -d '{"top_k": 10, "mode": "search", "data": ["text:hey, dude"]}' -H 'Content-Type: application/json' 'http://0.0.0.0:45678/api/search'

You’ll see the results output in JSON format. Each result looks like:

您将看到JSON格式的结果输出。 每个结果看起来像:

Now go back to your terminal running Docker and hit Ctrl-C (or Command-C on Mac) a few times to ensure you've stopped everything.

现在回到运行Docker的终端,然后Ctrl-C (或Mac上的Command-C )几次,以确保已停止所有操作。

从事! (Engage!)

Now that you know what we’re building, let’s get started!

现在您知道我们正在构建什么,让我们开始吧!

You will need:

你会需要:

  • A basic knowledge of Python

    Python基本知识
  • Python 3.7 or higher installed, and pip

    已安装Python 3.7或更高版本,并pip

  • A Mac or Linux computer (Jina doesn’t currently support Windows)

    Mac或Linux计算机(Jina当前不支持Windows)
  • 8 gigabytes or more of RAM

    8 GB或更多的RAM

克隆仓库 (Clone the Repo)

Let’s get the basic files we need to get moving:

让我们获取移动所需的基本文件:

git clone git@github.com:alexcg1/my-first-jina-app.git 
cd my-first-jina-app

运行Cookiecutter (Run Cookiecutter)

Image for post
Giphy
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值