Code Monkey home page Code Monkey logo

mltb2's Introduction

Machine Learning Toolbox 2 - MLTB2

MIT License Python Version pypi Poetry
pytest Static Code Checks Build & Deploy Doc GitHub issues

๐Ÿ“ฆ A box full of machine learning tools. ๐Ÿ“ฆ

Installation

MLTB2 is available at the Python Package Index (PyPI). It can be installed with pip:

pip install mltb2

For many modules optional dependencies are necessary. Those optional dependencies must be installed when you want to use the module. To install those module specific dependencies see the description of the individual modules.

Licensing

Copyright (c) 2023-2024 Philip May
Copyright (c) 2023-2024 Philip May, Deutsche Telekom AG

Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License by reviewing the file LICENSE in the repository.

mltb2's People

Contributors

philipmay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mltb2's Issues

Add Optuna tool to widen HP ranges.

new_trials = []

# copy trial and add param
for trial in study.trials:
    # ori: FloatDistribution(high=2e-05, log=False, low=2e-09, step=None)
    trial.distributions["learning_rate"] = optuna.distributions.FloatDistribution(2e-9, 2e-3)
    print(trial)
    new_trials.append(trial)

Add Jaccard Similarity

like so

def jaccard_similarity(text1, text2, somajo_tokenizer):

    def get_token_set(text):
        sentences = somajo_tokenizer.tokenize_text([text])
        tokens = [t.text.lower() for sentence in sentences for t in sentence]
        #token_ngrams = list(ngrams(sequence=tokens, n=2))
        #token_set = set(tokens + token_ngrams)
        token_set = set(tokens)
        return token_set

    token_set1 = get_token_set(text1)
    token_set2 = get_token_set(text2)
    intersection = token_set1.intersection(token_set2)
    union = token_set1.union(token_set2)
    jaccard_similarity = float(len(intersection)) / len(union)
    return jaccard_similarity

Add language identification tools

Like this:

class LanguageIdentification:

    def __init__(self):
        pretrained_lang_model = "/home/phmay/models/lid.176.bin"
        self.model = fasttext.load_model(pretrained_lang_model)

    def predict_lang(self, text):
        predictions = self.model.predict(text, k=2) # returns top 2 matching languages
        #print(predictions)
        if '__label__de' in predictions[0]:
            return predictions[1][predictions[0].index('__label__de')]
        else:
            return 0.0

li = LanguageIdentification()

sentences = [s for s in sentences if li.predict_lang(s) > 0.9]

Add file write and read tool.

like this:

with gzip.open(write_filename, 'w') as fout:
    fout.write(json.dumps(some_data, indent=2).encode('utf-8')) 

Add translation tool

like this

en2de = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-de',
                       checkpoint_file='model1.pt:model2.pt:model3.pt:model4.pt',
                       tokenizer='moses', bpe='fastbpe')
_ = en2de.eval()  # disable dropout
_ = en2de.cuda()  # use GPU

Add text clean tool.

  • detect strange unicode characters
  • remove strange whitespace like: "\u200b" or '\xa0'
  • remove multiple whitespaces

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.