Added parameters for partial and full sentences suggestions (#25)

* API parameter for number of suggestions

* Set n_best_partial in js

Co-authored-by: Sebastin Santy <sebastinssanty@gmail.com>
This commit is contained in:
Jahanvi Shah 2021-03-08 14:31:27 +05:30 коммит произвёл GitHub
Родитель 3a5ac491c1
Коммит af39c7dd08
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 10 добавлений и 10 удалений

Просмотреть файл

@ -94,16 +94,11 @@ def translate_new(request):
langspec = request.GET.get('langspec')
sentence = request.GET.get('sentence')
partial_trans = request.GET.get('partial_trans', '')
n_words = request.GET.get('n_words', '')
n_words = int(request.GET.get('n_words', '2'))
n_best_partial = int(request.GET.get('n_best_partial', '5'))
translatorbest = engines[langspec]["translatorbest"]
translatorbigram = engines[langspec]["translatorbigram"]
#set the default value for number of words in the suggestions as 2
n_suggestions = 2
if n_words != '':
n_suggestions = int(n_words)
src_segmenter = engines[langspec]["src_segmenter"]
L1 = preprocess_src(sentence.strip(), [src_segmenter])
@ -141,7 +136,8 @@ def translate_new(request):
batch_size=30,
attn_debug=False,
partial = toquotapos(L2),
dymax_len = n_suggestions,
dymax_len = n_words,
n_best = n_best_partial
)

Просмотреть файл

@ -290,7 +290,8 @@ class Translator(object):
phrase_table="",
partial=None,
partialfcheck=True,
dymax_len=None):
dymax_len=None,
n_best=None):
"""Translate content of ``src`` and get gold scores from ``tgt``.
Args:
@ -311,6 +312,8 @@ class Translator(object):
* attns is a list of attention scores for translation having highest cumilative log likelihood
"""
self.dymax_len = dymax_len
if n_best and n_best <= 5:
self.n_best = n_best
self.partialf = None
self.partialfcheck = partialfcheck

Просмотреть файл

@ -882,7 +882,8 @@ $(document).ready(function() {
'langspec': langspec,
'sentence': hin_inp.text(), // Maybe use some good names here?
'partial_trans': partial.clone().children().remove().end().text(),
'n_words': 2
'n_words': 2,
'n_best_partial': 5,
}, function(data) {
// console.log(data)
parseProcessedJsonResultsfunction(data, globalPartial)