nlm-utils


Namenlm-utils JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/nlmatics/nlm-utils
SummaryCommon utilities used by all nlm-* libraries.
upload_time2024-01-19 22:06:29
maintainer
docs_urlNone
authorAmbika Sukla
requires_python
licenseApache License 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nlmatics/nlm-utils",
    "name": "nlm-utils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ambika Sukla",
    "author_email": "ambika.sukla@nlmatics.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/11/199aaef35ac006a07ba1e37fe9d4cc6a08633b1356dbcdaef6eab95b8e33/nlm-utils-0.1.2.tar.gz",
    "platform": null,
    "description": "# About\nThis repo contains the utils for nlmatics projects. Any modules/funcs used across two repos should be listed here.\n\n## model_client\nThis module provides clients to access nlp models from model server.\n\n### EncoderClient with DPR\n```\nfrom nlm_utils.model_client import EncoderClient\nmodel_server_url = <suppy model server url>\nencoder = EncoderClient(\n    model=\"dpr-context\",\n    url=model_server_url,\n)\nencoder([\"sales was 20 million dollars\"])\n\nfrom nlm_utils.model_client import EncoderClient\nmodel_server_url = <suppy model server url>\nencoder = EncoderClient(\n    model=\"dpr-question\",\n    url=model_server_url,\n)\nencoder([\"how much was sales\"])\n```\n### EncoderClient with SIF\n```\nfrom nlm_utils.model_client import EncoderClient\nmodel_server_url = <suppy model server url>\nencoder = EncoderClient(\n    model=\"sif\",\n    url=model_server_url,\n)\nencoder([\"sales was 20 million dollars\"])\n```\n\n### ClassificationClient used to get possible answer type of a qa\n```\nfrom nlm_utils.model_client.classification import ClassificationClient\nmodel_server_url = <suppy model server url>\nqa_type_client = ClassificationClient(\n    model=\"roberta\",\n    task=\"qa_type\",\n    url=serverUrl,\n    retry=1,\n)\nqa_type_client([\"What is the name of the company\"])\n```\nreturns\n```\n{'predictions': ['HUM:gr']}\n```\n\n\n### ClassificationClient used for QA\n```\nfrom nlm_utils.model_client.classification import ClassificationClient\nmodel_server_url = <suppy model server url>\nqa_client = ClassificationClient(\n    model='roberta',\n    task=\"roberta-qa\",\n    host=model_server_url,\n    port=80,\n)\nqa_client([\"wht is the listing symbol of common stock or shares\"], [\"Our common stock is listed on the NYSE under the symbol 'MSFT'.\"])\n```\nreturns\n```\n{'answers': [{'0': {'end_byte': 60,\n    'end_logit': 16,\n    'probability': 0.9999986487212269,\n    'start_byte': 57,\n    'start_logit': 14,\n    'text': 'MSFT'}},\n  {}]}\n```\n\n### ClassificationClient used for boolean (yes/no) question answering\n```\nfrom nlm_utils.model_client.classification import ClassificationClient\nmodel_server_url = <suppy model server url>\nboolq_client = ClassificationClient(\n    model=\"roberta\",\n    task=\"boolq\",\n    url=model_server_url,\n    retry=1,\n)\nsentences = [\"it is snowing outside\"]\nquestion = [\"is it snowing\"]\nboolq_client(question, sentences)\n```\nreturns\n```\n{'predictions': ['True']}\n```\n\n## lazy cache\nThis module provides lazy cache for different types of data.\nCache can be configured to saved to different stroage\n- Files\n- Memory\n- Redis\n- MongoDB\n- Google Cloud (planning)\n\nUsage\n```\n# import Cache module\nfrom nlm_utils.cache import Cache\n\n# init cache with FileAgent\ncache = Cache(\"FileAgent\")\n\n# apply cache on function\n@cache\ndef func1(args):\n    pass\n\n# specify cache_key\nfunc1(args, cache_key=\"cache_key\")\n# force_overwrite_cache\nfunc1(args, overwrite=True)\n# do not read and write cache\nfunc1(args, no_cache=True)\n```\n### cache agent\nCurrently, cache support following agents\n```\n# file\ncache = Cache(\"FileAgent\", path=\".cache\", collection=\"collection\")\n\n# memory\ncache = Cache(\"MemoryAgent\", prefix=\"prefix\")\n\n# Mongodb\ncache = Cache(\"MongodbAgent\", db=\"cache\", collection=\"cache\")\n\n# Redis\ncache = Cache(\"RedisAgent\", prefix=\"collection\")\n```\n\n### Key for the cache\nBy default, cache layer will detect the arguments and generate the cache automaticly.\nYou can also specify the `cache_key` or include `uid` as a attribute in the argument.\nThe cache can be force overwrite by passing in `overwrite` argument.\n\nCache will also block the I/O if writing cache is happening (lock) -- planning\n\n\n\n## utils (planning)\nFunctions can be shared across multiple repos.\n- read_config(config_file)\n\n## Credits 2020-2024\nThe code was written by the following while working at Nlmatics Corp.\n- The initial skeleton and model clients were written by Suhail Kandanur.\n- Reshav Abraham wrote the nlp_client.\n- Yi Zhang refactored the code and created the core framework.\n- Ambika Sukla wrote the value parser added code and prompts for flan-t5, encoder and openai models. \n- Tom Liu wrote yolo client and made several bug fixes.\n- Kiran Panicker wrote the location parser, search summarization prompts for openai and made several bug fixes.\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Common utilities used by all nlm-* libraries.",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/nlmatics/nlm-utils"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "077f13c079a2f18ad53cff261cc785e6457e508526acff61913e484e7cb23fe6",
                "md5": "5165b1a21e1714d2ff6f441e7d1842b7",
                "sha256": "8870919cabcaf57e71f04d0b824e2c6ad4409ff931acfe5267b5e16dce97280d"
            },
            "downloads": -1,
            "filename": "nlm_utils-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5165b1a21e1714d2ff6f441e7d1842b7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 74075,
            "upload_time": "2024-01-19T22:06:27",
            "upload_time_iso_8601": "2024-01-19T22:06:27.477337Z",
            "url": "https://files.pythonhosted.org/packages/07/7f/13c079a2f18ad53cff261cc785e6457e508526acff61913e484e7cb23fe6/nlm_utils-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff11199aaef35ac006a07ba1e37fe9d4cc6a08633b1356dbcdaef6eab95b8e33",
                "md5": "b74f5053b1a4ba99eea540fd83e9871d",
                "sha256": "40cc3f6c510d801d0e592aba678d5273b27b4445444e36d014aa796692ddb7c4"
            },
            "downloads": -1,
            "filename": "nlm-utils-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b74f5053b1a4ba99eea540fd83e9871d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 58639,
            "upload_time": "2024-01-19T22:06:29",
            "upload_time_iso_8601": "2024-01-19T22:06:29.140874Z",
            "url": "https://files.pythonhosted.org/packages/ff/11/199aaef35ac006a07ba1e37fe9d4cc6a08633b1356dbcdaef6eab95b8e33/nlm-utils-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-19 22:06:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nlmatics",
    "github_project": "nlm-utils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "nlm-utils"
}
        
Elapsed time: 0.27006s