mesolitica / NLP-Models-Tensorflow

Gathers machine learning and Tensorflow deep learning models for NLP problems, 1.13 < Tensorflow < 2.0
MIT License
1.78k stars 729 forks source link

1.lstm-seq2seq-greedy.ipynb In [17] missing 1 required positional argument: 'maxlen' #18

Closed 425776024 closed 5 years ago

425776024 commented 5 years ago

In [17]: def pad_sentence_batch(sentence_batch, pad_int, maxlen): In [18]: batchx, = pad_sentence_batch(train_X[k: min(k+batch_size,len(train_X))], PAD) batchy, = pad_sentence_batch(train_Y[k: min(k+batch_size,len(train_X))], PAD) error: TypeError: pad_sentence_batch() missing 1 required positional argument: 'maxlen'

maybe: def pad_sentence_batch(sentence_batch, pad_int): padded_seqs = [] seq_lens = [] max_sentence_len = max([len(sentence) for sentence in sentence_batch]) for sentence in sentence_batch: padded_seqs.append(sentence + [pad_int] * (max_sentence_len - len(sentence))) seq_lens.append(len(sentence)) return padded_seqs, seq_lens