Giter VIP home page Giter VIP logo

semantic-search-faiss's Introduction

FAISS를 이용한 시맨틱 서치

FAISSElasticSearch를 이용한 시맨틱 서치 토이 프로젝트입니다.

프로젝트에 사용된 여러 라이브러리들이 리눅스에서만 지원되기 때문에, 리눅스 환경에서의 실행만 테스트되었습니다.

설치를 바르게 진행하셨다면 corpus.json 파일을 원하는 문장으로 채운 후, 커스텀 시맨틱 서치 API를 만들어 보실 수 있습니다.


프로젝트 설치

# 프로젝트 클론
git clone https://github.com/Huffon/semantic-search-faiss.git
cd semantic-search-faiss

# 아나콘다 환경 생성
conda create -n semantic-search python=3.6
conda activate semantic-search

# 프로젝트 필수 라이브러리 설치
conda install faiss-gpu pytorch cudatoolkit=10.0 -c pytorch
pip install -r requirements.txt
  • ElasticSearch의 사용을 위해서는 8 버전 이상의 JDK가 필요합니다.
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
echo $JAVA_HOME
>>> /usr/lib/jvm/java-11-openjdk-amd64/
  • ElasticSearch 인스턴스가 제대로 실행되지 않는 경우, JAVA_HOME path 가 잘 설정되어 있는지 확인하셔야 합니다.
# ElasticSearch 다운로드
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-aarch64.tar.gz

# 다운로드 파일 압축 해제
tar xvf elasticsearch-7.7.0-linux-aarch64.tar.gz

# ElasticSearch 폴더로 이동
cd elasticsearch-7.7.0/bin

# 한국어 토크나이저 Nori 설치
sudo ./elasticsearch-plugin install analysis-nori

실행 및 인퍼런스

  • ElasticSearch와의 통신을 위해 ElasticSearch 클라이언트를 실행합니다:
    • cf. ElasticSearch는 기본적으로 9200번 포트를 사용하기 때문에 포트 충돌이 일어나지 않도록 주의합니다.
./elasticsearch-7.7.0/bin/elasticsearch
  • Flask API 서버 실행을 위해 다음 코드를 실행합니다. 첫 실행 시에는 인덱스 생성으로 인한 Latency 가 있을 수 있습니다:
python server.py
  • 인퍼런스를 위해 다음 요청을 전송합니다:
http -v POST localhost:5000/search query="코로나"

cf. http는 다음 명령어를 통해 설치 가능합니다: apt-get install httpie


인퍼런스 결과

  • 코로나를 입력했을 때, ElasticSearchFAISS가 내놓은 헤드라인입니다.

  • 확진을 입력했을 때, ElasticSearchFAISS가 내놓은 헤드라인입니다.

TODO

  • FastAPI 적용
  • 한국어 문장 임베딩 모델 Fine-tuning 후, 갈아 끼우기
  • 유저 인터페이스 적용
  • 도커라이즈

참조

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.