Weak Annotators (NER)
Experiments with weak annotators for NER using different models and methods including LLMs.
Installation
pip install git+https://github.com/imvladikon/weak_annotators.git
Usage
- Using
UniversalNERextractor:
from weak_annotators import UniversalNerExtractor
text = """
The patient was prescribed 100 mg of aspirin daily for 3 days.
""".strip()
labels = ["DRUG", "DISEASE", "SYMPTOM", "DURATION"]
extractor = UniversalNerExtractor(labels=labels)
print(extractor(text))
# [Span(start=37, end=44, text='aspirin', label='DRUG'), Span(start=55, end=61, text='3 days', label='DURATION')]
It returns a list of Spans but if pass return_dict=True it will return a list of dictionaries:
print(extractor(text, return_dict=True))
# [{'start': 37, 'end': 44, 'text': 'aspirin', 'label': 'DRUG'}, {'start': 55, 'end': 61, 'text': '3 days', 'label': 'DURATION'}]
- Using
medalpacaLLM:
It requires labels descriptions:
from weak_annotators import MedAlpacaExtractor
labels = ["DRUG", "DISEASE", "SYMPTOM", "DURATION"]
labels_descriptions = {
"DRUG": "Drug or medication",
"DISEASE": "Any disease, syndrome, or medical condition",
"SYMPTOM": "Any symptom or sign of a disease or medical condition",
"DURATION": "Any period of time",
}
extractor = MedAlpacaExtractor(labels=labels, labels_description=labels_descriptions)
text = """
The patient was prescribed 100 mg of aspirin daily for 3 days.
""".strip()
annotations = extractor(text)
print(annotations)
Optionally, it's possible to pass prompt_template to MedAlpacaExtractor.
prompt_template = "Extract entities of type {} from the following text:"
extractor = MedAlpacaExtractor(labels=labels, labels_description=labels_descriptions, prompt_template=prompt_template)
- Using
flair(TARS extractor):
from weak_annotators import FlairExtractor
labels = ["DRUG", "DISEASE", "SYMPTOM", "DURATION"]
extractor = FlairExtractor(labels=labels)
print(extractor(text))
Metadata
Release files for weak-annotators 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| weak_annotators-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for weak_annotators-0.0.1-py3-none-any.whl |
Release files / weak_annotators-0.0.1-py3-none-any.whl
| Download URL | weak_annotators-0.0.1-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbe518f38ad46c875b465b1dddd4844a6f0ae5037146fab5e25575220539f50e
|
|
BLAKE2b-256 checksum How to use checksums |
8cb3dfb1bec1420eccfee880e05b2768dacf2c4df27bb046590d4b46f7bb7d04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for weak-annotators 0.0.1
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.