Skip to main content

TakeBlipMessageStructurer Package

Data & Analytics Research

Overview

Message Structurer is an AI model capable of assisting in structuring text messages.

For each message sent, a list is obtained with the main elements found in the analyzed sentence.

The elements found can be more than one word and have the following components:

  • value: sequence of characters found in the sentence corresponding to the element
  • lowercase: is the value found previously in lower case
  • postags: element grammar class
  • type: type of element found (class of entity found or postagging)

Here are presented these content:

Run

To run the Message Structurer is possible in two ways: for a single sentence e for a batch of sentences.

Single Sentence

To predict a single sentence, the method predict_line should be used. Example of initialization e usage:

  1. Import main packages;
  2. Initialize model variables;
  3. Read PosTagging, NER model and embedding model;
  4. Initialize and usage.

An example of the above steps could be found in the python code below:

  1. Import main packages:
import json
import torch

from TakeBlipNer.predict import NerPredict
from TakeBlipPosTagger.predict import PosTaggerPredict
from TakeBlipMessageStructurer.utils import load_fasttext_embeddings
from TakeBlipMessageStructurer.predict.messagestructurer import MessageStructurer
  1. Initialize model variables:

In order to predict the sentences tags, the following variables should be created:

  • postag_model_path: string with the path of PosTagging pickle model;
  • postag_label_path: string with the path of PosTagging pickle labels;
  • ner_model_path: string with the path of NER pickle model;
  • ner_label_path: string with the path of NER pickle labels;
  • wordembed_path: string with FastText embedding files;
  • padding_string: string which represents the pad token;
  • unknown_string: a string which represents unknown token;
  • sentence: string with sentence to be structured.

Example of variables creation:

postag_model_path = '*.pkl'
postag_label_path = '*.pkl'
ner_label_path = '*.pkl'
ner_model_path = '*.pkl'
wordembed_path = '*.kv'
padding_string = '<pad>'
unk_string = '<unk>'
sentence = 'SENTENCE EXAMPLE TO PREDICT'
  1. Read Embedding, PosTagging and NER model:
embedding_model = load_fasttext_embeddings(embedding_path, pad_string)

postagging_model = torch.load(postag_model_path)
postag_predicter = PosTaggerPredict(
    model=postagging_model,
    label_path=postag_label_path,
    embedding=embedding_model)

ner_model = torch.load(ner_model_path)
ner_predicter = NerPredict(
    pad_string=pad_string,
    unk_string=unk_string,
    model=ner_model,
    postag_model=postag_predicter,
    label_path=ner_label_path)
  1. Initialize tags to be removed, Message Structurer and usage:
tags = ['INT', 'ART', 'PRON', 'SIMB', 'PON', 'CONJ']
message_structurer = MessageStructurer(ner_model=ner_predicter)

print(message_structurer.structure_message(sentence, tags))

Batch

To predict a single sentence, the method predict_line should be used. Example of initialization e usage:

  1. Import main packages;
  2. Initialize model variables;
  3. Read PosTagging, NER model and embedding model;
  4. Read file to be structured;
  5. Initialize and usage;
  6. Package usage.

An example of the above steps could be found in the python code below:

  1. Import main packages:
import json
import torch

from TakeBlipNer.predict import NerPredict
from TakeBlipPosTagger.predict import PosTaggerPredict
from TakeBlipMessageStructurer.utils import load_fasttext_embeddings
from TakeBlipMessageStructurer.predict.messagestructurer import MessageStructurer
  1. Initialize model variables:

In order to predict the sentences tags, the following variables should be created:

  • postag_model_path: string with the path of PosTagging pickle model;
  • postag_label_path: string with the path of PosTagging pickle labels;
  • ner_model_path: string with the path of NER pickle model;
  • ner_label_path: string with the path of NER pickle labels;
  • wordembed_path: string with FastText embedding files;
  • padding_string: string which represents the pad token;
  • unknown_string: a string which represents unknown token.

Example of variables creation:

postag_model_path = '*.pkl'
postag_label_path = '*.pkl'
ner_label_path = '*.pkl'
ner_model_path = '*.pkl'
wordembed_path = '*.kv'
padding_string = '<pad>'
unk_string = '<unk>'
  1. Read Embedding, PosTagging and NER model:
embedding_model = load_fasttext_embeddings(embedding_path, pad_string)

postagging_model = torch.load(postag_model_path)
postag_predicter = PosTaggerPredict(
    model=postagging_model,
    label_path=postag_label_path,
    embedding=embedding_model)

ner_model = torch.load(ner_model_path)
ner_predicter = NerPredict(
    pad_string=pad_string,
    unk_string=unk_string,
    model=ner_model,
    postag_model=postag_predicter,
    label_path=ner_label_path)
  1. Read file to be structured:
  • In order to predict a batch, will need a json file as follows:
{
    "sentences": [
                    {
                        "id": 1, 
                        "sentence": "sentence_1"
                    }, 
                    {
                        "id": 2, 
                        "sentence": "sentence_2"
                    }
                ]
}
  • Reading json file:
file = open(path_sentences)
sentence = json.load(file)['Sentences']
  1. Initialize tags to be removed and Message Structurer:
tags = ['INT', 'ART', 'PRON', 'SIMB', 'PON', 'CONJ']
message_structurer = MessageStructurer(ner_model=ner_predicter)
  1. Package usage
  • In order to use the package, some variables should be initialized:
    • input_path: a string with path of the .csv file;
    • batch_size: number of sentences which will be predicted at the same time;
    • shuffle: a boolean representing if the dataset is shuffled;
    • use_pre_processing: a boolean indicating if sentence will be preprocessed;

Example of variable creations:

path_sentences = '*.json'
batch_size = 64
shuffle = True
use_pre_processing = True
  • Structuring a batch of sentences:
print(messagestructurer.structure_message_batch(
    batch_size=batch_size,
    shuffle=shuffle,
    use_pre_processing=use_pre_processing,
    sentences=sentence,
    tags_to_remove=tags))

Metadata

Release files for TakeBlipMessageStructurer 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 TakeBlipMessageStructurer 0.0.1
File Size Uploaded Provenance
TakeBlipMessageStructurer-0.0.1.tar.gz 10.8 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 21.4 kB

Release files / TakeBlipMessageStructurer-0.0.1.tar.gz

Download URL TakeBlipMessageStructurer-0.0.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
806cce4293522695504735839757ad5cdd05183e929a77ca6d4bef2032a05824
BLAKE2b-256 checksum
How to use checksums
498f9b5d76eb9f60a6a1df2ec54cd709cc0a86ad62554243c99ee4b1f2021b78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

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

Download URL TakeBlipMessageStructurer-0.0.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
985729d726d32789ad6b555a24004cb08a89ca9f37c98f66be3927ae6d6d600e
BLAKE2b-256 checksum
How to use checksums
00f8b47937d5239244d3242254f10726af18ab60c9f1a80751d057de2d9e9279
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

Security for TakeBlipMessageStructurer 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