Skip to content

TonmoyTalukder/Bangla-Key2Text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

139 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bangla Key2Text: Text Generation from Keywords for a Low Resource Language

This repository contains the code and datasets used in the paper titled "Bangla Key2Text: Text Generation from Keywords for a Low Resource Language" submitted at The 2025 Annual Conference of the North American Chapter of the Association for Computational Linguistics.

To download git lfs files, visit StackOverflow answer on How to download git-lfs files using the oid sha256 information.


Table of Contents

Text Generation Model

Find in Hugging Face

🤗 Text Generation Model (Currently, the privacy is in private mode, after acceptance of the paper, it will be released in public mode.)

Run using the below code

!pip install sentencepiece
!pip install transformers
!pip install git+https://github.com/csebuetnlp/normalizer
!pip install torch

import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from normalizer import normalize

model_dir = '***/***'
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = AutoModelForSeq2SeqLM.from_pretrained(model_dir)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

def predict(key): # Function to generate text from given keywords
    input_ids = tokenizer.encode(key, return_tensors='pt',add_special_tokens=True).to(device)

    with torch.no_grad():
      outputs = model.generate(
          input_ids=input_ids,
          max_length =512,
          do_sample=True,
          early_stopping =True,
          num_return_sequences = 1,
          top_k= 50,
          top_p= 0.95,
          repetition_penalty= 2.5,
          length_penalty= 1.0)

    preds = [tokenizer.decode(g,skip_special_tokens=True,clean_up_tokenization_spaces=True) for g in outputs]

    generated_text = preds[0]
    return generated_text


keywords = "কেমন ডাটাসেট সময় ভাই বানাতে"
predict(normalize(keywords)) # This normalize function will preprocess (clean) the sentence. 
# Output: "ভাই, ডাটাসেট বানাতে কেমন সময় লাগে?"

Bangla Keyword Extractor

We have developed a keyword extractor for Bangla sentences. This extractor extracts keywords based on the attention or importance of words in a sentence, calculating token-wise BERT embeddings.

Find in Hugging Face

🤗 bn-keyword-extractor (Currently, the privacy is in private mode, after acceptance of the paper, it will be released in public mode.)

We have uploaded this code as a PyPI project, which will be public after acceptance. bn-keyword-extractor

Run using the below code

!pip install bn-keyword-extractor

from keyword_extractor import KeywordExtractor
extractor = KeywordExtractor()
text = "আমি বাংলায় গান শোনা ভালবাসি।"
keywords = extractor.extract_keywords(text)
print(keywords) 

Output: ['শোনা', 'ভালবাসি', 'বাংলায়', 'গান']

Dataset: Bangla Key2Text 2.6 Million

We have uploaded our dataset, which was developed using our Bangla Keyword Extractor, as a Huggingface Dataset.

🤗 Bangla-Key2Text-2.6Million (Currently, the privacy is in private mode, after acceptance of the paper, it will be released in public mode.)

Run using the below code

!pip install datasets

from datasets import load_dataset

dataset = load_dataset("***/***", split="train") #split="test"
dataset

Model Weights

After acceptance model weights will be uploaded.

About

In this work, we introduce Bangla Key2Text, a fine-tuned encoder-decoder (multilingual T5) model that addresses the challenge of generating text from keywords in Bengali.

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors