luhua-rain / mrc_competition_dureader Goto Github PK
View Code? Open in Web Editor NEW机器阅读理解 冠军/亚军代码及中文预训练MRC模型
机器阅读理解 冠军/亚军代码及中文预训练MRC模型
感谢大佬的分享,不过大佬我想问一下,为什么的把模型下载到本地来调用与直接用的huggingface的API结果不一样呢?是huggingface的API部署的模型跟公开的出来的这个模型不是同一个嘛?他们好像实验的时候,得到的答案跟huggingface上的答案也是不一样的#39
感谢您的代码,我已经跑通但是得到的结果却比较差
b'{"errorMsg": "success", "errorCode": 0, "data": [{"type": "BOTH", "name": "ROUGE-L", "value": 39.79}, {"type": "BOTH", "name": "BLEU-4", "value": 32.93}]}'
我用的BERT是最新的中文全词覆盖BERT BERT-wwm-ext, Chinese,按道理说应该比您这里的结果还要好一些才对。另外,如果想提交到官方网站的话应该提交哪份文件呢?
Results: {'exact': 79.77632805219012, 'f1': 80.07492714389267, 'total': 3219, 'HasAns_exact': 79.77632805219012, 'HasAns_f1': 80.07492714389267, 'HasAns_total': 3219, 'best_exact': 79.77632805219012, 'best_exact_thresh': 0.0, 'best_f1': 80.07492714389267, 'best_f1_thresh': 0.0}
Successfully installed torchtext-0.7.0,下载的这个版本,然后运行Python3 train.py会报上面那个错,没有动态库?请问怎么解决
您的代码中最大序列长度是512,这个怎么来的?我看全词覆盖的Bert模型也没给出当时预训练时的最大序列长度。
如题,想请教训练完之后如何做成问答系统。
search.dev.json 和 zhidao.dev.json 各有5000条数据,但是跑完run_squad.py后的数据只有6000多条,我觉得应该有10000条,dev数据可以筛选得这么多吗?
想问一下大家,你们运行这个模型的配置是多少G的内存?运行了多长时间?最后模型的效果如何?
predicting.py 这个文件里用到了这个文件但是我好像找不到这个文件是怎么生成的
你好,我想问一下您自己写的预处理 和 官方提供的那个预处理数据集有区别吗。
请问提到的multi-task是怎么样的一种思路,想学习参考一下
PROCESS_NAME="$1"
case $PROCESS_NAME in # 这个位置报错
--para_extraction)
# Start paragraph extraction
if [ ! -d ../data ]; then
echo "Please download the preprocessed data first (See README - Preprocess)"
exit 1
fi
paragraph_extraction ../data ../data/extracted
;;
--prepare|--train|--evaluate|--predict)
# Start Paddle baseline
python run.py $@
;;
*)
echo $"Usage: $0 {--para_extraction|--prepare|--train|--evaluate|--predict}"
esac
运行sh run.sh --para_extraction时报错
run.sh: 35: run.sh: Syntax error: word unexpected (expecting "in")
感觉语法也没问题,找来找去都没搞懂是哪里错了,有大佬知道吗?
用以下模型对一个法律判决书做问答抽取信息:
'luhua/chinese_pretrain_mrc_roberta_wwm_ext_large'
'luhua/chinese_pretrain_mrc_macbert_large'
抽取被告人、徒刑等信息都正常,但是想抽取依据的法律和条文,怎么也得不到想要的效果。
比如抽取这一段里面的法律条文:
被告人陶某某自愿认罪认罚,可以从宽处理。综上,依据《中华人民共和国刑法》第二百六十六条,第六十七条第三款,第六十四条,《中华人民共和国刑事诉讼法》第十五条之规定,判决如下:
正确的结果应该是:
《中华人民共和国刑法》第二百六十六条,第六十七条第三款,第六十四条,《中华人民共和国刑事诉讼法》第十五条
实际测试结果:
Question: 判决依据是
{'score': 0.33327004313468933, 'start': 1525, 'end': 1537, 'answer': '连云港市海州区人民检察院'}
Question: 判决依据什么法律
{'score': 0.09680692106485367, 'start': 1727, 'end': 1730, 'answer': '诈骗罪'}
Question: 依据《中华人民共和国刑法》哪几条
{'score': 0.11693647503852844, 'start': 1666, 'end': 1673, 'answer': '第二百六十六条'}
请教一下,这种情况,有什么好办法。
测试代码:https://github.com/tigerzhang/bert-qa/blob/main/test-transformers-models.py#L43
您好,想要向您请教一下,预训练使用了多大数据量的数据,训练了多长时间。比赛中给出的训练集是作为下游任务进行微调,还是在预训练过程中也使用了该数据。不胜感激
你好,分词部分为什么没有使用例如:
text = '你好,明天'
token = ['你', '#好', ',', '明', '#天']
这种格式去转换成 input_ids 进行训练呢?
原版代码只改动了数据集的路径,执行sh train_bert.sh
进行训练。
报错如下:
File "main_bert.py", line 335
res_baidu = baidu_evaluate(f'{args.data_dir}/{args.predict_file}', f'{args.output_dir}/predictions_dev_{global_step}.json')
^
SyntaxError: invalid syntax
请问squad_convert_examples_to_features需要运行多久才可以转换完成
Training beyond specified 't_total' steps with schedule warmup_linear. Learning rate set to 0.0. Please set 't_total' of BertAdam correctly.
请问后台一直提示这个,是什么原因呢?args.py中的test_lines已经设置为train.data文件的行数了
有个问题想请教大神,为何我跑了大大小小很多歌Dureader的项目,包括百度dureader的原项目,bleu和l-rougue从来没有超过个位数,为何你们的分数却如此之高。
checklist/robust 请问这两部分什么时候能开放出来呢,想学习一下@basketballandlearn
您好,我想问下数据集是删除了吗,我看了下zhidao.train.json里面的数据只有1060行,没有评论说的5000多行,而且dev、train、test三个数据好像数据都是一样的
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.
Connection closed by foreign host.
运行predicting,就会断开服务器,怎么解决呢
你好,问下在readme里提到的网上收集的大量中文MRC数据,这份数据集能否分享一下,感谢!
您好, 在这个目录下 Dureader-Bert/Dureader/predict/predicting.py
, 有一段代码没看懂
在find_best_answer_for_passage
函数中, while True
跑三个循环这里是为什么这么定义的,
每次预测出的start跟end位置相反就全部置为0重来, 似乎讲不通..
感觉跟其他模型中用动态规划的思路求最大score的区间方式不太一样.
附上代码:
def find_best_answer_for_passage(start_probs, end_probs, passage_len, question):
best_start, best_end, max_prob = -1, -1, 0
start_probs, end_probs = start_probs.unsqueeze(0), end_probs.unsqueeze(0)
prob_start, best_start = torch.max(start_probs, 1)
prob_end, best_end = torch.max(end_probs, 1)
num = 0
while True:
if num > 3:
break
if best_end >= best_start:
break
else:
start_probs[0][best_start], end_probs[0][best_end] = 0.0, 0.0
prob_start, best_start = torch.max(start_probs, 1)
prob_end, best_end = torch.max(end_probs, 1)
num += 1
max_prob = prob_start * prob_end
if best_start <= best_end:
return (best_start, best_end), max_prob
else:
return (best_end, best_start), max_prob
我觉得squadexample这个类里面的这里有些问题吧
for c in self.context_text:
就这里转换位置的时候,因为context_text是个字符串,如果字符串里面没有空格,那么得到的char_to_word_offset里面就全都是0和1.。。这里是不是有一些问题啊?因为我看您在create example的时候并没有进行特殊处理,只是原始的字符串。我运行了一下发现会出现这种问题。谢谢!
感谢楼主的code和分享。执行sh run.sh --para_extraction报错,这个因为官方是用的python2.7。用py3报错信息为: init() got an unexpected keyword argument 'encoding'
,把json.dumps()改成python3版本后,解决这个错误了。
但依然不能执行,这个代码if p_idx < para_id:报错:提示int不能和None做比较。
您好!我按照您的代码跑完,但达不到您的效果,大概只有30多左右,请问您知道是哪里的问题吗?或者我需要改哪里的参数?
SQuAD2.0中没有对type的定义 自建数据集中没有这个字段对训练结果会有影响吗
我粗看了下数据处理,好像没有进行pad ,这样送进模型不会有问题吗?
下载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
请问大佬,我在python3 util.py中将路径改为测试集数据,报错,由于测试集中的数据格式与devset中不一样,因此报错,请问如何处理
main_bert.py里的一行代码: apex.amp.register_half_function(torch, "einsum")
我看到网上说的:函数(如einsum)暂不支持FP16加速, 这是怎么肥事?
如果方便的话,麻烦您能分享一些继续预训练的经验,包括但不限于:
1.预训练任务;
2.不同预训练模型,再次预训练时的差异;
3.超参数设置(是否需要根据训练数据量调整,怎么调整);
4.分段预训练是否有效,例如:第一次预训练使用10W数据,然后再此基础上用另外10W数据再次预训练,然后重复此过程;
5.根据您的经验,您是如何判断预训练在什么时候可以结束;
6.等等。
prior_scores=(0.44, 0.23, 0.15, 0.09, 0.07)
是自己写的,还是有什么依据或者说法?
1.find_best_answer()函数里prior_scores的这几个概率有什么说法吗?为什么要加?怎么定出来的?
2.你们的code跑dev的分数,用到'most_related_para'标签,这个在跑dev的分数时,确定是可以用的吗?我是指如果dev的分数要公开
3.Q和A合并组成512时,A提前删掉了len(Q)长度的切割字符,为什么呢?
在第二步运行时报错:
Model name 'bert-base-chinese' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese-vocab.txt' was a path or url but couldn't find any file associated to this path or url.
AttributeError: 'NoneType' object has no attribute 'convert_tokens_to_ids'
请问你的分数是按照现在上传的代码得出来的吗,要按照代码里注释了按照分数排序的语句吗(paragrahs extraction文件),感觉注释了只是选取前5段会更低?期待解答,谢谢
使用roberate_wwm_large_ext会报错CUDA:out of memory, 是因为模型的参数太大导致显存放不下是嘛,用的是10G的显存,请问题主训练使用的显存大小为多大啊
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
tokenizer = AutoTokenizer.from_pretrained("luhua/chinese_pretrain_mrc_roberta_wwm_ext_large")
model = AutoModelForQuestionAnswering.from_pretrained("luhua/chinese_pretrain_mrc_roberta_wwm_ext_large")
QA = pipeline('question-answering', model=model, tokenizer=tokenizer)
QA_input = {'question': "著名诗歌《假如生活欺骗了你》的作者是",'context': "普希金从那里学习人民的语言,吸取了许多有益的养料,这一切对普希金后来的创作产生了很大的影响。这两年里,普希金创作了不少优秀的作品,如《囚徒》、《致大海》、《致凯恩》和《假如生活欺骗了你》等几十首抒情诗,叙事诗《努林伯爵》,历史剧《鲍里斯·戈都诺夫》,以及《叶甫盖尼·奥涅金》前六章。"}
QA(QA_input)
这样返回答案是context,试了很多都是这样。
能麻烦帮忙看一下吗?谢谢!
不好意思。 打扰了。 后面的bert训练知道 但是不知道你最初为什么要来一个抽取,这里主要抽取具体是想干什么? 感觉处理过的数据貌似跟原始数据没啥差别。。
代码乱七八糟 还有很多python2语法
你好,哈工大讯飞的Bert模型无法下载,请问可以提供下相关文件吗?
还有,哈工大的是基于词重新训练的Bert的模型吧?这个能和官方的基于字的中文Bert模型一起使用么?
你好,请问你这边显示的dev data的metric结果,选取most_related_paragraph的方法是什么呢,根据question和paragraph之间的score?还是answer和paragraph之前的score呢,谢谢
OSError: Can't load '../init_model//roberta_wwm_ext/config.json'. Make sure that:
'../init_model//roberta_wwm_ext/config.json' is a correct model identifier listed on 'https://huggingface.co/models'
or '../init_model//roberta_wwm_ext/config.json' is the correct path to a directory containing a 'config.json' file
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.