A fast and simple NER tool
Project description
Quickner is a new tool to quickly annotate texts for NER (Named Entity Recognition). It is written in Rust and accessible through a Python API.
Quickner is blazing fast, simple to use, and easy to configure using a TOML file.
Installation
# Create a virtual environment
python3 -m venv env
source env/bin/activate
# Install quickner
pip install quickner # or pip3 install quickner
Usage
Using the config file
from quickner import Quickner, Config
config = Config(path="config.toml") # or Config() if the config file is in the current directory
# Initialize the annotator
quick = Quickner(config=config)
# Annotate the texts using the config file
quick.process() # or annotator.process(True) to save the annotated data to a file
Using Documents
from quickner import Quickner, Document
# Create documents
rust = Document("rust is made by Mozilla")
python = Document("Python was created by Guido van Rossum")
java = Document("Java was created by James Gosling")
# Documents can be added to a list
documents = [rust, python, java]
# Initialize the annotator
quick = Quickner(documents=documents)
quick
>>> Entities: 0 | Documents: 3 | Annotations:
>>> quick.documents
[Document(id="87e03d58b1ba4d72", text=rust is made by Mozilla, label=[]), Document(id="f1da5d23ef88f3dc", text=Python was created by Guido van Rossum, label=[]), Document(id="e4324f9818e7e598", text=Java was created by James Gosling, label=[])]
>>> quick.entities
[]
Using Documents and Entities
from quickner import Quickner, Document, Entity
# Create documents from texts
texts = (
"rust is made by Mozilla",
"Python was created by Guido van Rossum",
"Java was created by James Gosling at Sun Microsystems",
"Swift was created by Chris Lattner and Apple",
)
documents = [Document(text) for text in texts]
# Create entities
entities = (
("Rust", "PL"),
("Python", "PL"),
("Java", "PL"),
("Swift", "PL"),
("Mozilla", "ORG"),
("Apple", "ORG"),
("Sun Microsystems", "ORG"),
("Guido van Rossum", "PERSON"),
("James Gosling", "PERSON"),
("Chris Lattner", "PERSON"),
)
entities = [Entity(*(entity)) for entity in entities]
# Initialize the annotator
quick = Quickner(documents=documents, entities=entities)
quick.process()
>>> quick
Entities: 6 | Documents: 3 | Annotations: PERSON: 2, PL: 3, ORG: 1
>>> quick.documents
[Document(id=87e03d58b1ba4d72, text=rust is made by Mozilla, label=[(0, 4, PL), (16, 23, ORG)]), Document(id=f1da5d23ef88f3dc, text=Python was created by Guido van Rossum, label=[(0, 6, PL), (22, 38, PERSON)]), Document(id=e4324f9818e7e598, text=Java was created by James Gosling, label=[(0, 4, PL), (20, 33, PERSON)])]
Find documents by label or entity
When you have annotated your documents, you can use the find_documents_by_label
and find_documents_by_entity
methods to find documents by label or entity.
Both methods return a list of documents, and are not case sensitive.
Example:
# Find documents by label
>>> quick.find_documents_by_label("PERSON")
[Document(id=f1da5d23ef88f3dc, text=Python was created by Guido van Rossum, label=[(0, 6, PL), (22, 38, PERSON)]), Document(id=e4324f9818e7e598, text=Java was created by James Gosling, label=[(0, 4, PL), (20, 33, PERSON)])]
# Find documents by entity
>>> quick.find_documents_by_entity("Guido van Rossum")
[Document(id=f1da5d23ef88f3dc, text=Python was created by Guido van Rossum, label=[(0, 6, PL), (22, 38, PERSON)])]
>>> quick.find_documents_by_entity("rust")
[Document(id=87e03d58b1ba4d72, text=rust is made by Mozilla, label=[(0, 4, PL), (16, 23, ORG)])]
>>> quick.find_documents_by_entity("Chris Lattner")
[Document(id=3b0b3b5b0b5b0b5b, text=Swift was created by Chris Lattner and Apple, label=[(0, 5, PL), (21, 35, PERSON), (40, 45, ORG)])]
Get a Spacy Compatible Generator Object
You can use the spacy
method to get a spacy compatible generator object.
The generator object can be used to feed a spacy model with the annotated data, you still need to convert the data into DocBin format.
Example:
# Get a spacy compatible generator object
>>> quick.spacy()
<builtins.SpacyGenerator object at 0x102311440>
# Divide the documents into chunks
>>> chunks = quick.spacy(chunks=2)
>>> for chunk in chunks:
... print(chunk)
...
[('rust is made by Mozilla', {'entitiy': [(0, 4, 'PL'), (16, 23, 'ORG')]}), ('Python was created by Guido van Rossum', {'entitiy': [(0, 6, 'PL'), (22, 38, 'PERSON')]})]
[('Java was created by James Gosling at Sun Microsystems', {'entitiy': [(0, 4, 'PL'), (20, 33, 'PERSON'), (37, 53, 'ORG')]}), ('Swift was created by Chris Lattner and Apple', {'entitiy': [(0, 5, 'PL'), (21, 34, 'PERSON'), (39, 44, 'ORG')]})]
Single document annotation
You can also annotate a single document with a list of entities.
This is useful when you want to annotate a document with a list of entities is not in the list of entities of the Quickner object.
Example:
from quickner import Document, Entity
# Create a document from a string
# Method 1
rust = Document.from_string("rust is made by Mozilla")
# Method 2
rust = Document("rust is made by Mozilla")
# Create a list of entities
entities = [Entity("Rust", "PL"), Entity("Mozilla", "ORG")]
# Annotate the document with the entities, case_sensitive is set to False by default
>>> rust.annotate(entities, case_sensitive=True)
>>> rust
Document(id="87e03d58b1ba4d72", text=rust is made by Mozilla, label=[(16, 23, ORG)])
>>> rust.annotate(entities, case_sensitive=False)
>>> rust
Document(id="87e03d58b1ba4d72", text=rust is made by Mozilla, label=[(16, 23, ORG), (0, 4, PL)])
Load from file
Initialize the Quickner object from a file containing existing annotations.
Quickner.from_jsonl
and Quickner.from_spacy
are class methods that return a Quickner object and are able to parse the annotations and entities from a jsonl or spaCy file.
from quickner import Quickner
quick = Quickner.from_jsonl("annotations.jsonl") # load the annotations from a jsonl file
quick = Quickner.from_spacy("annotations.json") # load the annotations from a spaCy file
Configuration
The configuration file is a TOML file with the following structure:
# Configuration file for the NER tool
[general]
# Mode to run the tool, modes are:
# Annotation from the start
# Annotation from already annotated texts
# Load annotations and add new entities
[logging]
level = "debug" # level of logging (debug, info, warning, error, fatal)
[texts]
[texts.input]
filter = false # if true, only texts in the filter list will be used
path = "texts.csv" # path to the texts file
[texts.filters]
accept_special_characters = ".,-" # list of special characters to accept in the text (if special_characters is true)
alphanumeric = false # if true, only strictly alphanumeric texts will be used
case_sensitive = false # if true, case sensitive search will be used
max_length = 1024 # maximum length of the text
min_length = 0 # minimum length of the text
numbers = false # if true, texts with numbers will not be used
punctuation = false # if true, texts with punctuation will not be used
special_characters = false # if true, texts with special characters will not be used
[annotations]
format = "spacy" # format of the output file (jsonl, spaCy, brat, conll)
[annotations.output]
path = "annotations.jsonl" # path to the output file
[entities]
[entities.input]
filter = true # if true, only entities in the filter list will be used
path = "entities.csv" # path to the entities file
save = true # if true, the entities found will be saved in the output file
[entities.filters]
accept_special_characters = ".-" # list of special characters to accept in the entity (if special_characters is true)
alphanumeric = false # if true, only strictly alphanumeric entities will be used
case_sensitive = false # if true, case sensitive search will be used
max_length = 20 # maximum length of the entity
min_length = 0 # minimum length of the entity
numbers = false # if true, entities with numbers will not be used
punctuation = false # if true, entities with punctuation will not be used
special_characters = true # if true, entities with special characters will not be used
[entities.excludes]
# path = "excludes.csv" # path to entities to exclude from the search
Features Roadmap and TODO
- Add support for spaCy format
- Add support for brat format
- Add support for conll format
- Add support for jsonl format
- Add support for loading annotations from a json spaCy file
- Add support for loading annotations from a jsonl file
- Find documents with a specific entity/entities and return the documents
- Add support for loading annotations from a brat file
- Substring search for entities in the text (case sensitive and insensitive)
- Partial match for entities, e.g. "Rust" will match "Rustlang"
- Pattern/regex based entites, e.g. "Rustlang" will match "Rustlang 1.0"
- Fuzzy match for entities with levenstein distance, e.g. "Rustlang" will match "Rust"
- Add support for jupyter notebook
License
MOZILLA PUBLIC LICENSE Version 2.0
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Authors
- [Omar MHAIMDAT]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for quickner-0.0.1a13-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e2adf606fed2a740e4c73565303d430a53fe4250b8b36b2b29138149016e5c7 |
|
MD5 | ae3c452bf9f2c10c9ef8f9710d630530 |
|
BLAKE2b-256 | 5da6232981c6d6db86ecb58daa385dac1a697882d62a71c0d3bfa39484edc62a |
Hashes for quickner-0.0.1a13-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61415f7af176844ed1d4960bd83870affd957dd803b632acedda9423f2abfde7 |
|
MD5 | f4e99f7a33edba2f581ba831b1ca48bb |
|
BLAKE2b-256 | 25e1f3ee2665f2e2e55365a679191b61d90cd20eda1bf43f25720af960928d57 |
Hashes for quickner-0.0.1a13-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d5aa7845ca4a18d0218b7bc8c5ce4b0b3448a1fab13a40b15838379d698416a |
|
MD5 | edd095454d39f0da112a3269fd3ac274 |
|
BLAKE2b-256 | 8876520204f24e0a72e9cfa4d7fdd741451f98fde4d49c6177adfbdf95641a90 |
Hashes for quickner-0.0.1a13-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee028b1c004b1b8a556413c0089c0fd28f599d5bef72b69b3db6557cd0d92d19 |
|
MD5 | 64a32c66f1853c668e5130a60fe40ea4 |
|
BLAKE2b-256 | 2ba784c45f0b0cd2613b56aca0fab9a437f5b00f0dc94bb6bbc3796c67409059 |
Hashes for quickner-0.0.1a13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84e3fe6a1762c6eb4b99a3378583ef5b0e73d9f3dc2927ba34443367800aa4f6 |
|
MD5 | d2ad8436d06b5ae4155dbca991be30a5 |
|
BLAKE2b-256 | 85966766380562abb4c9ab8b22f7bf139c6156f8d7112152ff592bef03233bbf |
Hashes for quickner-0.0.1a13-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61bbc688085e8e1661595f431d7f9cabc790e4910041c5a03dfe07407591b674 |
|
MD5 | 058ceca37320e54bdfad1d7cf696df0b |
|
BLAKE2b-256 | 410f0d806486abcbc28bd9099a6a7f152533097a26c59b72ec2dc89e814bb9e8 |
Hashes for quickner-0.0.1a13-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbfb5209e05ce4e1d0329f408901c77b07d848c72e7654237500b69673c54077 |
|
MD5 | b4ae93c04b8be922021f3a55ca32a45f |
|
BLAKE2b-256 | c7732748762ea728bb8b9b647d43d038778a0ea9b77e63bf31a60e8ce03ac153 |
Hashes for quickner-0.0.1a13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8204f72dd148a24cb501ceb675050b8c0274cde0da04be9d19d8694356824182 |
|
MD5 | 6f1d5ed18c3b4862812a12f1f31f75fa |
|
BLAKE2b-256 | 53f39b13df654fe1728c722cb7f1bdaed239c87b752bce9ad028e265d5ee8f70 |
Hashes for quickner-0.0.1a13-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2819e8a90f0bb5a65d06fe470659f0d44ad5f1c8aef6c810e10578dd6e9456f4 |
|
MD5 | 02311529ec3d89f6fdcb21b66442421c |
|
BLAKE2b-256 | 418fd804dab5c68e82cfe1036c8a22b888d7fede4adeea30c07b2a112d3f13b3 |
Hashes for quickner-0.0.1a13-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9e3be2eaf340d129dae8187d0c1a7bc7ad3ec3513c530382928fc4a9f59f0ba |
|
MD5 | b947a48a7490bc194d89122757cefe9c |
|
BLAKE2b-256 | a5d611bd47efc60b567cd91ec9cf4b6a006751ec235724a27931e26abc1593d7 |
Hashes for quickner-0.0.1a13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59375a5198775b674d18f6c791270eaad2e3ac16b433fe3878303e0bb82e6a1e |
|
MD5 | 8a34f635a20d30e5d2a9164c0b4b6a86 |
|
BLAKE2b-256 | 55cecbd508ea5e71feae0197d6705945f4b2031acd056c1934d0a5a1cfb312cc |
Hashes for quickner-0.0.1a13-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a13048acf887b991b4b0da0903df6a6264b872da6e1c8617b9d50885c2e7d398 |
|
MD5 | 27cf803f2d8ce6dde84b86a20de13bf9 |
|
BLAKE2b-256 | 3064123bcd59ef6bf3719ed933453a3c67a9c3d645825bedcc1b5a41cf7e733c |
Hashes for quickner-0.0.1a13-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e4cdad45b9dcd5f8d132c1822a1bfe586b02c42b37c41d686c9d7706fa9e075 |
|
MD5 | 6e80fe34ca5e304c44e54779431f3d1f |
|
BLAKE2b-256 | 921e580f814ade803fd9989dd41464e833309aa26d629e6017567f3399c7c10c |
Hashes for quickner-0.0.1a13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eb046d9c6e62950308d5dbca648090cf9307c27ef368b009dabdf867fb92430 |
|
MD5 | 0db778b754c523e4d25528d5be161863 |
|
BLAKE2b-256 | 0b1f44c973f8d722ce6f84b67a6cb30b2fd1c8e73ef1e4e39c9d6b130502e102 |
Hashes for quickner-0.0.1a13-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597eadba0397cb806135115ca781de1dfa06a63e0f5e39088aa950dedb23ebdc |
|
MD5 | 36021ac939af5f5ab8e69b668f5965c4 |
|
BLAKE2b-256 | dae8af70b7538dde5f454b3e153046951313c883887cdff68292c5cb422c6731 |
Hashes for quickner-0.0.1a13-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9cf7da2e0379401ab2a19a61df9e7bedcf95391662360c051fb89b4fcb9495c |
|
MD5 | cd3618bf96625f6c96c3f19647477f94 |
|
BLAKE2b-256 | a7395a6bb6a81db7338fc139c72afd9468b601ea8e5e7213bdb168f841eeb2af |
Hashes for quickner-0.0.1a13-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07c6ef8816a60d237fc949fdcba759072a8e057b9ef30c4c41f4387b53e5b121 |
|
MD5 | 9b554960c6c04552f72cee2eb5c6f38a |
|
BLAKE2b-256 | 3fb74427a6a8c70184a49f9f59dc7218f58eb54a861ea9cbe05f41f1f8a44c65 |
Hashes for quickner-0.0.1a13-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b530b97f144482acc8c22207841b4af6c55e5b8f31e525c5deb006539a4839d |
|
MD5 | 63ea45a212bfc2fc8acecf2909ca9590 |
|
BLAKE2b-256 | 2727aa711106c8f94227c8c4b5bd511a8ef6513f037476e1c41149f5d8e30e03 |