Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

narray_ext.rb:21:in `new': Argument required (ArgumentError) #7

Open
MikaelGyth opened this issue Aug 30, 2017 · 1 comment
Open

narray_ext.rb:21:in `new': Argument required (ArgumentError) #7

MikaelGyth opened this issue Aug 30, 2017 · 1 comment
Assignees

Comments

@MikaelGyth
Copy link

Hello.
I have unfortunately not been able to get this to run:
I keep getting the error:
narray_ext.rb:21:in 'new': Argument required (ArgumentError)
I realize that the error is from narray but I believe that the gem should work out of the box, following the instructions in the Readme? I have installed GSL and the DevKit following the instructions from their page.

This is the program that generates the error:

require 'zombie_writer'

zombie = ZombieWriter::MachineLearning.new

zombie.add_string(content: "Lorem ipsum dolor sit amet.",
sourcetext: "Cicero's Great Speech On Ethics",
sourceurl: "http://example.com/lorem-ipsum")

array = zombie.generate_articles

And this is the stack trace:

Uncaught exception: Argument required
	/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/narray-0.6.1.2/narray/narray_ext.rb:21:in `new'
	/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/narray-0.6.1.2/narray/narray_ext.rb:21:in `cast'
	/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/kmeans-clusterer-0.11.4/lib/kmeans-clusterer.rb:13:in `ensure_matrix'
	/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/kmeans-clusterer-0.11.4/lib/kmeans-clusterer.rb:130:in `run'
	/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/zombie_writer-0.2.0/lib/zombie_writer.rb:80:in `generate_clusters'
	/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/zombie_writer-0.2.0/lib/zombie_writer.rb:56:in `generate_articles'
	/home/mikael/Documents/source/Zombie/main.rb:9:in `<top (required)>'
	/home/mikael/.rbenv/versions/2.4.1/bin/rdebug-ide:23:in `load'
	/home/mikael/.rbenv/versions/2.4.1/bin/rdebug-ide:23:in `<main>'
/home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/narray-0.6.1.2/narray/narray_ext.rb:21:in `new': Argument required (ArgumentError)
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/narray-0.6.1.2/narray/narray_ext.rb:21:in `cast'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/kmeans-clusterer-0.11.4/lib/kmeans-clusterer.rb:13:in `ensure_matrix'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/kmeans-clusterer-0.11.4/lib/kmeans-clusterer.rb:130:in `run'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/zombie_writer-0.2.0/lib/zombie_writer.rb:80:in `generate_clusters'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/zombie_writer-0.2.0/lib/zombie_writer.rb:56:in `generate_articles'
	from /home/mikael/Documents/source/Zombie/main.rb:9:in `<top (required)>'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.6.0/lib/ruby-debug-ide.rb:88:in `debug_load'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.6.0/lib/ruby-debug-ide.rb:88:in `debug_program'
	from /home/mikael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/ruby-debug-ide-0.6.0/bin/rdebug-ide:130:in `<top (required)>'
	from /home/mikael/.rbenv/versions/2.4.1/bin/rdebug-ide:23:in `load'
	from /home/mikael/.rbenv/versions/2.4.1/bin/rdebug-ide:23:in `<main>'

Hope you can help me pinpoint what has gone wrong here? Keep up the good work.

@tra38 tra38 self-assigned this Sep 1, 2017
@tra38
Copy link
Owner

tra38 commented Sep 2, 2017

I am able to replicate this error too. It seems that ZombieWriter::MachineLearning is unable to gracefully handle scenarios where every quote is exactly the same. So this type of program would crash...

zombie = ZombieWriter::MachineLearning.new

zombie.add_string(content: "Lorem ipsum dolor sit amet.",
sourcetext: "Cicero's Great Speech On Ethics",
sourceurl: "http://example.com/lorem-ipsum")

zombie.add_string(content: "Lorem ipsum dolor sit amet.",
sourcetext: "Cicero's Great Speech On Ethics",
sourceurl: "http://example.com/lorem-ipsum")

array = zombie.generate_articles

...while this type of program would work as expected (by slightly changing the second input).

zombie = ZombieWriter::MachineLearning.new

zombie.add_string(content: "Lorem ipsum dolor sit amet.",
sourcetext: "Cicero's Great Speech On Ethics",
sourceurl: "http://example.com/lorem-ipsum")

zombie.add_string(content: "Lorem ipsum dolors sit amet.",
sourcetext: "Cicero's Great Speech On Ethics",
sourceurl: "http://example.com/lorem-ipsum")

array = zombie.generate_articles

I'll try to see whether it's possible to raise an exception to catch this edge case. For now, a workaround is to make sure that your program has more than one quote, and that at least one quote is "unique" from all the other quotes.

EDIT: Another workaround is to use ZombieWriter::Randomization instead. Note that ZombieWriter fails when generating summaries for "one sentence articles" (#1), so your input need to have more than one sentence.

zombie = ZombieWriter::Randomization.new

zombie.add_string(content: "Lorem ipsum dolor sit amet. Consectetur adipiscing elit.",
sourcetext: "Cicero's Great Speech On Ethics",
sourceurl: "http://example.com/lorem-ipsum")

array = zombie.generate_articles

EDIT 2: That being said, I only really answered what caused the existing problem, rather than the main problem of trying to see how the gem is supposed to work. The point of ZombieWriter is to take an existing corpus (such as this CSV file) and then divide it into several clusters. So the intention would be that you'd add multiple different sentences, not a single one (or the same one multiple times).

Here's a better code snippet to demonstrate the power of ZombieWriter (slightly adapted from this Issue Report).

require 'zombie_writer'
zombie = ZombieWriter::MachineLearning.new
# You may also use ZombieWriter::Randomization here as well

zombie.add_string(content: "This is filler text that I invented. This is also a paragraph that could be used.")
zombie.add_string(content: "This post is amazing. Please take a look.")
zombie.add_string(content: "For all sport fans, please watch this cool video.")

array = zombie.generate_articles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants