Skip to main content

About

This repo contains the utils for nlmatics projects. Any modules/funcs used across two repos should be listed here.

model_client

This module provides clients to access nlp models from model server.

EncoderClient with DPR

from nlm_utils.model_client import EncoderClient
model_server_url = <suppy model server url>
encoder = EncoderClient(
    model="dpr-context",
    url=model_server_url,
)
encoder(["sales was 20 million dollars"])

from nlm_utils.model_client import EncoderClient
model_server_url = <suppy model server url>
encoder = EncoderClient(
    model="dpr-question",
    url=model_server_url,
)
encoder(["how much was sales"])

EncoderClient with SIF

from nlm_utils.model_client import EncoderClient
model_server_url = <suppy model server url>
encoder = EncoderClient(
    model="sif",
    url=model_server_url,
)
encoder(["sales was 20 million dollars"])

ClassificationClient used to get possible answer type of a qa

from nlm_utils.model_client.classification import ClassificationClient
model_server_url = <suppy model server url>
qa_type_client = ClassificationClient(
    model="roberta",
    task="qa_type",
    url=serverUrl,
    retry=1,
)
qa_type_client(["What is the name of the company"])

returns

{'predictions': ['HUM:gr']}

ClassificationClient used for QA

from nlm_utils.model_client.classification import ClassificationClient
model_server_url = <suppy model server url>
qa_client = ClassificationClient(
    model='roberta',
    task="roberta-qa",
    host=model_server_url,
    port=80,
)
qa_client(["wht is the listing symbol of common stock or shares"], ["Our common stock is listed on the NYSE under the symbol 'MSFT'."])

returns

{'answers': [{'0': {'end_byte': 60,
    'end_logit': 16,
    'probability': 0.9999986487212269,
    'start_byte': 57,
    'start_logit': 14,
    'text': 'MSFT'}},
  {}]}

ClassificationClient used for boolean (yes/no) question answering

from nlm_utils.model_client.classification import ClassificationClient
model_server_url = <suppy model server url>
boolq_client = ClassificationClient(
    model="roberta",
    task="boolq",
    url=model_server_url,
    retry=1,
)
sentences = ["it is snowing outside"]
question = ["is it snowing"]
boolq_client(question, sentences)

returns

{'predictions': ['True']}

lazy cache

This module provides lazy cache for different types of data. Cache can be configured to saved to different stroage

  • Files
  • Memory
  • Redis
  • MongoDB
  • Google Cloud (planning)

Usage

# import Cache module
from nlm_utils.cache import Cache

# init cache with FileAgent
cache = Cache("FileAgent")

# apply cache on function
@cache
def func1(args):
    pass

# specify cache_key
func1(args, cache_key="cache_key")
# force_overwrite_cache
func1(args, overwrite=True)
# do not read and write cache
func1(args, no_cache=True)

cache agent

Currently, cache support following agents

# file
cache = Cache("FileAgent", path=".cache", collection="collection")

# memory
cache = Cache("MemoryAgent", prefix="prefix")

# Mongodb
cache = Cache("MongodbAgent", db="cache", collection="cache")

# Redis
cache = Cache("RedisAgent", prefix="collection")

Key for the cache

By default, cache layer will detect the arguments and generate the cache automaticly. You can also specify the cache_key or include uid as a attribute in the argument. The cache can be force overwrite by passing in overwrite argument.

Cache will also block the I/O if writing cache is happening (lock) -- planning

utils (planning)

Functions can be shared across multiple repos.

  • read_config(config_file)

Credits 2020-2024

The code was written by the following while working at Nlmatics Corp.

  • The initial skeleton and model clients were written by Suhail Kandanur.
  • Reshav Abraham wrote the nlp_client.
  • Yi Zhang refactored the code and created the core framework.
  • Ambika Sukla wrote the value parser added code and prompts for flan-t5, encoder and openai models.
  • Tom Liu wrote yolo client and made several bug fixes.
  • Kiran Panicker wrote the location parser, search summarization prompts for openai and made several bug fixes.

Metadata

Release files for nlm-utils 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nlm-utils 0.1.2
File Size Uploaded Provenance Actions
nlm-utils-0.1.2.tar.gz 58.6 kB Without provenance Details for nlm-utils-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nlm-utils 0.1.2
File Interpreter ABI Platform Actions
nlm_utils-0.1.2-py3-none-any.whl Python 3 none any Details for nlm_utils-0.1.2-py3-none-any.whl

Total release size: 132.7 kB

Release files / nlm-utils-0.1.2.tar.gz

Download URL nlm-utils-0.1.2.tar.gz
Size 58.6 kB
Tags Source
SHA-256 checksum
How to use checksums
40cc3f6c510d801d0e592aba678d5273b27b4445444e36d014aa796692ddb7c4
BLAKE2b-256 checksum
How to use checksums
ff11199aaef35ac006a07ba1e37fe9d4cc6a08633b1356dbcdaef6eab95b8e33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / nlm_utils-0.1.2-py3-none-any.whl

Download URL nlm_utils-0.1.2-py3-none-any.whl
Size 74.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8870919cabcaf57e71f04d0b824e2c6ad4409ff931acfe5267b5e16dce97280d
BLAKE2b-256 checksum
How to use checksums
077f13c079a2f18ad53cff261cc785e6457e508526acff61913e484e7cb23fe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for nlm-utils 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page