Skip to main content

Utils package for loading datasets and models

Project description

mlutils

Function utils to load work with datasets and models

how to use it

clone the repository into your folder

cd myproject
git clone https://github.com/nluninja/mlutils.git

import the module into your project, and call the needed utils

import mlutils

utils list

model utils

Utils to work with models.

compute_prediction_latency(dataset, model, n_instances=-1):
    """Compute prediction latency of a model.

def from_encode_to_literal_labels(y_true, y_pred, idx2tag):
    '''Transform sequences of encoded labels in sequences of string labels'''

keras utils

Utils to load embeddings, to create LSTMs, and to memory usage: the memory functions work with Tensorflow only

def get_model_memory_usage(batch_size, model):
    """Return memory usage of a model in MB given the batch size"""

def print_model_memory_usage(batch_size, model):
    """Print memory usage of a model in MB given the batch size"""

def load_glove_embedding_matrix(path, word_index, embed_dim):
    """Load Glove embeddings.    """

def load_w2v_nlpl_embedding_matrix(path, word_index, embed_dim):
    """Load NLPL Italian embedding."""

def create_BiLSTM(vocabulary_size, seq_len, n_classes, hidden_cells=128, 
                  embed_dim=32, drop=0.5, use_glove=False, glove_matrix=None):
    """Create a BiLSTM model using keras, given its parameters"""

def create_paper_BiLSTM(vocabulary_size, seq_len, n_classes, hidden_cells=200, 
                  embed_dim=100, drop=0.4, use_glove=False, glove_matrix=None):
    """Create a BiLSTM model using keras, given its parameters"""

def remove_flat_padding(X, y_true, y_pred, pad=0):
    """Remove padding predictions and flatten the list of sequences"""

def remove_seq_padding(X, y_true, y_pred, pad=0):
    """Remove padding predictions from list of sequences"""

I/O utils

Utils to load datasets such as conll, wikiner.

def open_read_from_url(url):
    """ Take in input an url to a .txt file and return the list of its raws"""

def read_raw_conll(url_root, dir_path, filename):
    """Read a file which contains a conll03 dataset"""

def is_real_sentence(only_token, sentence):
    """Chek if a sentence is a real sentence or a document separator"""

def load_conll_data(filename, url_root=CONLL_URL_ROOT, dir_path='', 
                    only_tokens=False):
    """ Take an url to the raw .txt files that you can find the repo linked above,
    load data and save it into a list of tuples data structure. """

def _df_to_xy(df):
    """Transform anerd dataframe in X, y sets."""

def load_wikiner(path, token_only=False):
    """Load WikiNER dataset."""

def _get_digits(text):
    """Preprocess numbers in tokens accordingly to itWac word embedding."""

def _normalize_text(word):
    """Preprocess word in order to match with the itWac embedding vocabulary"""

def itwac_preprocess_data(sentences):
    """Preprocess text in order to match with the itWac embedding vocabulary"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dvtm_utils-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dvtm_utils-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file dvtm_utils-0.1.0.tar.gz.

File metadata

  • Download URL: dvtm_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for dvtm_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 762dd249df1d7e59cc0e3928e73e39291696d0d54ed6e1826dd67ec3f98abdbb
MD5 0b7189e67c9ba6a21f17093d017185fd
BLAKE2b-256 cd64840b6a7f129fb8a569fc2ed96b69c7cae4e9fd40fb99b44f4594714085a9

See more details on using hashes here.

File details

Details for the file dvtm_utils-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dvtm_utils-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for dvtm_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d3e7a489703da6b78c267a738e7476ec2e0c7806a1adb41f9faf82eb816cc45
MD5 0076acb955b698b7197eb2ca51c66af5
BLAKE2b-256 00ab7bcc38dacde4c4d7af55e1f1c8f87119ef38498901b961a6d49fcf99d79a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page