模型:
ydshieh/bert2bert-cnn_dailymail-fp16
[这是通过转换原始的 PyTorch 版本得到的 TensorFlow 版本 Bert2Bert ]
该模型是在摘要生成任务上对 Bert2Bert 模型进行微调的结果。
Bert2Bert 是一个 EncoderDecoderModel 模型,意味着编码器和解码器都是 bert-base-uncased BERT 模型。通过使用 EncoderDecoderFramework ,可以简单地将这两个预训练模型加载到框架中:
bert2bert = TFEncoderDecoderModel.from_encoder_decoder_pretrained("bert-base-uncased", "bert-base-uncased")
TFEncoderDecoder 模型的解码器需要跨注意力层,并经常在自回归生成中使用因果遮蔽。因此,bert2bert 在 CNN/Daily Mail 数据集上进行微调,生成的模型 bert2bert-cnn_dailymail-fp16 在此处上传。
该模型并不是最先进的模型,但仍能够产生合理的摘要结果。它主要是作为 ? EncoderDecoder Framework 的概念验证进行微调的。
可以按照以下步骤使用该模型:
from transformers import AutoTokenizer, TFEncoderDecoderModel loc = "ydshieh/bert2bert-cnn_dailymail-fp16" model = TFEncoderDecoderModel.from_pretrained(loc) tokenizer = AutoTokenizer.from_pretrained(loc) article = """(CNN)Sigma Alpha Epsilon is under fire for a video showing party-bound fraternity members singing a racist chant. SAE's national chapter suspended the students, but University of Oklahoma President David Boren took it a step further, saying the university's affiliation with the fraternity is permanently done. The news is shocking, but it's not the first time SAE has faced controversy. SAE was founded March 9, 1856, at the University of Alabama, five years before the American Civil War, according to the fraternity website. When the war began, the group had fewer than 400 members, of which "369 went to war for the Confederate States and seven for the Union Army," the website says. The fraternity now boasts more than 200,000 living alumni, along with about 15,000 undergraduates populating 219 chapters and 20 "colonies" seeking full membership at universities. SAE has had to work hard to change recently after a string of member deaths, many blamed on the hazing of new recruits, SAE national President Bradley Cohen wrote in a message on the fraternity's website. The fraternity's website lists more than 130 chapters cited or suspended for "health and safety incidents" since 2010. At least 30 of the incidents involved hazing, and dozens more involved alcohol. However, the list is missing numerous incidents from recent months. Among them, according to various media outlets: Yale University banned the SAEs from campus activities last month after members allegedly tried to interfere with a sexual misconduct investigation connected to an initiation rite. Stanford University in December suspended SAE housing privileges after finding sorority members attending a fraternity function were subjected to graphic sexual content. And Johns Hopkins University in November suspended the fraternity for underage drinking. "The media has labeled us as the 'nation's deadliest fraternity,' " Cohen said. In 2011, for example, a student died while being coerced into excessive alcohol consumption, according to a lawsuit. SAE's previous insurer dumped the fraternity. "As a result, we are paying Lloyd's of London the highest insurance rates in the Greek-letter world," Cohen said. Universities have turned down SAE's attempts to open new chapters, and the fraternity had to close 12 in 18 months over hazing incidents.""" input_ids = tokenizer(article, return_tensors="tf").input_ids output_ids = model.generate(input_ids) summary = tokenizer.decode(output_ids[0], skip_special_tokens=True) print(summary) # should produce # sae was founded in 1856, five years before the civil war. the fraternity has had to work hard to change recently. the university of oklahoma president says the university's affiliation with the fraternity is permanently done. the sae has had a string of members in recent mon ths.
如需获取原始的 PyTorch BERT2BERT 模型,请按照本教程了解如何启动一个 BERT2BERT 模型:
获取的结果应为:
- | Rouge2 - mid -precision | Rouge2 - mid - recall | Rouge2 - mid - fmeasure |
---|---|---|---|
CNN/Daily Mail | 16.12 | 17.07 | 16.1 |