CodeLee24
2021-07-21 10:53
采纳率: 75%
浏览 80

BERT问题,无法解决,求帮助?

自建的类,但是这个错误就是没办法解决,求帮助啊
Traceback (most recent call last):
File "D:/desk/bert-master333/bert-master/run_classifier.py", line 1024, in
tf.app.run()
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "D:\anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 303, in run
_run_main(main, args)
File "D:\anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "D:/desk/bert-master333/bert-master/run_classifier.py", line 885, in main
train_examples = processor.get_train_examples(FLAGS.data_dir)
File "D:/desk/bert-master333/bert-master/run_classifier.py", line 380, in get_train_examples
self._read_tsv(os.path.join(data_dir, "train.csv")), "train")
File "D:/desk/bert-master333/bert-master/run_classifier.py", line 410, in _create_examples
label = tokenization.convert_to_unicode(line[1])
IndexError: list index out of range

class limengnanProcessor(DataProcessor):

    def get_train_examples(self, data_dir):
        return self._create_examples(
            self._read_tsv(os.path.join(data_dir, "train.csv")), "train")

    def get_dev_examples(self, data_dir):
        return self._create_examples(
            self._read_tsv(os.path.join(data_dir, "dev.csv")), "dev")

    def get_test_examples(self, data_dir):
        return self._create_examples(
            self._read_tsv(os.path.join(data_dir, "test.csv")), "test")

    def get_labels(self):
        return ['0','1']

    def _read_tsv(cls, input_file, quotechar=None):
        with tf.gfile.Open(input_file, "r") as f:
            reader = csv.reader(f, delimiter="&", quotechar=quotechar)
            lines = []
            for line in reader:
                lines.append(line)
            return lines

    def _create_examples(self, lines, set_type):
        examples = []
        for (i, line) in enumerate(lines):
            guid = "%s-%s" % (set_type, i)
            if set_type == "test":
                text_a = tokenization.convert_to_unicode(line[0])
                label = "0"
            else:
                text_a = tokenization.convert_to_unicode(line[0])
                label = tokenization.convert_to_unicode(line[1])
            if label not in ['0','1']:
                continue

            examples.append(
                InputExample(guid=guid, text_a=text_a, text_b=None, label=label))
        return examples

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题