CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing
https://cqcl.github.io/lambeq/
Apache License 2.0
439 stars 106 forks source link

Error when running Parser #11

Closed ACE07-Sev closed 2 years ago

ACE07-Sev commented 2 years ago

Below is the code I ran for testing the parser : from lambeq import BobcatParser

parser = BobcatParser() diagram = parser.sentence2diagram('This is a test sentence') diagram.draw()

and this is the error I received when running it : 2022-05-22 20:19:08.041411: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2022-05-22 20:19:08.042271: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. Traceback (most recent call last): File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1342, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request self._send_request(method, url, body, headers, encode_chunked) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1301, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1250, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1010, in _send_output self.send(msg) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 950, in send self.connect() File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1424, in connect self.sock = self._context.wrap_socket(self.sock, File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create self.do_handshake() File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\elmm\Desktop\CQM\QNLP Depression 2.py", line 3, in parser = BobcatParser() File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\text2diagram\bobcat_parser.py", line 258, in init download_model(model_name_or_path, model_dir, verbose) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\text2diagram\bobcat_parser.py", line 130, in download_model model_file, headers = urlretrieve(url, reporthook=progress_bar.update) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 239, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen return opener.open(url, data, timeout) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open response = self._open(req, data) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain result = func(*args) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1385, in https_open return self.do_open(http.client.HTTPSConnection, req, File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1345, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1123)>

How can I resolve this?

Thommy257 commented 2 years ago

Hi, thanks for submitting this issue, this has happened before and we are currently investigate it. Could you please give us the following information about your system:

In the meantime, you can download the model through this link, extract it, and pass the path to the extracted files to the BobcatParser:

from lambeq import BobcatParser

parser = BobcatParser(model='path/to/model')
diagram = parser.sentence2diagram('This is a test sentence')
diagram.draw()
Stephenito commented 2 years ago

I have the same problem with SSL certificate. I have tried with the following configuration:

I also downloaded the model from the link you provided and extracted it. I copy-pasted your code, and tried as paths the relative paths and abosulte paths (I/O is working properly with other files) of both the directory containing the model and the file 'pytorch_model.bin', but still the program returns the same SSL error.

Is there something i am doing wrong while loading the local file? Thanks for your help.

Thommy257 commented 2 years ago

Sorry, the download link might have been deprecated. Can you try downloading the model from https://qnlp.cambridgequantum.com/models/bert/latest/model.tar.gz?

Also, I realised that the correct variable is model_name_or_path. So this will work:

from lambeq import BobcatParser

parser = BobcatParser(model_name_or_path='path/to/model')
diagram = parser.sentence2diagram('This is a test sentence')
diagram.draw()

Many apologies!

Update: the link was broken.

ACE07-Sev commented 2 years ago

I downloaded the model.tar.gz. How shall I set the Parser path to it? I'm not very familiar with .tar.gz files.

Thommy257 commented 2 years ago

Hi @ACE07-Sev, .tar.gz is an compressed file. You need to extract it first. Maybe this page helps: https://superuser.com/questions/215629/how-to-open-a-tar-gz-file-in-windows

ACE07-Sev commented 2 years ago

Hi yes now it's fixed. I extracted it and then addressed the file path to that. thank you so much

ACE07-Sev commented 2 years ago

Hi sorry, I ran the model and got this error :

2022-06-06 18:03:29.258323: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2022-06-06 18:03:29.259328: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. Traceback (most recent call last): File "C:\Users\elmm\Desktop\CQM\QNLP Depression.py", line 104, in trainer.fit(train_dataset, val_dataset, logging_step=12) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\trainer.py", line 365, in fit y_hat, loss = self.training_step(batch) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\quantum_trainer.py", line 149, in training_step y_hat, loss = self.optimizer.backward(batch) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\spsa_optimizer.py", line 125, in backward y0 = self.model(diagrams) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\model.py", line 59, in call return self.forward(*args, **kwds) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py", line 131, in forward return self.get_diagram_output(x) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py", line 103, in get_diagram_output seed=self._randint() File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py", line 71, in _randint return np.random.randint(low, high) File "mtrand.pyx", line 746, in numpy.random.mtrand.RandomState.randint File "_bounded_integers.pyx", line 1334, in numpy.random._bounded_integers._rand_int32 ValueError: low is out of bounds for int32

The parser is working now so I think besides this we can close the issue.

ACE07-Sev commented 2 years ago

I tried changing the seed to 7 for instance but still got the error. May I ask how can I resolve this?

Thommy257 commented 2 years ago

Follow-up in #12