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.1a17-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09be47e443a1a549821991e8691a11c332183867587cd04b59ae1fd8466cabd1 |
|
MD5 | 1e1d390251cb3512f727f775d4324acb |
|
BLAKE2b-256 | 266f7c1c8f86e0a83df10784e3d891639b93fc8d16654f962881241d636eafb3 |
Hashes for quickner-0.0.1a17-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b064f9cd8d510c76c473485db165bec184fab623d7aafc65262026d6f47d53e5 |
|
MD5 | 3e8c250ec6938618120279174ce00726 |
|
BLAKE2b-256 | 5ee8fcfb5f094857ebb6fc94d2865cd7c0468edc975bda3ad84d194ec3a6a399 |
Hashes for quickner-0.0.1a17-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0df6991c2ece29234bace6e1d0d22531c6d75260507a2a37710c4a48a3f841c |
|
MD5 | 3335e46c47fce0a5b653628e8a0bce9a |
|
BLAKE2b-256 | 6727990a60701d8487ce759946f6a041d6f1c43d60debfdf736a9865b53e1cad |
Hashes for quickner-0.0.1a17-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96ff810ac80e277c6b1399073b1ca51c5f00a538caffba31c22dd3def967a166 |
|
MD5 | ff06bf759407d49b34c34bbc907b01ab |
|
BLAKE2b-256 | eccefd1076e2a706cffd31540181dfedabc875c9a375fbefd0b80f46f1a039f8 |
Hashes for quickner-0.0.1a17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12643916a7f6879ee33460bc5a853488e1af62fbd8380af0460f4755cc390b1d |
|
MD5 | cdf308c10cb67fe1c32ccede833bf220 |
|
BLAKE2b-256 | 12ce5a6a398c207c09994b4c1ef79df799b4d5a9463ac34cab3129422fd924be |
Hashes for quickner-0.0.1a17-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89772550bba1b9025baef03831dba7b12e7d7ed5d33b32eeb8dad646809959ed |
|
MD5 | f9682ffcea523969d0a707c494a4e65c |
|
BLAKE2b-256 | 32aa7965ab237c989d8ef723b4787da380f8c5195b959b3dc9c07f943b014931 |
Hashes for quickner-0.0.1a17-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a61d7656c887fede365bf8112025ac1bacc83c535b006caa73276e78e6b69c65 |
|
MD5 | 636b22d59a971e79589bcddea187b46e |
|
BLAKE2b-256 | 8458a07465fb453fae08976983ea971d28e91c6c3cec45ee36694f47c6167007 |
Hashes for quickner-0.0.1a17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25cbe5ff8405eee66f0aaee9f4e760dc739cb99f3ef06d9530744ab29814007b |
|
MD5 | 18a77fb8c12cb73d358803ac891a4267 |
|
BLAKE2b-256 | 366b5a8949d0a3ca1e6d2eb22b32b67f07922ddb02d0c01140b2ffabf8a9deb1 |
Hashes for quickner-0.0.1a17-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdcd31ca3b4c8091103c1c607b1888a2a38d9cc36a1e217df5fb5bb64a75fd41 |
|
MD5 | f121e86260857eabdd11cf66fb249eea |
|
BLAKE2b-256 | 6f1bf950af08d4d7b0c237505e2a5c8f89601d92c0c5c1d57792b08680cfc8e0 |
Hashes for quickner-0.0.1a17-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afc7d23294759030872f5bf52620fc0c49d67f5325e259c92ecac481059779a4 |
|
MD5 | d7494dc898ffaa519038322f3fef7203 |
|
BLAKE2b-256 | 1a7d927cfd442a7ea0ab5c602f5c2e13cfed981886b627c282449e4884bb7a00 |
Hashes for quickner-0.0.1a17-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 785c3dc5561d3dcea790d0f58cea8c669d202c645083680287a61927ef812179 |
|
MD5 | c61117f6db722c784f1af64eecaaf0c0 |
|
BLAKE2b-256 | 4b0f6696888dd2721d7a60d8620fa81dd98621f6d4babbb8d111862b9549035d |
Hashes for quickner-0.0.1a17-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da79af97b6b02113b31438c4ddd13759bc401cd47a06ab398b2b4e3d3c264196 |
|
MD5 | 22837d7fdd11444f3e2d02ea77ba3b0e |
|
BLAKE2b-256 | 1f5ecf5d1fe1b5790af26ffa883f585c738f82a145811fb3d667dceb7317d7c0 |
Hashes for quickner-0.0.1a17-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76b8064e5993e58f9d0af7dc396c5a6a6a0b61be55393ddc0cd11cbb2c2b4940 |
|
MD5 | 2e4251a8425db95dc21a891594293204 |
|
BLAKE2b-256 | 9acb9634a3c57c3fbdb1fd9c8690bcaca0b14746ee1b38902f78453c81534f27 |
Hashes for quickner-0.0.1a17-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8874ff571ab6dd396eebea2a2f41265d1fa7cbec1d9a2476708cd2f51003e2d0 |
|
MD5 | 6f5220b8e58b09159a99ffc37eb8a87e |
|
BLAKE2b-256 | 75d6d228ad80858bc60dfaa4a6e953cf40f0c52af39d866557b1baf3a4b9c6f9 |
Hashes for quickner-0.0.1a17-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85dbc92611c068d15047fe0ab3e80a4e6e170b62c99bdc79913e2fe24ea791b2 |
|
MD5 | f13ef73d164117839837e104655f6b2d |
|
BLAKE2b-256 | e7cdfc0d656f1cbadb88394482ddb9f9a6f1c73a1e0acce020419208e7aa24ae |
Hashes for quickner-0.0.1a17-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c7cf64e3edbd677fc19173f6d923c862fc8f89cfc690ba7af2dc01deb436533 |
|
MD5 | 3affd85f01536b17399dd1e923e82d48 |
|
BLAKE2b-256 | 6fbd32d7d11ef5457de3349c0ac89ba28bbda3a4a4e35e744327f1a61c532f17 |
Hashes for quickner-0.0.1a17-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f22442d6dfbed9edf51f4d8ee6db56530b7494b633fa5711b699f4c618e803c |
|
MD5 | 47a88c37f52553ac7d60d78244f89cdc |
|
BLAKE2b-256 | 2cfaf33b538dd9a612697a9bad800014fd5f9fbe73b713713360da1cd3069f57 |
Hashes for quickner-0.0.1a17-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08f5f6dee9abc0bf9a58e5a562bb07bfa032ab8bfdcba867bfc8334830edc936 |
|
MD5 | 5de567deea9ad8ed6523803bd2ea92fe |
|
BLAKE2b-256 | 741ed5cdd6fc65f1323c001959b30956f82742ce3674d9ff4c15674aa7c89949 |