MRC_Competition_Dureader
MRC_Competition_Dureader copied to clipboard
predict 结果是no answer
下载chinese_pretrain_mrc_roberta_wwm_ext_large
到本地
参数为:
model_name = "roberta_wwm_ext_large" # "chinese_pretrain_mrc_macbert_large"
model_type = 'bert'
threads = 24
eval_batch_size = 64
max_seq_length = 384
max_query_length = 32
doc_stride = 128
n_best_size = 10
max_answer_length = 384
do_lower_case = True
version_2_with_negative = False
null_score_diff_threshold = 0.0
verbose_logging = False
output_prediction_file = None
output_nbest_file = None
output_null_log_odds_file = None
predict 代码如下
examples = []
example = SquadExample(
qas_id='f388cc7597def765543c1a6d00b19018',
question_text='张家港汽车站在哪里',
context_text="""1.张家港北站:位于南丰镇辖区内,北至内河泗兴港,南至市铁路专用线,西至沪通铁路,东至规划经四路(双丰公路西侧),面积约
2.6平方公里。 是货运站,沪通铁路沿线办理货运的中间站,设正线2条,到发线3条,有效长1050m。运输品类主要为集装箱、零担、笨重粗杂等。还设货场一处,牵出
线1条,有效长350m。货场初期占地185亩,其中围墙内装卸区100.7亩。货场内设货物线两条,具备笨重粗杂线装卸、仓库站台线装、粗杂货区装卸和仓库等功能。 >站点最新进展:目前,张家港北站范围的路基施工作业已完成,货场暂时用作铺轨基地,站区配套用房计划与张家港站同步实施。图片来源:张家港新闻 2.张家港站:>位于塘桥镇新204国道东侧,人民路北侧。 站前广场为两层结构,负二层是地铁车站,负一层是地下停车场。站前广场工程涉及地上空间广场、道路以及地下停车场>与地铁站,其中,地下停车场可容纳800辆车停放。本项目建设内容分为站前核心区(主要为广场和道路等)和铁路站场桥下区(主要为停车场和地铁区间等),总用地面
积约7.4公顷,总建筑面积约6.7万㎡。 站点最新进展:2020年7月1日,站房和站前广场将与沪通铁路同步投运。 ▽效果图""",
answer_text='',
start_position_character=None,
is_impossible=True,
answers=[],
)
examples.append(example)
features, dataset = squad_convert_examples_to_features_orig(
examples=examples,
tokenizer=tokenizer,
max_seq_length=max_seq_length,
doc_stride=doc_stride,
max_query_length=max_query_length,
is_training=False,
return_dataset="pt",
threads=threads,
)
eval_sampler = SequentialSampler(dataset)
eval_dataloader = DataLoader(dataset, sampler=eval_sampler, batch_size=eval_batch_size)
def to_list(tensor):
return tensor.detach().cpu().tolist()
all_results = []
for batch in tqdm(eval_dataloader, desc="Evaluating"):
model.eval()
batch = tuple(t.to('cuda') for t in batch)
with torch.no_grad():
inputs = {
"input_ids": batch[0],
"attention_mask": batch[1],
"token_type_ids": batch[2],
}
example_indices = batch[3]
if model_type in ["xlm", "roberta", "distilbert", "camembert"]:
del inputs["token_type_ids"]
outputs = model(**inputs)
for i, example_index in enumerate(example_indices):
eval_feature = features[example_index.item()]
unique_id = int(eval_feature.unique_id)
output = [to_list(output[i]) for output in outputs]
start_logits, end_logits = outputs
result = SquadResult(unique_id, start_logits, end_logits)
all_results.append(result)
predictions = compute_predictions_logits(
examples,
features,
all_results,
n_best_size,
max_answer_length,
do_lower_case,
output_prediction_file,
output_nbest_file,
output_null_log_odds_file,
verbose_logging,
version_2_with_negative,
null_score_diff_threshold,
tokenizer
)
返回结果为no answer
我现在直接使用pipeline测试一下模型的结果,模型直接输出输入的整个context作为答案,好家伙
跟https://huggingface.co/luhua/chinese_pretrain_mrc_roberta_wwm_ext_large
测试结果不一样
我现在直接使用pipeline测试一下模型的结果,模型直接输出输入的整个context作为答案,好家伙
老铁你解决了吗。。。我也想用pipeline @basketballandlearn
我现在直接使用pipeline测试一下模型的结果,模型直接输出输入的整个context作为答案,好家伙
是的我也是一样的问题,是不是大佬模型传错了啊
需要升级transformers
需要升级transformers
后来确认不是transformers的问题,是下载的模型有问题,不要下载好解压进去,要直接代码下载缓存好