TypeError: test() missing 1 required positional argument












0















I want to predict a score for each sentence in a text. I have written this test method:



def test(sent):
# Predict for a given sentence
if sent != "":
input, seq_lengths, target = make_variables([sent], )
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
score = pred.cpu().numpy()[0][0]
print("The sentence is:",sent, "The score is:", score)
return


print("evaluating trained model ...")
total_mse=0

for sents, scores in test_loader:
input, seq_lengths, target = make_variables(sents, scores)
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
error=mean_squared_error(pred,target.data.view_as(pred.float()))
total_mse +=error
print(" ********** Total MSE is **********",total_mse)
return


In a part of main method, I have:



# Testing
test("")
# Testing for a given sample _a sentence_
test("For instance, wolves prey on moose, which are too big for coyotes.")


But I received this error:




Error Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 59, in testPartExecutor
yield File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 601, in run
testMethod() File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) Exception: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



E
====================================================================== ERROR: mahsa_rnn_sent_classification.test
---------------------------------------------------------------------- Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) TypeError: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



---------------------------------------------------------------------- Ran 1 test in 0.004s



FAILED (errors=1)




I think that test() has its argument 'sent'. How can I correct this error?










share|improve this question

























  • Please include the complete error message.

    – DYZ
    Nov 24 '18 at 6:46











  • Where is your self? Do you have a class? Can you learn some BASIC python first?

    – shawn
    Nov 24 '18 at 6:47











  • I edited my question by adding full error comment.

    – user7418216
    Nov 24 '18 at 6:51
















0















I want to predict a score for each sentence in a text. I have written this test method:



def test(sent):
# Predict for a given sentence
if sent != "":
input, seq_lengths, target = make_variables([sent], )
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
score = pred.cpu().numpy()[0][0]
print("The sentence is:",sent, "The score is:", score)
return


print("evaluating trained model ...")
total_mse=0

for sents, scores in test_loader:
input, seq_lengths, target = make_variables(sents, scores)
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
error=mean_squared_error(pred,target.data.view_as(pred.float()))
total_mse +=error
print(" ********** Total MSE is **********",total_mse)
return


In a part of main method, I have:



# Testing
test("")
# Testing for a given sample _a sentence_
test("For instance, wolves prey on moose, which are too big for coyotes.")


But I received this error:




Error Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 59, in testPartExecutor
yield File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 601, in run
testMethod() File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) Exception: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



E
====================================================================== ERROR: mahsa_rnn_sent_classification.test
---------------------------------------------------------------------- Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) TypeError: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



---------------------------------------------------------------------- Ran 1 test in 0.004s



FAILED (errors=1)




I think that test() has its argument 'sent'. How can I correct this error?










share|improve this question

























  • Please include the complete error message.

    – DYZ
    Nov 24 '18 at 6:46











  • Where is your self? Do you have a class? Can you learn some BASIC python first?

    – shawn
    Nov 24 '18 at 6:47











  • I edited my question by adding full error comment.

    – user7418216
    Nov 24 '18 at 6:51














0












0








0








I want to predict a score for each sentence in a text. I have written this test method:



def test(sent):
# Predict for a given sentence
if sent != "":
input, seq_lengths, target = make_variables([sent], )
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
score = pred.cpu().numpy()[0][0]
print("The sentence is:",sent, "The score is:", score)
return


print("evaluating trained model ...")
total_mse=0

for sents, scores in test_loader:
input, seq_lengths, target = make_variables(sents, scores)
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
error=mean_squared_error(pred,target.data.view_as(pred.float()))
total_mse +=error
print(" ********** Total MSE is **********",total_mse)
return


In a part of main method, I have:



# Testing
test("")
# Testing for a given sample _a sentence_
test("For instance, wolves prey on moose, which are too big for coyotes.")


But I received this error:




Error Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 59, in testPartExecutor
yield File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 601, in run
testMethod() File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) Exception: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



E
====================================================================== ERROR: mahsa_rnn_sent_classification.test
---------------------------------------------------------------------- Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) TypeError: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



---------------------------------------------------------------------- Ran 1 test in 0.004s



FAILED (errors=1)




I think that test() has its argument 'sent'. How can I correct this error?










share|improve this question
















I want to predict a score for each sentence in a text. I have written this test method:



def test(sent):
# Predict for a given sentence
if sent != "":
input, seq_lengths, target = make_variables([sent], )
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
score = pred.cpu().numpy()[0][0]
print("The sentence is:",sent, "The score is:", score)
return


print("evaluating trained model ...")
total_mse=0

for sents, scores in test_loader:
input, seq_lengths, target = make_variables(sents, scores)
output = classifier(input, seq_lengths)
pred = output.data.max(1, keepdim=True)[1]
error=mean_squared_error(pred,target.data.view_as(pred.float()))
total_mse +=error
print(" ********** Total MSE is **********",total_mse)
return


In a part of main method, I have:



# Testing
test("")
# Testing for a given sample _a sentence_
test("For instance, wolves prey on moose, which are too big for coyotes.")


But I received this error:




Error Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 59, in testPartExecutor
yield File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/unittest/case.py",
line 601, in run
testMethod() File "/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) Exception: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



