Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sagorbrur committed Apr 29, 2021
2 parents 7813781 + 72a6a31 commit a8be3b6
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 11 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ NB: No `GPU` Needed. Totally `CPU` based
```py
from bntranslit import BNTransliteration

bntrans = BNTransliteration()

model_path = "bntranslit_model.pth"
word = "vaat"
output = bntrans.predict(model_path, word, topk=10)
# output: ['ভাট', 'ভাত', 'ভাঁট', 'ওয়াট', 'ভাঁত', 'ভোট', 'ভাঠ', 'ভাদ', 'ভট', 'ভ্যাট']
bntrans = BNTransliteration(model_path)

word = "aami"
output = bntrans.predict(word, topk=10)
# output: ['আমি', 'আমী', 'অ্যামি', 'আমিই', 'এমি', 'আমির', 'আমিদ', 'আমই', 'আমে', 'আমিতে']

```

Expand Down
2 changes: 1 addition & 1 deletion bntranslit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

__version__= "1.0.0"
__version__= "2.0.0"

from wasabi import msg

Expand Down
Binary file modified bntranslit/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified bntranslit/__pycache__/bntransliteration.cpython-36.pyc
Binary file not shown.
Binary file modified bntranslit/__pycache__/utils.cpython-36.pyc
Binary file not shown.
12 changes: 7 additions & 5 deletions bntranslit/bntransliteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def load_pretrained(model, weight_path, flexible = False):
return model

class BNTransliteration:
def __init__(self):
def __init__(self, model_path):
self.device = "cpu"
self.en_num = [chr(alpha) for alpha in range(48, 58)]
self.english_lower_script = [chr(alpha) for alpha in range(97, 123)]
Expand Down Expand Up @@ -567,13 +567,15 @@ def __init__(self):
self.model = Seq2Seq(self.enc, self.dec, pass_enc2dec_hid=enc2dec_hid,
device=self.device)
self.model = self.model.to(self.device)

def predict(self, model_path, word, topk=10):
model = load_pretrained(self.model, model_path)
self.model = load_pretrained(self.model, model_path)

def predict(self, word, topk=10):
in_vec = torch.from_numpy(self.src_glyph.word2xlitvec(word)).to(self.device)
p_out_list = model.active_beam_inference(in_vec, beam_width = topk)
p_out_list = self.model.active_beam_inference(in_vec, beam_width = topk)
p_result = [ self.tgt_glyph.xlitvec2word(out.cpu().numpy()) for out in p_out_list]
result = p_result

return result



2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setuptools.setup(
name="bntranslit",
version="1.0.0",
version="2.0.0",
author="Sagor Sarker",
author_email="sagorhem3532@gmail.com",
description="BNTRANSLIT is a deep learning based transliteration app for Bangla word",
Expand Down
6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from bntranslit import BNTransliteration

bntrans = BNTransliteration('bntransliterate_model.pth')

output = bntrans.predict('aami', topk=10)
print(output)

0 comments on commit a8be3b6

Please sign in to comment.