Skip to content

Latest commit

 

History

History
98 lines (75 loc) · 4.53 KB

File metadata and controls

98 lines (75 loc) · 4.53 KB

Taiwan-Criminal-Law-Interactive-Chatbot

This project is made by undergraduate students from the WIDM Lab. (Web Intelligence and Data Mining Laboratory), and is the result of NCU (National Central University) CSIE dept. (Computer Science and Information Engineering department) 2023 project competition.

It has won the Outstanding Performance Award (4th place) in the department-level project competition and the Excellent Award (2nd place) in the college-level project competition.

Before using

Download data, pre-trained model and checkpoints

Due to the size of data, model and checkpoints files are too large, you need to download those files and put them into the correct paths manually, and the program can execute correctly.

  • data: put all files into ./legal_judgment_prediction/data
  • pytorch_model.bin: put file into ./legal_judgment_prediction/bert/
  • checkpoints: download the checkpoint you want and put the file into ./legal_judgment_prediction/results/Bert

Install the required modules

Run pip install -r requirements.txt to install all required modules.

How to run LJP (Legal Judgment Prediction) model?

This program has three mode: train, eval, serve.

All execution messages are saved in legal_judgment_prediction/log/Bert.log.

Usage

python main.py --config [config_file_path] --gpu [gpu IDs] --mode [mode] \
[--checkpoint] [checkpoint_file_path] [--do_test] [--open_server]

Detail of parameters

  • --config, -c [config_file_path]: The path of config file. You can use default config ./config.ini
  • --gpu, -g [gpu_IDs]: The list of gpu ID. The first gpu ID starts from 0.
  • --mode, -m [mode]: There are three mode: train, eval or serve.
  • --checkpoint: The path of checkpoint. (eval, serve mode required)
  • --do_test: If you want to do test when training, add this parameter into instruction.
  • --open_server: If you want to run this service on Line-Bot, Add this parameter into instruction.

Train

Basic usage

python main.py --config [config_file_path] --gpu [gpu_IDs] --mode train \
[--checkpoint] [checkpoint_file_path] [--do_test]

In this mode, program will train new checkpoints.

If you add --checkpoint [checkpoint_file_path] into instruction, program will train new checkpoints based [checkpoint_file_path].

If you want to do test when training, add --do_test into instruction.

Eval

Basic usage

python main.py --config [config_file_path] --gpu [gpu_IDs] --mode eval \
--checkpoint [checkpoint_file_path]

In this mode, program will evalute test data.

Serve

Basic usage

python main.py --config [config_file_path] --gpu [gpu_IDs] --mode serve \
--checkpoint [checkpoint_file_path] [--open_server]

In this mode, program can predict the accuse, article and article_source of inputting string.

If you add --open_server into instruction, program will open Flask web server. You can use this mode with Line-Bot.

How to run Line-Bot

  1. Move to root directory Taiwan-Criminal-Law-Interactive-Chatbot
  2. Revise below settings in ./config.ini
    • [server]
      • server_socket_IP: This can be found with command ifconfig.
      • LINE_CHANNEL_ACCESS_TOKEN: This can be found in your channel on LINE Developers.
      • CHANNEL_SECRET: This can be found in your channel on LINE Developers.
  3. Run ngrok with instruction ngrok http 5000
  4. Edit Webhook URL in your channel on LINE Developers with the link generated by ngrok
  5. Run main.py with serve mode and add --open_server parameter into instruction

Demo

Serve (simple_IO)

Event Prediction

Demo_simple_IO

Enter shutdown in chatroom to close whole system safely.

Serve (open_server)

How to Use

Demo_Line_Bot_How_to_Use

Today News

Demo_Line_Bot_Today_News

Event Prediction

Demo_Line_Bot_Event_Prediction

Law Search

Demo_Line_Bot_Law_Search

Enter shutdown in chatroom to close whole system safely (Same as Serve (simple_IO)).