Skip to main content

Weak Named Entity Recognition (NER) Model

This package utilizes three systems for labeling named entities in text. The first system uses files containing lists of words and expressions of a certain NER Entity. The second system uses regex patters to recognize part of speech patterns. The third system uses rules to break ambiguity when the first two systems cannot decide on a label.

Installation

The Weak NER can be installed from PyPi:

pip install weak_ner

Usage

NER Classes Accepted

This project utilizes the following NER labels and their tokens are as follow:

'Financial': 'FIN',
'Generic': 'GEN',
'Company': 'COMP',
'Number': 'NUMBER',
'Document': 'DOC',
'Location': 'LOC',
'Person': 'PERS',
'Phone': 'PHONE',
'Address': 'ADDR',
'Email': 'EMAIL',
'Date': 'DATE',
'Week Day': 'WD',
'Money': 'MONEY',
'Relatives': 'REL',
'Vocatives': 'VOC'

Some additional information is used to identify where the recognized entity begins and ends.

The letter B indicates the beginning of the CLASS class entity
The letter I indicates that the respective token is a continuation of the class with the name CLASS started
The letter O indicates that no entity related to the token was found

For example, the sentence ligar internet a cabo! would be classified as: O O B-GEN I-GEN I-GEN O.

Where B-GEN represents the beginning of the GEN entity (token "internet") and the next two tokens are the continuation of the entity (tokens "a cabo"). In this way, the entity found in the sentence would be "internet a cabo" of the GEN class

Text Pre Processing

All text used is pre processed by the default utilizing the following operations:

  • Case lowering
  • Adding space around punctuation
  • Removing non-ASCII characters

It can also optionally perform the following tokenizations:

  • E-mails
  • Urls
  • Numbers
  • Codes

In order to use the optional pre processing the user needs to pass a list containing EMAIL, URL, NUMBER and/or CODE. It can be passed in the instatiation of the class as shown bellow:

tokenization_options = ['EMAIL', 'CODE']
weak_ner = WeakNER('directory_path/', tokenization_options)

List Based Model

Files

In order to label a string using the list based model the user needs to create a directory containing the following files:

substantivos_meses  
substantivos_nomes  
substantivos_sobrenome
substantivos_empresas
substantivos_empresas_internacionais
substantivos_documentos
substantivos_vocativos
substantivos_paises
substantivos_cidades
substantivos_continentes
substantivos_estados
substantivos_financeiros
substantivos_dias_da_semana
substantivos_animais
substantivos_parentescos
substantivos_carros
pronomes
artigos
preposicoes
interjeicoes 

In which the contents should be one word of that class per line. For example the file artigos.txt would contain the words:

a  
no  
nas
nas
num 
numa
nuns 
numas

Weak Labeling

The default weak labeling utilizes two steps:

  • The first step is the labeling module WeakNERModel created with the files input in the class.
  • The second step is the label correction module WeakNERRules.

In order to use the default pipeline to label a sentence the user needs to first instantiate the class passing the path of the directory where the files are stored. The user then can use this class to label a sentence by passing it and its POS Tags to the class:

weak_ner = WeakNER('directory_path/')
sentence = "meu nome é Gabriel"
postags = 'PRON SUBS VERB SUBS'
labeled_sentence = weak_ner.label_sentence(sentences, postags)

And the user should receive back the result:

'O B-GEN O B-PERS'

The user can also specify which optional text pre processing will be applied on the sentence:

tokenization_options = ['EMAIL', 'CODE']
weak_ner = WeakNER('directory_path/', tokenization_options)
 sentence = "meu nome é Gabriel e meu contato é research@email.com"
postags = 'PRON SUBS VERB SUBS PREP PRON SUBS VERB SUBS'
labeled_sentence = weak_ner.label_sentence(sentences, postags)

And the user should receive back the result:

'O B-GEN O B-PERS O O O O O B-EMAIL'

Contribute

If this is the first time you are contributing to this project, first create the virtual environment using the following command:

conda env create -f env/environment.yml

Then activate the environment:

conda activate weakner_env

To test your modifications build the package:

pip install dist\weak_ner-0.0.1-py3-none-any.whl --force-reinstall

Then run the tests:

pytest

Metadata

Release files for weak-ner 0.0.1

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

Source distribution (sdist)

Source distribution for weak-ner 0.0.1
File Size Uploaded Provenance
weak-ner-0.0.1.tar.gz 15.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for weak-ner 0.0.1
File Interpreter ABI Platform
weak_ner-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.7 kB

Release files / weak-ner-0.0.1.tar.gz

Download URL weak-ner-0.0.1.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b95f7b2bab28bbb60730665fbc0e20b8a024d8a4d4cdc122738b17bdcfe7bc2d
BLAKE2b-256 checksum
How to use checksums
a4bbcd0d8b8ee4bbed8c3c70b81ead5eb0417260fe4adfc283d4db60ec028318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.6

Release files / weak_ner-0.0.1-py3-none-any.whl

Download URL weak_ner-0.0.1-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
597c9930f8c16ff55df1b03c02683d996f01eaac2204fd3143afcac17401d7f8
BLAKE2b-256 checksum
How to use checksums
43bd26e35fa33385245cb889c53894f88a9588116d369c3de33879b0e02e3ce5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.6

Security for weak-ner 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.

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