Giter VIP home page Giter VIP logo

bnaug's Introduction

bnaug (Bangla Text Augmentation)

bnaug is a text augmentation tool for Bangla text.

Installation

pip install bnaug
  • Dependencies
    • pytorch >=1.7.0

Demo Notebook

Necessary Model Links

Sentence Augmentation

Token Replacement

  • Mask generation based augmentation

    from bnaug.sentence import TokenReplacement
    
    tokr = TokenReplacement()
    text = "আমি ঢাকায় বাস করি।"
    output = tokr.masking_based(text, sen_n=5)
  • Word2Vec based augmentation

    from bnaug.sentence import TokenReplacement
    
    tokr = TokenReplacement()
    text = "আমি ঢাকায় বাস করি।"
    model = "msc/bangla_word2vec/bnwiki_word2vec.model"
    output = tokr.word2vec_based(text, model=model, sen_n=5, word_n=5)
    print(output)
  • Glove based augmentation

    from bnaug.sentence import TokenReplacement
    
    tokr = TokenReplacement()
    text = "আমি ঢাকায় বাস করি।"
    vector = "msc/bn_glove.300d.txt"
    output = tokr.glove_based(text, vector_path=vector, sen_n=5, word_n=5)
    print(output)

Back Translation

Back translation based augmentation first translate Bangla sentence to English and then again translate the English to Bangla.

from bnaug.sentence import BackTranslation

bt = BackTranslation()
text = "বাংলা ভাষা আন্দোলন তদানীন্তন পূর্ব পাকিস্তানে সংঘটিত একটি সাংস্কৃতিক ও রাজনৈতিক আন্দোলন। "
output = bt.get_augmented_sentences(text)
print(output)

Text Generation

  • Paraphrase generation
from bnaug.sentence import TextGeneration

tg = TextGeneration()
text = "বিমানটি যখন মাটিতে নামার জন্য এয়ারপোর্টের কাছাকাছি আসছে, তখন ল্যান্ডিং গিয়ারের খোপের ঢাকনাটি খুলে যায়।"
output = tg.parapharse_generation(text)
print(output)

Random Augmentation

  • Random remove part and generate new sentence

    At present it's removing word, stopwords, punctuations, numbers and generate new sentences

    from bnaug.sentence import RandomAugmentation
    
    raug = RandomAugmentation()
    sentence = "আমি ১০০ বাকি দিলাম"
    output = raug.random_remove(sentence)
    print(output)

    or apply individually

    from bnaug import randaug
    
    text = "১০০ বাকি দিলাম"
    output = randaug.remove_digits(text)
    print(output)
    
    text = "১০০! বাকি দিলাম?"
    output = randaug.remove_punctuations(text)
    print(output)
    
    text = "আমি ১০০ বাকি দিলাম"
    randaug.remove_stopwords(text)
    print(output)
    
    text = "আমি ১০০ বাকি দিলাম"
    randaug.remove_random_word(text)
    print(output)
    
    text = "আমি ১০০ বাকি দিলাম"
    randaug.remove_random_char(text)
    print(output)

Inspired from

bnaug's People

Contributors

menon92 avatar sagorbrur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

menon92

bnaug's Issues

Failed building wheel for gensim

I can't seem to install bnaug with !pip install bnaug in Google Colab using Python version 3.10.11.

I am getting the following errors.

Building wheels for collected packages: gensim
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for gensim (setup.py) ... error
  ERROR: Failed building wheel for gensim
  Running setup.py clean for gensim
Failed to build gensim
Installing collected packages: tokenizers, sentencepiece, python-crfsuite, sklearn-crfsuite, huggingface-hub, gensim, transformers, bnlp-toolkit, bnaug
  Attempting uninstall: gensim
    Found existing installation: gensim 4.3.1
    Uninstalling gensim-4.3.1:
      Successfully uninstalled gensim-4.3.1
  error: subprocess-exited-with-error
  
  × Running setup.py install for gensim did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Running setup.py install for gensim ... error
  Rolling back uninstall of gensim
  Moving to /usr/local/lib/python3.10/dist-packages/gensim-4.3.1.dist-info/
   from /usr/local/lib/python3.10/dist-packages/~ensim-4.3.1.dist-info
  Moving to /usr/local/lib/python3.10/dist-packages/gensim/
   from /usr/local/lib/python3.10/dist-packages/~ensim
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> gensim

note: This is an issue with the package mentioned above, not pip.

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.