E
====================================================================== ERROR: mahsa_rnn_sent_classification.test
---------------------------------------------------------------------- Traceback (most recent call last): File
"/home/mahsa/anaconda3/envs/pytorch_env/lib/python3.5/site-packages/nose/case.py",
line 198, in runTest
self.test(*self.arg) TypeError: test() missing 1 required positional argument: 'sent'
-------------------- >> begin captured logging << -------------------- gensim.models.doc2vec: DEBUG: Fast version of gensim.models.doc2vec is
being used summa.preprocessing.cleaner: INFO: 'pattern' package not
found; tag filters are not available for English gensim.utils: INFO:
loading KeyedVectors object from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
gensim.utils: INFO: loading syn0 from
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved.syn0.npy
with mmap=None gensim.utils: INFO: setting ignored attribute syn0norm
to None gensim.utils: INFO: loaded
/home/mahsa/PycharmProjects/PyTorch_env_project/Thesis/proj2/glove_saved
--------------------- >> end captured logging << ---------------------



---------------------------------------------------------------------- Ran 1 test in 0.004s



FAILED (errors=1)




I think that test() has its argument 'sent'. How can I correct this error?







python pycharm pytest text-mining nose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 9:19







user7418216

















asked Nov 24 '18 at 6:43









user7418216user7418216

118115




118115













  • Please include the complete error message.

    – DYZ
    Nov 24 '18 at 6:46











  • Where is your self? Do you have a class? Can you learn some BASIC python first?

    – shawn
    Nov 24 '18 at 6:47











  • I edited my question by adding full error comment.

    – user7418216
    Nov 24 '18 at 6:51



















  • Please include the complete error message.

    – DYZ
    Nov 24 '18 at 6:46











  • Where is your self? Do you have a class? Can you learn some BASIC python first?

    – shawn
    Nov 24 '18 at 6:47











  • I edited my question by adding full error comment.

    – user7418216
    Nov 24 '18 at 6:51

















Please include the complete error message.

– DYZ
Nov 24 '18 at 6:46





Please include the complete error message.

– DYZ
Nov 24 '18 at 6:46













Where is your self? Do you have a class? Can you learn some BASIC python first?

– shawn
Nov 24 '18 at 6:47





Where is your self? Do you have a class? Can you learn some BASIC python first?

– shawn
Nov 24 '18 at 6:47













I edited my question by adding full error comment.

– user7418216
Nov 24 '18 at 6:51





I edited my question by adding full error comment.

– user7418216
Nov 24 '18 at 6:51












1 Answer
1






active

oldest

votes


















0














Running tests with nose or unittest is not trivial, if you're new at this, I think you would have an easier time getting started with something like pytest






share|improve this answer
























  • I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

    – user7418216
    Nov 24 '18 at 9:16













  • I don't use PyCharm nor Windows, sorry, can't help you with that...

    – Silmathoron
    Nov 24 '18 at 9:18











  • No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

    – Silmathoron
    Nov 24 '18 at 9:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455834%2ftypeerror-test-missing-1-required-positional-argument%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Running tests with nose or unittest is not trivial, if you're new at this, I think you would have an easier time getting started with something like pytest






share|improve this answer
























  • I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

    – user7418216
    Nov 24 '18 at 9:16













  • I don't use PyCharm nor Windows, sorry, can't help you with that...

    – Silmathoron
    Nov 24 '18 at 9:18











  • No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

    – Silmathoron
    Nov 24 '18 at 9:23
















0














Running tests with nose or unittest is not trivial, if you're new at this, I think you would have an easier time getting started with something like pytest






share|improve this answer
























  • I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

    – user7418216
    Nov 24 '18 at 9:16













  • I don't use PyCharm nor Windows, sorry, can't help you with that...

    – Silmathoron
    Nov 24 '18 at 9:18











  • No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

    – Silmathoron
    Nov 24 '18 at 9:23














0












0








0







Running tests with nose or unittest is not trivial, if you're new at this, I think you would have an easier time getting started with something like pytest






share|improve this answer













Running tests with nose or unittest is not trivial, if you're new at this, I think you would have an easier time getting started with something like pytest







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 8:38









SilmathoronSilmathoron

1,0211821




1,0211821













  • I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

    – user7418216
    Nov 24 '18 at 9:16













  • I don't use PyCharm nor Windows, sorry, can't help you with that...

    – Silmathoron
    Nov 24 '18 at 9:18











  • No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

    – Silmathoron
    Nov 24 '18 at 9:23



















  • I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

    – user7418216
    Nov 24 '18 at 9:16













  • I don't use PyCharm nor Windows, sorry, can't help you with that...

    – Silmathoron
    Nov 24 '18 at 9:18











  • No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

    – Silmathoron
    Nov 24 '18 at 9:23

















I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

– user7418216
Nov 24 '18 at 9:16







I try running my code by pytest instead of nostest by trying this path: Pycharm->Settings->Tools->Python Integrated Tools-> Default Test Runner=py.test.' But when I right click on my python file in Pycharm, there is still Run/Debug Nosetest in myfile.py`. How can I change this to pytest?

– user7418216
Nov 24 '18 at 9:16















I don't use PyCharm nor Windows, sorry, can't help you with that...

– Silmathoron
Nov 24 '18 at 9:18





I don't use PyCharm nor Windows, sorry, can't help you with that...

– Silmathoron
Nov 24 '18 at 9:18













No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

– Silmathoron
Nov 24 '18 at 9:23





No pb, if you cannot use it, then have a look at the unittest tutorials to see how to build the test classes

– Silmathoron
Nov 24 '18 at 9:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455834%2ftypeerror-test-missing-1-required-positional-argument%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python