i'm trying to install pyrouge, and i ran this code (following this repo)
from pyrouge import Rouge155
from pprint import pprint
ref_texts = {'A': "Poor nations pressurise developed countries into granting trade subsidies.",
'B': "Developed countries should be pressurized. Business exemptions to poor nations.",
'C': "World's poor decide to urge developed nations for business concessions."}
summary_text = "Poor nations demand trade subsidies from developed nations."
rouge = Rouge155(n_words=100)
score = rouge.score_summary(summary_text, ref_texts)
pprint(score)
But i got some error, the traceback displayed as below:
Traceback (most recent call last):
File "<ipython-input-116-94aea372ee05>", line 1, in <module>
runfile('C:/Users/cerdas/Documents/Bil/Lat/rouge.py', wdir='C:/Users/cerdas/Documents/Bil/Lat')
File "C:\Users\cerdas\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\cerdas\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/cerdas/Documents/Bil/Lat/rouge.py", line 10, in <module>
rouge = Rouge155(n_words=100)
TypeError: __init__() got an unexpected keyword argument 'n_words'
and here the code of __init__.py
from pyrouge.base import Doc, Sent
from pyrouge.rouge import Rouge155
and the called function Rouge155
class Rouge155(object):
def __init__(self, rouge_home=ROUGE_EVAL_HOME, n_words=None, stem=False, keep_files=False):
self._stem = stem
self._n_words = n_words
self._discover_rouge(rouge_home)
self._keep_files = keep_files
You need to export your environment variable: ROUGE_EVAL_HOME
From the docs:
Assuming a working ROUGE-1.5.5. installation, tell pyrouge the ROUGE path with this command:
pyrouge_set_rouge_path /absolute/path/to/ROUGE-1.5.5/directory
Go to your Repository (Your folder where you cloned this from). Now make your way into pyrouge/base.py and make sure the variable ROUGE_EVAL_HOME points to tools/ROUGE-1.5.5.Try entering the entire destination manually by copying the filepath and then if it works try using os module to make it more dynamic. You need to tell your code to point to the ROUGE package that is in your repository not the one you get from pip install pyrouge
The following instructions were tested on Windows 10 and python 3.7x32
Do download your project pyrouge on the repository of the
Anders Johannsen. No install thought for pip install pyrouge.
To solve I had to make a small modification at the moment the command line is built that and will run ROUGE-1.5.5.pl. In windows, besides you need to add PERL.exe to the environment variables, but you will also need change the class Rouge155() in file code \pyrouge\rouge.py.
Open the file code \pyrouge\rouge.py go to the function def _run_rouge(self) (it's at line 96 at the time I am writing this answer).
Go to the line 122, comment this line return check_output([self._rouge_bin] + options)
Add this code in place:
command = [self._rouge_bin] + options
command.insert(0, 'perl ')
return check_output(command)
Franck Dernoncourt in your answer for the question How to install the Python package pyrouge on Microsoft Windows? solved the problem in the step 7, but this step only works in pyrouge installed through of the pip install rouge, in the implementation of repository of the other author, Benjamin Heinzerling.
And you are trying to use the version available the repository of the author Anders Johannsen. The his implementation has the class with the arguments you commented n_words=100, but only in the his version of the class Rouge155(), and her not in Python Package Index (PyPI).
P.S: Sorry for any mistake, my english is medium.
Related
I have been dealing an error when trying to learn Google "temporal fusion transformer" algorithm in anaconda spyder 5.1.5.
Guys, it is very important for me to solve this error. Somebody should say something. I will be very glad.
The example which i use in the link below;
https://pytorch-forecasting.readthedocs.io/en/latest/tutorials/stallion.html
In example, when i come to run the code which i mention below, i got the error
study = optimize_hyperparameters(
train_dataloader,
val_dataloader,
model_path="optuna_test",
n_trials=200,
max_epochs=50,
gradient_clip_val_range=(0.01, 1.0),
hidden_size_range=(8, 128),
hidden_continuous_size_range=(8, 128),
attention_head_size_range=(1, 4),
learning_rate_range=(0.001, 0.1),
dropout_range=(0.1, 0.3),
trainer_kwargs=dict(limit_train_batches=30),
reduce_on_plateau_patience=4,
use_learning_rate_finder=False # use Optuna to find ideal learning rate or use in-built learning rate finder
)
Here is the error below
A new study created in memory with name: no-name-fe7e21ce-3034-4679-b60a-ee4d5c9a4db5
[W 2022-10-21 19:36:49,382] Trial 0 failed because of the following error: TypeError("__init__() got an unexpected keyword argument 'weights_summary'")
Traceback (most recent call last):
File "C:\Users\omer\anaconda3\lib\site-packages\optuna\study\_optimize.py", line 196, in _run_trial
value_or_values = func(trial)
File "C:\Users\omer\anaconda3\lib\site-packages\pytorch_forecasting\models\temporal_fusion_transformer\tuning.py", line 150, in objective
trainer = pl.Trainer(
File "C:\Users\omer\anaconda3\lib\site-packages\pytorch_lightning\utilities\argparse.py", line 345, in insert_env_defaults
return fn(self, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'weights_summary'
Traceback (most recent call last):
Input In [3] in <cell line: 1>
study = optimize_hyperparameters(
File ~\anaconda3\lib\site-packages\pytorch_forecasting\models\temporal_fusion_transformer\tuning.py:217 in optimize_hyperparameters
study.optimize(objective, n_trials=n_trials, timeout=timeout)
File ~\anaconda3\lib\site-packages\optuna\study\study.py:419 in optimize
_optimize(
File ~\anaconda3\lib\site-packages\optuna\study\_optimize.py:66 in _optimize
_optimize_sequential(
File ~\anaconda3\lib\site-packages\optuna\study\_optimize.py:160 in _optimize_sequential
frozen_trial = _run_trial(study, func, catch)
File ~\anaconda3\lib\site-packages\optuna\study\_optimize.py:234 in _run_trial
raise func_err
File ~\anaconda3\lib\site-packages\optuna\study\_optimize.py:196 in _run_trial
value_or_values = func(trial)
File ~\anaconda3\lib\site-packages\pytorch_forecasting\models\temporal_fusion_transformer\tuning.py:150 in objective
trainer = pl.Trainer(
File ~\anaconda3\lib\site-packages\pytorch_lightning\utilities\argparse.py:345 in insert_env_defaults
return fn(self, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'weights_summary'
What is problem with the code? Is there anyone to help me, please?
So, i had same ploblom as you have.
I suggest you find out "weights_suammry" variable on your code
I use .yaml file and put parameters of pytorch_lightning.Trainer automatically using hydra also use strategy=DDPStrategy(find~)
i just realize there was weights_summary in .yaml file,
the structure was
trainer:
_target_: ~~
~~:
weights_summary : "top"
and i remove weights_summary on it and the plobloms have solved
the weights_summary argument was removed starting from Pytorch-Lightning version 1.7.0. See pull request here. As an alternative use parameter enable_model_summary, as described in the docs here.
I think you installed pytorch-forecasting from conda-forge. The current version is v0.10.2 for conda-forge while it is v0.10.3 for pip. See https://github.com/jdb78/pytorch-forecasting. They solved this issue in v0.10.3. So you can either reinstall it with pip or downgrade pytorch-lightning, like
conda remove pytorch-lightning
conda install pytorch-lightning=1.6.4 -c conda-forge
conda remove pytorch-forecasting
conda install pytorch-forecasting -c conda-forge
As a temporary measure, there is a way to directly modify the installed library file.
In my case, line 147 of file /opt/conda/lib/python3.7/site-packages/pytorch_forecasting/models/temporal_fusion_transformer/tuning.py
weights_summary=[None, "top"][optuna_verbose < optuna.logging.INFO] ,
was modified as follows.
enable_model_summary=[None, "top"][optuna_verbose < optuna.logging.INFO],
So it seems like there is an incompatibility issue with the pytorch_lightning version that you are using. Your version is probably to advanced.
I'm using pytorch_ligtning v1.5, and pytorch_forecasting at 0.10.2, and it works.
I am working a somewhat extensive python program that uses multiprocessing. Because I wanted the user to see some progress on the console when running the program, I read about using a shared counter on stackoverflow and after a while of playing around with my code, I got it to work. As I said it's too much code to post here, but the gist is that I instantiate a multiprocessing array after the name==main line,
if __name__ == "__main__":
total_progress_counter = Array('i',[0,0])
and then during the main portion of code I pass this array to a function in other module:
some_name.plot(<other variables>,
total_progress_counter=total_progress_counter)
Then within that other function, I used the .get_lock method that I found described here on stackoverflow:
with total_progress_counter.get_lock():
total_progress_counter[0] += self.total_panels_to_plot
I also update the other component, total_progress_counter[1], in the same function. This works fine for me on my work machine, where I wrote the code, and that machine has a Centos operating system.
But, when I run it on my personal MacBook it gives the following traceback:
Traceback (most recent call last):
File "./program.py", line 775, in <module>
program.run()
File "./program.py", line 177, in run
cases_plotted = pool.map(self.__plot__, all_cases)
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 771, in get
raise self._value
AttributeError: 'list' object has no attribute 'get_lock'
I have python3 version 3.8.3 on my personal machine and python3 version 3.7.4 on my work machine. Can anyone help me understand why I'm getting different behavior on these two environments? I'd be grateful, as this is meant to be software others might use on different machines.
I am attempting to write a Hello World program in Manim.
I have installed Manim and its prerequisite programs, and can run the sample code from the command prompt as intended. This sample code operates in an unusual way; the user issues a command specifying not only a .py file, but also a single class within it, and Python executes the class definition code, seemingly without instantiating the class.
Now I'm trying to write a standalone .py file that works by instantiating a class when run (I am running it in Visual Studio Community 2019), rather than requiring external commands.
I have checked many of the Similar Questions, but unfortunately, they are all about Hello World programs in general, even spanning many non-Python languages.
I found a few AttributeError: '____' object has no attribute '____' questions in search, including this helpful explanation (https://stackoverflow.com/a/8696339/2364796), but nothing that seems to apply to the code I've explicitly written.
I also checked in IRC, and it was suggested that the problem is triggered within the imported code. However, the same code functions properly when imported into the sample, so I must be working with it incorrectly.
This is the current code for my Hello World program.
from manimlib.imports import *
class GreetingScript(Scene):
def construct(self):
characters = TextMobject("Hello World!")
self.add(characters)
scene1 = Scene()
readthrough = GreetingScript(scene1)
This is the error message produced by the above code.
Media will be stored in ./media\. You can change this behavior by writing a
diff
erent directory to media_dir.txt.
Traceback (most recent call last):
File "C:\Users\Admin\Documents\Visual Studio
2019\Projects\PythonApplication1\
PythonApplication1\PythonApplication1.py", line 8, in <module>
scene1 = Scene()
File "C:\Users\Admin\PortableApps\manim-0.1.5\manimlib\scene\scene.py",
line 3
7, in __init__
self, **self.file_writer_config,
File "C:\Users\Admin\PortableApps\manim-
0.1.5\manimlib\scene\scene_file_writer
.py", line 44, in __init__
self.init_output_directories()
File "C:\Users\Admin\PortableApps\manim-
0.1.5\manimlib\scene\scene_file_writer
.py", line 49, in init_output_directories
output_directory = self.output_directory or
self.get_default_output_director
y()
File "C:\Users\Admin\PortableApps\manim-
0.1.5\manimlib\scene\scene_file_writer
.py", line 80, in get_default_output_directory
filename = os.path.basename(self.input_file_path)
AttributeError: 'SceneFileWriter' object has no attribute 'input_file_path'
Press any key to continue . . .
I would expect the output of the program to be a display of the text "Hello World!" but the actual output is AttributeError: 'SceneFileWriter' object has no attribute 'input_file_path' accompanied by the rest of the above message.
The best way to solve this problem is to remove the code that creates the scene1 object. To make this code work, it is required to implement only the source of your scene class, and you can generate the scene using:
$ python -m manim -p /path/to/source.py GreetingScript
The -p flag means to open the video after rendering the scene. I hope this can help on your issue.
from big_ol_pile_of_manim_imports import *
class makeText(Scene):
def construct(self):
#######Code#######
#Making text
first_line = TextMobject("Manim is fun")
second_line = TextMobject("and useful")
final_line = TextMobject("Hope you like it too!", color=BLUE)
color_final_line = TextMobject("Hope you like it too!")
#Coloring
color_final_line.set_color_by_gradient(BLUE,PURPLE)
#Position text
second_line.next_to(first_line, DOWN)
#Showing text
self.wait(1)
self.play(Write(first_line), Write(second_line))
self.wait(1)
self.play(FadeOut(second_line), ReplacementTransform(first_line, final_line))
self.wait(1)
self.play(Transform(final_line, color_final_line))
self.wait(2)
have you tried something?
I have tried running the code found at http://computationallegalstudies.com/2009/11/15/programming-dynamic-models-in-python-3-outbreak-on-a-network/ but at the end the following shows up:
File "/Library/Python/2.7/site-packages/igraph/drawing/__init__.py", line 446, in plot
result = Plot(target, bbox, background=kwds.get("background", "white"))
File "/Library/Python/2.7/site-packages/igraph/drawing/__init__.py", line 117, in __init__
self._surface_was_created = not isinstance(target, cairo.Surface)
File "/Library/Python/2.7/site-packages/igraph/drawing/utils.py", line 396, in __getattr__
raise TypeError("plotting not available")
TypeError: plotting not available
It's a code for modelling SIR model on networks. I really need someone's help as I am not able to use a computer , a mac in this case. Thank you in advance
You need to install the Cairo library and its Python bindings for plotting. If you are using Homebrew, it is simply a matter of brew install cairo py2cairo, assuming that you use the system Python (which you seem to be, judging from the stack trace).
I read in the howto documentation to install Trigger, but when I test in python environment, I get the error below:
>>> from trigger.netdevices import NetDevices
>>> nd = NetDevices()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 913, in __init__
with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 767, in __init__
production_only=production_only, with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 83, in _populate
# device_data = _munge_source_data(data_source=data_source)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 73, in _munge_source_data
# return loader.load_metadata(path, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/loader.py", line 163, in load_metadata
raise RuntimeError('No data loaders succeeded. Tried: %r' % tried)
RuntimeError: No data loaders succeeded. Tried: [<trigger.netdevices.loaders.filesystem.XMLLoader object at 0x7f550a1ed350>, <trigger.netdevices.loaders.filesystem.JSONLoader object at 0x7f550a1ed210>, <trigger.netdevices.loaders.filesystem.SQLiteLoader object at 0x7f550a1ed250>, <trigger.netdevices.loaders.filesystem.CSVLoader object at 0x7f550a1ed290>, <trigger.netdevices.loaders.filesystem.RancidLoader object at 0x7f550a1ed550>]
Does anyone have some idea how to fix it?
The NetDevices constructor is apparently trying to find a "metadata source" that isn't there.
Firstly, you need to define the metadata. Second, your code should handle the exception where none is found.
I'm the lead developer of Trigger. Check out the the doc Working with NetDevices. It is probably what you were missing. We've done some work recently to improve the quality of the setup/install docs, and I hope that this is more clear now!
If you want to get started super quickly, you can feed Trigger a CSV-formatted NetDevices file, like so:
test1-abc.net.example.com,juniper
test2-abc.net.example.com,cisco
Just put that in a file, e.g. /tmp/netdevices.csv and then set the NETDEVICES_SOURCE environment variable:
export NETDEVICES_SOURCE=/tmp/netdevices.csv
And then fire up python and continue on with your examples and you should be good to go!
I found that the default of /etc/trigger/netdevices.xml wasn't listed in the setup instructions. It did indicate to copy from the trigger source folder:
cp conf/netdevices.json /etc/trigger/netdevices.json
But, I didn't see how to specify this instead of the default NETDEVICES_SOURCE on the installation page. But, as soon as I had a file that NETDEVICES_SOURCE pointed to in my /etc/trigger folder, it worked.
I recommend this to get the verifying functionality examples to work right away with minimal fuss:
cp conf/netdevices.xml /etc/trigger/netdevices.xml
Using Ubuntu 14.04 with Python 2.7.3