Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tutorials Notebooks #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ weights/
models/
.terraform
.terraform.lock.hcl
examples/.bashrc
261 changes: 261 additions & 0 deletions examples/Automating Compliance Document Reviews.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6ec165ea-0eee-44a4-a05e-1b59ea362f91",
"metadata": {},
"source": [
"## Automating Compliance Document Reviews"
]
},
{
"cell_type": "markdown",
"id": "6a7f8089-b865-411e-8d50-4372c41763aa",
"metadata": {},
"source": [
"### Prerequisites to follow this notebook:"
]
},
{
"cell_type": "markdown",
"id": "3af8b1ad-4bbe-4b91-8af8-15b799338d7e",
"metadata": {},
"source": [
"1. Install the remyxai-cli: `pip install git+https://github.com/remyxai/remyxai-cli.git`\n",
"2. Ensure the REMYXAI_API_KEY is set as an environment variable."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b9a03a2-6469-4e87-86ad-8668e104e6e2",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import traceback\n",
"from remyxai.client.myxboard import MyxBoard\n",
"from remyxai.client.remyx_client import RemyxAPI\n",
"from remyxai.api.evaluations import EvaluationTask, download_evaluation, list_evaluations"
]
},
{
"cell_type": "markdown",
"id": "4fed21c4-b1d7-4c52-814f-6ea40abdc454",
"metadata": {},
"source": [
"### Step 1: Define models for evaluation"
]
},
{
"cell_type": "markdown",
"id": "21d2ce6a-4bcd-4617-bad6-628d9f15bc4c",
"metadata": {},
"source": [
"Evaluate models that are capable of processing compliance documents. Use models supported by Remyx for tasks like identifying risks and summarizing compliance insights."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eba2744b-8aef-4f4a-89cd-038349de0137",
"metadata": {},
"outputs": [],
"source": [
"models = ['openai/LegalGPT-2', 'microsoft/DeBERTa-v3-large', 'meta-llama/Llama-2-13b-hf', 'google/BERT-GDPR', 'mistralai/Mistral-7B-Instruct-v0.3']"
]
},
{
"cell_type": "markdown",
"id": "65db1505-9df1-42c8-bd91-e7d81139649f",
"metadata": {},
"source": [
"### Create a MyxBoard for evaluation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cc5bfc5-7798-4097-a2d2-efd1d233158c",
"metadata": {},
"outputs": [],
"source": [
"myx_board_name = \"compliance_doc_review\"\n",
"myx_board = MyxBoard(model_repo_ids=models, name=myx_board_name)\n",
"myx_board"
]
},
{
"cell_type": "markdown",
"id": "96c4abf4-36da-42e6-bd56-f7509b6d23d8",
"metadata": {},
"source": [
"### Initialize the RemyxAPI"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "418cc6f8-2dcb-4619-a74b-bd5c8c10334b",
"metadata": {},
"outputs": [],
"source": [
"remyx_api = RemyxAPI()\n",
"remyx_api"
]
},
{
"cell_type": "markdown",
"id": "b1edd97e-52e1-488d-a3b8-3f3ede49e0e8",
"metadata": {},
"source": [
"### Define the evaluation task"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "479d0c08-2157-4e5a-bb4c-a1735c9528af",
"metadata": {},
"outputs": [],
"source": [
"tasks = [EvaluationTask.MYXMATCH]"
]
},
{
"cell_type": "markdown",
"id": "dbab58b3-aee6-4546-814b-52862a84e996",
"metadata": {},
"source": [
"### Define compliance document prompts for evaluation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4cd3cd31-32a0-4023-a35c-d7ef0874652c",
"metadata": {},
"outputs": [],
"source": [
"prompts = [\n",
" \"Identify key regulatory risks in this document\",\n",
" \"Highlight non-compliance with GDPR\",\n",
" \"Summarize the main compliance requirements in this section\"\n",
"]"
]
},
{
"cell_type": "markdown",
"id": "e6aa3786-61af-41ea-824b-708e9a1556a7",
"metadata": {},
"source": [
"### Run evaluation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0aeb28e6-6c57-4d06-b9a7-ebfe675b8751",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"for prompt in prompts:\n",
" remyx_api.evaluate(myx_board, tasks, prompt=prompt)"
]
},
{
"cell_type": "markdown",
"id": "0aec6afa-7b49-4944-a2ba-2d8a58229d64",
"metadata": {},
"source": [
"### Check evaluation status"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1157771d-a569-440b-8c8d-0aad1eb0de99",
"metadata": {},
"outputs": [],
"source": [
"evaluations = list_evaluations()\n",
"evaluations"
]
},
{
"cell_type": "markdown",
"id": "5655193e-a997-4127-afa4-80af5ae42b9d",
"metadata": {},
"source": [
"### Download results for analysis"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4e51b1d-b5b6-4c14-bf31-423a745b477b",
"metadata": {},
"outputs": [],
"source": [
"results = download_evaluation(\"myxmatch\", \"compliance_doc_review\")\n",
"results['message']"
]
},
{
"cell_type": "markdown",
"id": "0820de00-261c-498f-bf6f-6b26e57df0cb",
"metadata": {},
"source": [
"### Results Summary"
]
},
{
"cell_type": "markdown",
"id": "dd0133ea-20c0-4c58-bcbe-77cf28315bfb",
"metadata": {},
"source": [
"- **Top Model for Compliance Tasks**: `LegalGPT-2` ranks the highest for identifying risks and summarizing compliance documents.\n",
"- **Integration**: Use the insights to integrate `LegalGPT-2` into a document processing pipeline for automation of compliance document review tasks."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cdbbf694-366b-4140-a96a-53330cc96965",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "aef7d4cd-9e3e-439d-aa20-cc12d13b714e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading