All Projects → sagorbrur → Bnlp

sagorbrur / Bnlp

Licence: mit
BNLP is a natural language processing toolkit for Bengali Language.

Projects that are alternatives of or similar to Bnlp

Pytorch Bert Crf Ner
KoBERT와 CRF로 만든 한국어 개체명인식기 (BERT+CRF based Named Entity Recognition model for Korean)
Stars: ✭ 236 (+85.83%)
Mutual labels:  jupyter-notebook, named-entity-recognition, ner
Turkish Bert Nlp Pipeline
Bert-base NLP pipeline for Turkish, Ner, Sentiment Analysis, Question Answering etc.
Stars: ✭ 85 (-33.07%)
Mutual labels:  jupyter-notebook, named-entity-recognition, ner
Ner blstm Crf
LSTM-CRF for NER with ConLL-2002 dataset
Stars: ✭ 51 (-59.84%)
Mutual labels:  jupyter-notebook, named-entity-recognition, ner
Multilstm
keras attentional bi-LSTM-CRF for Joint NLU (slot-filling and intent detection) with ATIS
Stars: ✭ 122 (-3.94%)
Mutual labels:  jupyter-notebook, named-entity-recognition, ner
Bert Sklearn
a sklearn wrapper for Google's BERT model
Stars: ✭ 182 (+43.31%)
Mutual labels:  jupyter-notebook, named-entity-recognition, ner
Bert Multitask Learning
BERT for Multitask Learning
Stars: ✭ 380 (+199.21%)
Mutual labels:  jupyter-notebook, named-entity-recognition, ner
Jointre
End-to-end neural relation extraction using deep biaffine attention (ECIR 2019)
Stars: ✭ 41 (-67.72%)
Mutual labels:  named-entity-recognition, ner
Nagisa Tutorial Pycon2019
Code for PyCon JP 2019 talk "Python による日本語自然言語処理 〜系列ラベリングによる実世界テキスト分析〜"
Stars: ✭ 46 (-63.78%)
Mutual labels:  jupyter-notebook, named-entity-recognition
Phonlp
PhoNLP: A BERT-based multi-task learning toolkit for part-of-speech tagging, named entity recognition and dependency parsing (NAACL 2021)
Stars: ✭ 56 (-55.91%)
Mutual labels:  named-entity-recognition, ner
Torchcrf
An Inplementation of CRF (Conditional Random Fields) in PyTorch 1.0
Stars: ✭ 58 (-54.33%)
Mutual labels:  named-entity-recognition, ner
Wikipedia ner
📖 Labeled examples from wiki dumps in Python
Stars: ✭ 61 (-51.97%)
Mutual labels:  jupyter-notebook, named-entity-recognition
Bert Bilstm Crf Pytorch
bert-bilstm-crf implemented in pytorch for named entity recognition.
Stars: ✭ 71 (-44.09%)
Mutual labels:  jupyter-notebook, named-entity-recognition
Named entity recognition
中文命名实体识别(包括多种模型:HMM,CRF,BiLSTM,BiLSTM+CRF的具体实现)
Stars: ✭ 995 (+683.46%)
Mutual labels:  named-entity-recognition, ner
Nlp Experiments In Pytorch
PyTorch repository for text categorization and NER experiments in Turkish and English.
Stars: ✭ 35 (-72.44%)
Mutual labels:  named-entity-recognition, ner
Tf ner
Simple and Efficient Tensorflow implementations of NER models with tf.estimator and tf.data
Stars: ✭ 876 (+589.76%)
Mutual labels:  named-entity-recognition, ner
Chinesener
中文命名实体识别,实体抽取,tensorflow,pytorch,BiLSTM+CRF
Stars: ✭ 938 (+638.58%)
Mutual labels:  named-entity-recognition, ner
Bond
BOND: BERT-Assisted Open-Domain Name Entity Recognition with Distant Supervision
Stars: ✭ 96 (-24.41%)
Mutual labels:  named-entity-recognition, ner
Bi Lstm Crf Ner Tf2.0
Named Entity Recognition (NER) task using Bi-LSTM-CRF model implemented in Tensorflow 2.0(tensorflow2.0 +)
Stars: ✭ 93 (-26.77%)
Mutual labels:  named-entity-recognition, ner
Ner Evaluation
An implementation of a full named-entity evaluation metrics based on SemEval'13 Task 9 - not at tag/token level but considering all the tokens that are part of the named-entity
Stars: ✭ 126 (-0.79%)
Mutual labels:  named-entity-recognition, ner
Yedda
YEDDA: A Lightweight Collaborative Text Span Annotation Tool. Code for ACL 2018 Best Demo Paper Nomination.
Stars: ✭ 704 (+454.33%)
Mutual labels:  named-entity-recognition, ner
bnlp

