Skip to main content

A SpaCy pipeline and models for NLP on Indian legal text.

Project description

Opennyai : An efficient NLP Pipeline for Indian Legal documents

Current Release Version PyPI version python version Downloads

Opennyai is a python library for natural language preprocessing on Indian legal texts.

This library provides unified access to the following 3 pre-trained AI models developed by OpenNyAI which focus on Indian court judgments:

  • Named Entity Recognition (NER): GitHub , paper
  • Judgment Structuring using Sentence Rhetorical Roles: GitHub , paper
  • Extractive Summarizer: GitHub

This library is mainly for running the pretrained models on your custom input judgments text. For more details about data and model training, please refer to individual git repo links.

🔧 1. Installation

Using uv (recommended)

Install uv if you haven't already:

curl -LsSf https://astral.sh/uv/install.sh | sh

Create a virtual environment and install opennyai:

uv venv --python 3.13
source .venv/bin/activate
uv pip install opennyai

Using pip

You can also install with pip directly (requires Python >= 3.13):

python -m venv .venv
source .venv/bin/activate
pip install -U opennyai

For GPU support

If you want to utilize spacy with GPU please install Cupy with the appropriate CUDA version:

pip install cupy-cuda12x  # For CUDA 12.x

In case of any issue with installation please refer to spacy installation with cupy.

📖 2. Documentation

Please refer to the Documentation for more details.

👩‍💻 3. Usage

To run the 3 OpenNyAI models on judgment texts of your choice please run following python code

from opennyai import Pipeline
from opennyai.utils import Data
import urllib

# Get court judgment texts on which to run the AI models
text1 = urllib.request.urlopen(
    'https://raw.githubusercontent.com/OpenNyAI/Opennyai/master/samples/sample_judgment1.txt').read().decode()
text2 = urllib.request.urlopen(
    'https://raw.githubusercontent.com/OpenNyAI/Opennyai/master/samples/sample_judgment2.txt').read().decode()

# you can also load your text files directly into this
texts_to_process = [text1, text2]

# create Data object for data  preprocessing before running ML models
data = Data(texts_to_process)

# If you have access to GPU then set this to True else False
use_gpu = True

# Choose which of the AI models you want to run from the 3 models 'NER', 'Rhetorical_Role','Summarizer'. E.g. If just Named Entity is of interest then just select 'NER'

pipeline = Pipeline(components=['NER', 'Rhetorical_Role', 'Summarizer'], use_gpu=use_gpu, verbose=True)

results = pipeline(data)

The output of each model is present in following keys of each element of the output

results[0][
    'annotations']  ## shows the result of model at sentence level, each entry will have entities, rhetorical role, and other details
results[0]['summary']  ## shows Summary for each of the Rheorical Role for first judgment text 

For more details on usage please refer to the documentation

Google Colab Notebook

Description Link
Run Inference Open In Colab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opennyai-0.0.14.tar.gz (882.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opennyai-0.0.14-py3-none-any.whl (171.6 kB view details)

Uploaded Python 3

File details

Details for the file opennyai-0.0.14.tar.gz.

File metadata

  • Download URL: opennyai-0.0.14.tar.gz
  • Upload date:
  • Size: 882.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for opennyai-0.0.14.tar.gz
Algorithm Hash digest
SHA256 55f1772ec4f66223d6ce1fb2a4b81e07006cc9735ef8680aa7269c63d745fc4d
MD5 82589949359805424bfc4d3adbb495a0
BLAKE2b-256 6a3e26366d11169d9a800e175e62ca7480094fbada14d3c01c4ef85272575a17

See more details on using hashes here.

File details

Details for the file opennyai-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: opennyai-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 171.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for opennyai-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 047722f3ff189d0541447699b27418f39b08bf7c670b3bbcc6717e9daa1017d4
MD5 af80c7c717ae5b63ea1ce584dc23e0c8
BLAKE2b-256 394c2db6d2b6cedb3f685bf9536fa1738f92e28ad37a93e86ba51950e2e79d0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page