python - tensorflow.python.framework.errors_impl.OutOfRangeError:读取的字节数少于请求的字节数 [[{{node checkpoint_initializer_196}}]]
问题描述
我使用谷歌研究发布的 BERT 对我自己的数据集进行分类。我在源代码中创建了一个新类来指定我自己的分类任务,并在 Colab 上运行我的代码。运行文件中的 run_classifier.py 时发生错误。这是我的代码
创建我自己的任务
class MyProcessor(DataProcessor):
"""Base class for data converters for sequence classification data sets."""
def __init__(self):
self.labels = ['货物', '服务', '工程']
def get_train_examples(self, data_dir):
"""Gets a collection of `InputExample`s for the train set."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "train.tsv")), "train")
def get_dev_examples(self, data_dir):
"""Gets a collection of `InputExample`s for the dev set."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "val.tsv")), "val")
def get_test_examples(self, data_dir):
"""Gets a collection of `InputExample`s for prediction."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "test.tsv")), "test")
def get_labels(self):
return self.labels
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 = "货物"
else:
text_a = tokenization.convert_to_unicode(line[1])
label = tokenization.convert_to_unicode(line[0])
examples.append(InputExample(guid=guid, text_a=text_a, text_b=None, label=label))
return examples
@classmethod
def _read_tsv(cls, input_file, quotechar=None):
"""Reads a tab separated value file."""
with tf.gfile.Open(input_file, "r") as f:
reader = csv.reader(f, delimiter="\t", quotechar=quotechar)
lines = []
for line in reader:
lines.append(line)
return lines
跑
!python run_classifier.py \
--task_name=mytask \
--data_dir=data/ \
--bert_config_file=checkpoint/bert_config.json \
--init_checkpoint=checkpoint/bert_model.ckpt \
--vocab_file=checkpoint/vocab.txt \
--output_dir=./output/result_dir/ \
--max_seq_length=50 \
--do_train=true \
--do_eval=true \
----train_batch_size=128
解决方案
推荐阅读
- android - 是否可以将使用本机反应制作的 GUI 与本机代码 (kotlin) 中的实用方法相结合?
- google-sheets - 具有转置列的 Google 表格笛卡尔积
- unit-testing - Jest - 模拟承诺的 SQS 调用
- c++ - qt如何处理多时间信号槽连接?
- spring-boot - Spring boot,从 Gradle 5 中的测试中排除依赖项
- google-maps-api-3 - 谷歌地图LocalContextMapView:平移地图时不刷新
- webrtc - 在 Ant Media Server 中使用 WebRTC 观看带有 B 帧的 rtmp 流时出现抖动问题
- android - 导航抽屉:Gradle 不构建
- javascript - 如何检查字符串是否在 JSON 文件中并获取字符串的条目号
- spring-boot - IntelliJ IDEA 中的 Vaadin Flow .war 静态资源