question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: param_init_embedding_layer() missing 2 required positional arguments: 'n_words' and 'dims

See original GitHub issue

I have been trying to get nematus to work using the wmt16 model, but I think there is something wrong in the code. I tried to fix it but no matter what I (guessed) to change, it keeps crashing in different places. Here’s the root problem:

Warning: No built-in rules for language de.
Detokenizer Version $Revision: 4134 $
Language: de
Tokenizer Version 1.1
Language: en
Number of threads: 1
Translating <stdin> ...
Using cuDNN version 5110 on context None
Mapped name None to device cuda: GeForce GTX 960M (0000:01:00.0)
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap
    self.run()
  File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/media/data/translation/nematus/nematus/translate.py", line 54, in translate_model
    f_init, f_next = build_sampler(tparams, option, use_noise, trng, return_alignment=return_alignment)
  File "/media/data/translation/nematus/nematus/nmt.py", line 359, in build_sampler
    x, ctx = build_encoder(tparams, options, trng, use_noise, x_mask=None, sampling=True)
  File "/media/data/translation/nematus/nematus/nmt.py", line 186, in build_encoder
    emb = get_layer_constr('embedding')(tparams, x, suffix='', factors= options['factors'])
TypeError: param_init_embedding_layer() missing 2 required positional arguments: 'n_words' and 'dims'
Error: translate worker process 10737 crashed with exitcode 1

If you look at layers.py, line 76, I think it’s true. But where to get n_words and dims from?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
michael-bradecommented, May 14, 2017

Oh, excellent observation! Yes, the code is pretty much unmodified, except that I am using it with python 3.5 and had to adapt a few imports and the renamed iteritems(). The solution for my problem is this little typo:

--- a/nematus/layers.py
+++ b/nematus/layers.py
@@ -20,7 +20,7 @@ from alignment_util import *
 layers = {'ff': ('param_init_fflayer', 'fflayer'),
           'gru': ('param_init_gru', 'gru_layer'),
           'gru_cond': ('param_init_gru_cond', 'gru_cond_layer'),
-          'embedding': {'param_init_embedding_layer', 'embedding_layer'}
+          'embedding': ('param_init_embedding_layer', 'embedding_layer')
           }

note the difference of { vs (. embedding returned a set instead of a tuple, and python 3 sorted the set according to string length, thus it had the wrong order. python 2.7 doesn’t sort strings in sets at all, it seems to me, so you were lucky 😉

If you want, I can create a PR with all my python 3 changes.

0reactions
michael-bradecommented, Jul 14, 2018

Great! I still have the tab open as a TODO reminder, but I just won’t have enough time until December. Guess I’ll be able to close those tabs, too, then 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: missing 2 required positional arguments (Python)
The Python TypeError: missing 2 required positional arguments occurs when we forget to provide 2 required arguments when calling a function or method....
Read more >
TypeError: __init__() missing 2 required positional arguments
You have to specify the number of activations and the dimensions when you create the object: a = SET_MLP(activations = x, dimensions =...
Read more >
Function() missing 2 required positional arguments - Python
TypeError : function() missing 2 required positional arguments: 'city1' ... to have function() , you could eliminate the parameters, and have
Read more >
TypeError: __new__() missing 2 required positional arguments
A couple of fixes: from abc import ABC, abstractmethod. # not ABCMeta, which is where your error arises. assign_values_to_sides() in ...
Read more >
doInOrden() missing 2 required positional arguments: 'probe ...
For me not much experience just run some code have face the error required two positional arguments probe and visit please help me...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found