LegalQA using SentenceKoBART
Implementation of legal QA system based on SentenceKoBART
- How to train SentenceKoBART
- Based on Neural Search Engine Jina v2.0
- Provide Korean legal QA data(1,830 pairs)
- Apply approximate KNN search with Faiss, Annoy, Hnswlib.
Setup
# install git lfs , https://github.com/git-lfs/git-lfs/wiki/Installation
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt install git-lfs
git clone https://github.com/haven-jeon/LegalQA.git
cd LegalQA
git lfs pull
# If the lfs quota is exceeded, please download it with the command below.
# https://drive.google.com/file/d/1DJFMknxT7OAAWYFV_WGW2UcCxmuf3cp_/view?usp=sharing
# mv SentenceKoBART.bin model/
# pip install --use-deprecated=legacy-resolver -r requirements.txt
pip install -r requirements.txt
Index
python app.py -t index
GPU-based indexing available as an option
device: cuda
Search
With REST API
To start the Jina server for REST API:
# python app.py -t query_restful --flow flows/query_numpy.yml
python app.py -t query_restful
Then use a client to query:
curl --request POST -d '{"parameters": {"limit": 1}, "data": ["μμ κ΄λ ¨ λ¬Έμ"]}' -H 'Content-Type: application/json' 'http://0.0.0.0:1234/search'
From the terminal
# python app.py -t query --flow flows/query_numpy.yml
python app.py -t query
AnnLite
Approximate KNN Search withpython app.py -t index --flow flows/index_annlite.yml
python app.py -t query --flow flows/query_annlite.yml
- Retrieval time(sec.)
- AMD Ryzen 5 PRO 4650U, 16 GB Memory
- Average of 100 searches
- Excluding BertReRanker
top-k | Numpy | AnnLite | Faiss | Annoy |
---|---|---|---|---|
10 | 1.433 | 0.101 | 0.131 | 0.118 |
HNSWPostgresIndexer
Production Ready Neural Search withdocker run -e POSTGRES_PASSWORD=123456 -p 127.0.0.1:5432:5432/tcp postgres:13.2
python app.py -t index --flow flows/index_psqlhnsw.yml
python app.py -t query --flow flows/query_psqlhnsw.yml
Presentation
![]() |
---|
Demo
- Working!
![]() |
---|
Links
FAQ
Why this dataset?
Legal data is composed of technical terms, so it is difficult to search if you are not familiar with these terms. Because of these characteristics, I thought it was a good example to show the effectiveness of neural IR.
LFS quota is exceeded
You can download SentenceKoBART.bin
from one of the two links below.
Citation
Model training, data crawling, and demo system were all supported by the AWS Hero program.
@misc{heewon2021,
author = {Heewon Jeon},
title = {LegalQA using SentenceKoBART},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/haven-jeon/LegalQA}}
License
- QA data
data/legalqa.jsonlines
is crawled in www.freelawfirm.co.kr based onrobots.txt
. Commercial use other than academic use is prohibited. - We are not responsible for any legal decisions we make based on the resources provided here.