crownpku / Information-Extraction-Chinese

Chinese Named Entity Recognition with IDCNN/biLSTM+CRF, and Relation Extraction with biGRU+2ATT 中文实体识别与关系提取
2.23k stars 814 forks source link

tensorflow 1.10 运行报错 #80

Closed huwen2117 closed 6 years ago

huwen2117 commented 6 years ago

Traceback (most recent call last): File "D:\python\python install\helpers\pydev\pydev_run_in_console.py", line 53, in run_file pydev_imports.execfile(file, globals, locals) # execute the script File "D:\python\python install\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "G:/pythonDevelop/Extraction/NER_IDCNN_CRF/main.py", line 228, in tf.app.run(main) File "G:\pythonDevelop\venv1\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv)) File "G:/pythonDevelop/Extraction/NER_IDCNN_CRF/main.py", line 222, in main train() File "G:/pythonDevelop/Extraction/NER_IDCNN_CRF/main.py", line 153, in train train_manager = BatchManager(train_data, FLAGS.batch_size) File "G:/pythonDevelop/Extraction/NER_IDCNN_CRF\data_utils.py", line 285, in init self.batch_data = self.sort_and_pad(data, batch_size) File "G:/pythonDevelop/Extraction/NER_IDCNN_CRF\data_utils.py", line 293, in sort_and_pad batch_data.append(self.pad_data(sorted_data[ibatch_size : (i+1)batch_size])) TypeError: slice indices must be integers or None or have an index method

huwen2117 commented 6 years ago
def sort_and_pad(self, data, batch_size):
    num_batch = int(math.ceil(len(data) /batch_size))
    sorted_data = sorted(data, key=lambda x: len(x[0]))
    batch_data = list()
    for i in range(num_batch):
        batch_data.append(self.pad_data(sorted_data[i*batch_size : (i+1)*batch_size])) # line 293
    return batch_data
huwen2117 commented 6 years ago

I change 293 to this: batch_data.append(self.pad_data(sorted_data[int(i batch_size): int((i + 1) batch_size)]))