Bengali Natural Language Processing(BNLP)

Build Status PyPI version release version Support Python Version Documentation Status Gitter

BNLP is a natural language processing toolkit for Bengali Language. This tool will help you to tokenize Bengali text, Embedding Bengali words, Bengali POS Tagging, Bengali Name Entity Recognition, Construct Neural Model for Bengali NLP purposes.

Installation

PIP installer(Python: 3.5, 3.6, 3.7, 3.8 tested okay, OS: linux, windows tested okay )

pip install bnlp_toolkit

or Upgrade

pip install -U bnlp_toolkit

Pretrained Model

Download Link

Training Details

  • Sentencepiece, Word2Vec, Fasttext, GloVe model trained with Bengali Wikipedia Dump Dataset
  • SentencePiece Training Vocab Size=50000
  • Fasttext trained with total words = 20M, vocab size = 1171011, epoch=50, embedding dimension = 300 and the training loss = 0.318668,
  • Word2Vec word embedding dimension = 300
  • To Know Bengali GloVe Wordvector and training process follow this repository
  • Bengali CRF POS Tagging was training with nltr dataset with 80% accuracy.
  • Bengali CRF NER Tagging was train with this data with 90% accuracy.

Tokenization

  • Basic Tokenizer

    from bnlp import BasicTokenizer
    basic_tokenizer = BasicTokenizer()
    raw_text = "আমি বাংলায় গান গাই।"
    tokens = basic_tokenizer.tokenize(raw_text)
    print(tokens)
    
    # output: ["আমি", "বাংলায়", "গান", "গাই", "।"]
    
    
  • NLTK Tokenization

    from bnlp import NLTKTokenizer
    
    bnltk = NLTKTokenizer()
    text = "আমি ভাত খাই। সে বাজারে যায়। তিনি কি সত্যিই ভালো মানুষ?"
    word_tokens = bnltk.word_tokenize(text)
    sentence_tokens = bnltk.sentence_tokenize(text)
    print(word_tokens)
    print(sentence_tokens)
    
    # output
    # word_token: ["আমি", "ভাত", "খাই", "।", "সে", "বাজারে", "যায়", "।", "তিনি", "কি", "সত্যিই", "ভালো", "মানুষ", "?"]
    # sentence_token: ["আমি ভাত খাই।", "সে বাজারে যায়।", "তিনি কি সত্যিই ভালো মানুষ?"]
    
    
  • Bengali SentencePiece Tokenization

    • tokenization using trained model
      from bnlp import SentencepieceTokenizer
      
      bsp = SentencepieceTokenizer()
      model_path = "./model/bn_spm.model"
      input_text = "আমি ভাত খাই। সে বাজারে যায়।"
      tokens = bsp.tokenize(model_path, input_text)
      print(tokens)
      text2id = bsp.text2id(model_path, input_text)
      print(text2id)
      id2text = bsp.id2text(model_path, text2id)
      print(id2text)
      
      
    • Training SentencePiece
      from bnlp import SentencepieceTokenizer
      
      bsp = SentencepieceTokenizer()
      data = "raw_text.txt"
      model_prefix = "test"
      vocab_size = 5
      bsp.train(data, model_prefix, vocab_size) 
      
      

Word Embedding

  • Bengali Word2Vec

    • Generate Vector using pretrain model

      from bnlp import BengaliWord2Vec
      
      bwv = BengaliWord2Vec()
      model_path = "bengali_word2vec.model"
      word = 'আমার'
      vector = bwv.generate_word_vector(model_path, word)
      print(vector.shape)
      print(vector)
      
      
    • Find Most Similar Word Using Pretrained Model

      from bnlp import BengaliWord2Vec
      
      bwv = BengaliWord2Vec()
      model_path = "bengali_word2vec.model"
      word = 'গ্রাম'
      similar = bwv.most_similar(model_path, word)
      print(similar)
      
      
    • Train Bengali Word2Vec with your own data

      from bnlp import BengaliWord2Vec
      bwv = BengaliWord2Vec()
      data_file = "raw_text.txt"
      model_name = "test_model.model"
      vector_name = "test_vector.vector"
      bwv.train(data_file, model_name, vector_name)
      
      
      
  • Bengali FastText

    To use fasttext you need to install fasttext manually by pip install fasttext==0.9.2

    NB: fasttext may not be worked in windows, it will only work in linux

    • Generate Vector Using Pretrained Model

      from bnlp.embedding.fasttext import BengaliFasttext
      
      bft = BengaliFasttext()
      word = "গ্রাম"
      model_path = "bengali_fasttext_wiki.bin"
      word_vector = bft.generate_word_vector(model_path, word)
      print(word_vector.shape)
      print(word_vector)
      
      
      
    • Train Bengali FastText Model

      from bnlp.embedding.fasttext import BengaliFasttext
      
      bft = BengaliFasttext()
      data = "raw_text.txt"
      model_name = "saved_model.bin"
      epoch = 50
      bft.train(data, model_name, epoch)
      
  • Bengali GloVe Word Vectors

    We trained glove model with bengali data(wiki+news articles) and published bengali glove word vectors You can download and use it on your different machine learning purposes.

    from bnlp import BengaliGlove
    glove_path = "bn_glove.39M.100d.txt"
    word = "গ্রাম"
    bng = BengaliGlove()
    res = bng.closest_word(glove_path, word)
    print(res)
    vec = bng.word2vec(glove_path, word)
    print(vec)
    
    

