A web interface for a fine-tuned legal question-answering model using Hugging Face Transformers.
- Legal Q&A Model
The model used in this project is a fine-tuned version of the deepset/roberta-base-squad2 model from Hugging Face Transformers. It is specifically designed for question-answering tasks, utilizing a transformer architecture to provide accurate responses based on given contexts.
- Transformer Architecture: Leverages the power of transformer models for improved performance.
- Fine-Tuning: Adapted for legal document context, enhancing its ability to understand and respond to legal inquiries.
The model has been fine-tuned using the Open Australian Legal Q&A Dataset (Butler, 2023) available on Hugging Face. This dataset comprises a collection of legal questions and their corresponding answers extracted from Australian legal documents.
- Diverse Legal Questions: Includes a wide range of questions covering various aspects of Australian law.
- Contextual Information: Each question is paired with relevant context from legal documents, allowing the model to learn the relationship between legal texts and user inquiries.
This rich dataset enables the model to provide precise and contextually relevant answers to user queries related to Australian legal matters.
The web interface is built using FastAPI and provides an intuitive user experience for interacting with the question-answering model.
- User-Friendly Form: Users can easily input their questions and context through a simple HTML form.
- Dynamic Responses: The application processes inputs in real-time and displays the top answers along with their confidence scores.
- Sliding Window Technique: To handle large text inputs effectively, the application utilizes a sliding window technique to split the context into manageable chunks, ensuring that the model can process the entire text efficiently. The model then chooses the top 5 answers with the highest confidence scores and reports them.
- Responsive Design: The interface is designed to be accessible on both desktop and mobile devices.
- FastAPI: For building the web application and API.
- Jinja2: For rendering HTML templates dynamically.
- Transformers: For loading the fine-tuned model and processing questions.
The web interface serves as a bridge between users and the underlying model, facilitating easy access to legal information and enhancing the usability of the fine-tuned question-answering system.
Before you start, ensure you have the following installed on your machine:
- Docker (follow the installation instructions for your operating system)
- Basic command line knowledge
- Open your terminal (Command Prompt, PowerShell, or Terminal).
- Clone the repository using the following command:
git clone https://github.com/furkmak/legal_qa.git
- Navigate into the cloned directory:
cd legal_qa
- In the terminal, ensure you are in the root of the project directory (where the
Dockerfile
is located). - Build the Docker image using the following command (replace
yourimage
with your desired image name):docker build -t yourimage .
Once the image is built, you can run the Docker container using:
docker run -p 8000:8000 yourimage
This command maps port 8000 of your local machine to port 8000 of the container, allowing you to access the web interface.
- Open your web browser.
- Navigate to http://localhost:8000.
- You should see the application interface where you can input your questions and context.
- Enter your Question: In the "Question" input field, type your legal question.
- Provide Context: In the "Context" text area, paste the relevant legal document text.
- Click the "Get Answer" button.
- The application will process your input and display the answer with its confidence score.
To stop the Docker container, go back to your terminal and press Ctrl + C
. This will stop the running process.
- If you encounter issues building the Docker image, ensure that you have Docker running and that your internet connection is stable (as it may need to download dependencies).
- For any errors while running the container, check the terminal output for error messages, and ensure that the correct ports are not in use by other applications.
If you would like to contribute to this project, please feel free to fork the repository and submit a pull request with your improvements.
This project is licensed under the MIT License.