monoses icon indicating copy to clipboard operation
monoses copied to clipboard

Step5 induce_phrase_table problem

Open cong1 opened this issue 5 years ago • 8 comments

Thank you for your sharing.I trained to the fifth step and there was a problem.

Traceback (most recent call last): File "monoses/training/induce-phrase-table.py", line 153, in main() File "monoses/training/induce-phrase-table.py", line 140, in main .format((epoch + j/n)/args.epochs, t.detach().cpu().numpy(), loss.detach().cpu().numpy()), TypeError: unsupported format string passed to numpy.ndarray.format sort: cannot read: MODEL-DIR/tmpvkx1vuhd/src2trg.phrase-table: No such file or directory

cong1 avatar May 15 '19 12:05 cong1

I have the same problem.

Traceback (most recent call last): File "/home/ubuntu/liu/demo/monoses-master/third-party/vecmap/map_embeddings.py", line 422, in main() File "/home/ubuntu/liu/demo/monoses-master/third-party/vecmap/map_embeddings.py", line 145, in main srcfile = open(args.src_input, encoding=args.encoding, errors='surrogateescape') FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR/step3/emb.src' Traceback (most recent call last): File "/home/ubuntu/liu/demo/monoses-master/training/induce-phrase-table.py", line 153, in main() File "/home/ubuntu/liu/demo/monoses-master/training/induce-phrase-table.py", line 110, in main srcfile = open(args.src, encoding=args.encoding, errors='surrogateescape') FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR/step4/emb.src' sort: cannot read: MODEL-DIR/tmpzq65kr2x/src2trg.phrase-table: No such file or directory Traceback (most recent call last): File "train.py", line 484, in main() File "train.py", line 474, in main induce_phrase_table(args) File "train.py", line 317, in induce_phrase_table os.remove(args.tmp + '/' + part + '.phrase-table') FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR/tmpzq65kr2x/src2trg.phrase-table'

yaoyao2 avatar Aug 27 '19 02:08 yaoyao2

@yaoyao2 did you manage to solve this? I'm having the same problem

gilis-rnd avatar Sep 02 '19 10:09 gilis-rnd

You can fix this by changing:

print('Optimizing temperature | Progress: {:.2%} | Temperature: {:.2f} | Loss: {:.2f}'
                  .format((epoch + j/n)/args.epochs, t.detach().cpu().numpy(), loss.detach().cpu().numpy()),
                  file=sys.stderr)

to

print('Optimizing temperature | Progress: {:.2%} | Temperature: {:.2f} | Loss: {:.2f}'
                  .format((epoch + j/n)/args.epochs, 
                      float(np.array2string(t.detach().cpu().numpy())), 
                      float(np.array2string(loss.detach().cpu().numpy()))),
                  file=sys.stderr)

in training/induce-phrase-table.py

kellymarchisio avatar Nov 04 '19 19:11 kellymarchisio

Did you manage to solve this problem? I tried the solution indicated by @kellymarchisio but it didn't work for me. Here's my error message:

/Desktop/monoses-master/third-party/vecmap/map_embeddings.py:301: RuntimeWarning: divide by zero encountered in true_divide return vt.T.dot(xp.diag(1/s)).dot(vt) Traceback (most recent call last): File "/Desktop/monoses-master/third-party/vecmap/map_embeddings.py", line 422, in main() File "/Desktop/monoses-master/third-party/vecmap/map_embeddings.py", line 309, in main wx2, s, wz2_t = xp.linalg.svd(xw[src_indices].T.dot(zw[trg_indices])) File "<array_function internals>", line 6, in svd File /.pyenv/versions/trans/lib/python3.7/site-packages/numpy/linalg/linalg.py", line 1626, in svd u, s, vh = gufunc(a, signature=signature, extobj=extobj) ValueError: On entry to DLASCL parameter number 4 had an illegal value Traceback (most recent call last): File /Desktop/monoses-master/training/induce-phrase-table.py", line 155, in main() File "/Desktop/monoses-master/training/induce-phrase-table.py", line 110, in main srcfile = open(args.src, encoding=args.encoding, errors='surrogateescape') FileNotFoundError: [Errno 2] No such file or directory: 'trial/step4/emb.src' sort: cannot read: trial/tmp00doxrpc/src2trg.phrase-table: No such file or directory Traceback (most recent call last): File "train.py", line 484, in main() File "train.py", line 474, in main induce_phrase_table(args) File "train.py", line 317, in induce_phrase_table os.remove(args.tmp + '/' + part + '.phrase-table') FileNotFoundError: [Errno 2] No such file or directory: 'trial/tmp00doxrpc/src2trg.phrase-table'

fferlito avatar Jun 08 '20 20:06 fferlito

To solve, try to change in map_embeddings.py in third_parties/vecmap the function whitening_transformation at line 298 with the following. It adds a small number epsilon to s to avoid division by zero. On top of that, be sure that your corpora are formatted properly. def whitening_transformation(m):

           u, s, vt = xp.linalg.svd(m, full_matrices=False)

            # Whitening constant: prevents division by zero

            epsilon = 0.002   

            return vt.T.dot(xp.diag(1/(s + epsilon))).dot(vt)

fferlito avatar Jun 08 '20 21:06 fferlito

Hello, I have made all the changes above suggested. But still getting error. Here is my error message: /usr/local/lib/python3.6/dist-packages/torch/nn/_reduction.py:43: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead. warnings.warn(warning.format(ret)) Optimizing temperature | Progress: 20000.00% | Temperature: 1.00 | Loss: 7.97 Traceback (most recent call last): File "/content/monoses/training/induce-phrase-table.py", line 155, in main() File "/content/monoses/training/induce-phrase-table.py", line 147, in main write_phrase_table(x, z, src_words, trg_words, t, args.size, args.batch, args.min_prob, device, f) File "/content/monoses/training/induce-phrase-table.py", line 78, in write_phrase_table scores, ind = x[i:j].matmul(z.t()).topk(size, dim=1) # batch*k RuntimeError: selected index k out of range sort: cannot read: MODEL-DIR9/tmp6kja9f4h/trg2src.phrase-table: No such file or directory Traceback (most recent call last): File "/content/monoses/train.py", line 484, in main() File "/content/monoses/train.py", line 474, in main induce_phrase_table(args) File "/content/monoses/train.py", line 317, in induce_phrase_table os.remove(args.tmp + '/' + part + '.phrase-table') FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR9/tmp6kja9f4h/trg2src.phrase-table'

shefs0709 avatar Jun 14 '20 05:06 shefs0709

I got the error too! FileNotFoundError: [Errno 2] No such file or directory: 'exp/enes//step4/emb.src' sort: cannot read: exp/enes/tmpksyk_67i/src2trg.phrase-table: No such file or directory Traceback (most recent call last): File "train.py", line 484, in <module> main() File "train.py", line 474, in main induce_phrase_table(args) File "train.py", line 317, in induce_phrase_table os.remove(args.tmp + '/' + part + '.phrase-table') FileNotFoundError: [Errno 2] No such file or directory: 'exp/enes/tmpksyk_67i/src2trg.phrase-table'

fallcat avatar Jun 15 '20 20:06 fallcat

@fallcat @shefs0709 - I had this issue when the automatically-created temp folder got deleted before the file could be read again. it was ages ago, but I believe I solved it by just changing to writing to a regular directory I made instead of a python tempdir

kellymarchisio avatar Mar 03 '21 16:03 kellymarchisio