Bengali POS Tagging

  • Bengali CRF POS Tagging

    • Find Pos Tag Using Pretrained Model

      from bnlp import POS
      bn_pos = POS()
      model_path = "model/bn_pos.pkl"
      text = "আমি ভাত খাই।"
      res = bn_pos.tag(model_path, text)
      print(res)
      # [('আমি', 'PPR'), ('ভাত', 'NC'), ('খাই', 'VM'), ('।', 'PU')]
      
      
    • Train POS Tag Model

      from bnlp import POS
      bn_pos = POS()
      model_name = "pos_model.pkl"
      tagged_sentences = [[('রপ্তানি', 'JJ'), ('দ্রব্য', 'NC'), ('-', 'PU'), ('তাজা', 'JJ'), ('ও', 'CCD'), ('শুকনা', 'JJ'), ('ফল', 'NC'), (',', 'PU'), ('আফিম', 'NC'), (',', 'PU'), ('পশুচর্ম', 'NC'), ('ও', 'CCD'), ('পশম', 'NC'), ('এবং', 'CCD'),('কার্পেট', 'NC'), ('৷', 'PU')], [('মাটি', 'NC'), ('থেকে', 'PP'), ('বড়জোর', 'JQ'), ('চার', 'JQ'), ('পাঁচ', 'JQ'), ('ফুট', 'CCL'), ('উঁচু', 'JJ'), ('হবে', 'VM'), ('৷', 'PU')]]
      
      bn_pos.train(model_name, tagged_sentences)
      
      

Bengali NER

  • Bengali CRF NER

    • Find NER Tag Using Pretrained Model

      from bnlp import NER
      bn_ner = NER()
      model_path = "model/bn_ner.pkl"
      text = "সে ঢাকায় থাকে।"
      result = bn_ner.tag(model_path, text)
      print(result)
      # [('সে', 'O'), ('ঢাকায়', 'S-LOC'), ('থাকে', 'O')]
      
      
    • Train NER Tag Model

      from bnlp import NER
      bn_ner = NER()
      model_name = "ner_model.pkl"
      tagged_sentences = [[('ত্রাণ', 'O'),('ও', 'O'),('সমাজকল্যাণ', 'O'),('সম্পাদক', 'S-PER'),('সুজিত', 'B-PER'),('রায়', 'I-PER'),('নন্দী', 'E-PER'),('প্রমুখ', 'O'),('সংবাদ', 'O'),('সম্মেলনে', 'O'),('উপস্থিত', 'O'),('ছিলেন', 'O')], [('ত্রাণ', 'O'),('ও', 'O'),('সমাজকল্যাণ', 'O'),('সম্পাদক', 'S-PER'),('সুজিত', 'B-PER'),('রায়', 'I-PER'),('নন্দী', 'E-PER'),('প্রমুখ', 'O'),('সংবাদ', 'O'),('সম্মেলনে', 'O'),('উপস্থিত', 'O'),('ছিলেন', 'O')], [('ত্রাণ', 'O'),('ও', 'O'),('সমাজকল্যাণ', 'O'),('সম্পাদক', 'S-PER'),('সুজিত', 'B-PER'),('রায়', 'I-PER'),('নন্দী', 'E-PER'),('প্রমুখ', 'O'),('সংবাদ', 'O'),('সম্মেলনে', 'O'),('উপস্থিত', 'O'),('ছিলেন', 'O')]]
      
      bn_ner.train(model_name, tagged_sentences)
      
      

Bengali Corpus Class

  • Stopwords and Punctuations

    from bnlp.corpus import stopwords, punctuations
    
    stopwords = stopwords() 
    print(stopwords)
    print(punctuations)
    
    
  • Remove stopwords from Text

    from bnlp.corpus import stopwords
    from bnlp.corpus.util import remove_stopwords
    
    stopwords = stopwords()
    raw_text = 'আমি ভাত খাই।' 
    result = remove_stopwords(raw_text, stopwords)
    print(result)
    # ['ভাত', 'খাই', '।']
    

Contributor Guide

Check CONTRIBUTING.md page for details.

Thanks To

Contributor List

Extra Contributor

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].