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

TypeError: only integer scalar arrays can be converted to a scalar index #75

Open
DaemonicCao opened this issue May 4, 2022 · 8 comments
Labels
question Further information is requested

Comments

@DaemonicCao
Copy link

Traceback (most recent call last):
File "D:/seq2seq-couplet-master/couplet.py", line 23, in
m.train(5000000)
File "D:\seq2seq-couplet-master\model.py", line 164, in train
bleu_score = self.eval(step)
File "D:\seq2seq-couplet-master\model.py", line 194, in eval
self.eval_reader.vocabs).split(' ')
File "D:\seq2seq-couplet-master\reader.py", line 25, in decode_text
word = vocabs[idx]
TypeError: only integer scalar arrays can be converted to a scalar index

进程已结束,退出代码1

Repository owner deleted a comment from Lijiaxing-lx May 5, 2022
Repository owner deleted a comment from zhoujinyang1996 May 5, 2022
Repository owner deleted a comment from DaemonicCao May 5, 2022
@wb14123 wb14123 added the question Further information is requested label May 5, 2022
@wb14123 wb14123 changed the title 大佬来看看这个怎么解决啊!!!! TypeError: only integer scalar arrays can be converted to a scalar index May 5, 2022
@xiaoshuai1
Copy link

同问

@zhoujinyang1996
Copy link

zhoujinyang1996 commented Jun 18, 2022 via email

@Lijiaxing-lx
Copy link

Lijiaxing-lx commented Jun 18, 2022 via email

@Drizzlenum
Copy link

请问跑通了吗

@cui-z
Copy link

cui-z commented Aug 4, 2022

word = vocabs[idx] 修改为
word = np.array(vocabs)[idx]

@LongHuW
Copy link

LongHuW commented Aug 13, 2022

我这边是因为labels出现了三维array这种数据,所以我加了一个步骤,将其降维成一维就好了

def decode_text(labels, vocabs, end_token = '</s>'):
    results = []
    if isinstance(labels, list) == False and labels.ndim>1:
        labels_one = labels.reshape(-1).astype(int)
        for idx in labels_one:
            word = vocabs[idx]
            if word == end_token:
                return ' '.join(results)
            results.append(word)
        return ' '.join(results)

    for idx in labels:
        word = vocabs[idx]
        if word == end_token:
            return ' '.join(results)
        results.append(word)
    return ' '.join(results)

@DaemonicCao
Copy link
Author

DaemonicCao commented Oct 11, 2022 via email

@weifang74
Copy link

我这边是因为labels出现了三维array这种数据,所以我加了一个步骤,将其降维成一维就好了

def decode_text(labels, vocabs, end_token = '</s>'):
    results = []
    if isinstance(labels, list) == False and labels.ndim>1:
        labels_one = labels.reshape(-1).astype(int)
        for idx in labels_one:
            word = vocabs[idx]
            if word == end_token:
                return ' '.join(results)
            results.append(word)
        return ' '.join(results)

    for idx in labels:
        word = vocabs[idx]
        if word == end_token:
            return ' '.join(results)
        results.append(word)
    return ' '.join(results)

我这边也是这个问题,跑起来了,就是不知道这样改有问题没

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

9 participants