NLP-文本摘要:利用预训练模型进行文本摘要任务【transformers:pipeline、T5、BART、Pegasus】

本文主要是介绍NLP-文本摘要:利用预训练模型进行文本摘要任务【transformers:pipeline、T5、BART、Pegasus】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、pipeline

可以使用pipeline快速实现文本摘要

from transformers import pipelinesummarizer = pipeline(task="summarization", model='t5-small')text = """summarize: (CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyresult = summarizer(text, max_length=130, min_length=30, do_sample=False)print('result = ', result)

打印结果:

Token indices sequence length is longer than the specified maximum sequence length for this model (593 > 512). Running this sequence through the model will result in indexing errors
result =  [{'summary_text': 'a new group of bishops and archbishops will become cardinals . they come from 13 countries from every continent . the new cards are often referred to as the princes of the Catholic Church .'}]Process finished with exit code 0

二、T5

方式01、from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py
from transformers import AutoTokenizer, AutoModelForSeq2SeqLMtokenizer = AutoTokenizer.from_pretrained(r'D:\Pretrained_Model\t5-base')
model = AutoModelForSeq2SeqLM.from_pretrained(r'D:\Pretrained_Model\t5-base')# 用T5做文本摘要任务,前面加 "summarize:"识别符
text = """summarize: (CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyinputs = tokenizer(text, max_length=1024, truncation=True, return_tensors='pt')print('inputs = ', inputs)summary_ids = model.generate(inputs['input_ids'])print('\nsummary_ids = ', summary_ids)print([tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids])
print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))

打印结果:

Ignored unknown kwarg option direction
inputs =  {'input_ids': tensor([[21603,    10,    41,   254, 17235,    61,  3809,     8,   511,    97,383,   112,     3, 16281,  4710,     6, 17384, 11065,    65,  2162,3,     9,   126,   563,    13, 25214,     7,    11, 11508, 11514,10776,     7,   356,    12,   582,   895, 10270,     7,  1636,    11,79,   369,    45,    66,   147,     8,   296,     5, 17384, 11065,243,  1771,    24,     3,    88,   133,  1520,     3,     9,  1338,13,   895, 10270,     7,    30,  2083,   968,    96,    26,  7920,84,    27,    56,   564,   627,   126, 21967,     7,   113,     6,1107,    45,  1179,  1440,    45,   334, 10829,     6,  6571,     8,3,  8482,     7, 26175,  2416,   344,     8,  2345,    13,  7332,11,     8,  1090,  2345,    15,     7,   915,    16,     8,   296,976,  1315,    12, 25770,  5061,     5,   368,   895, 10270,     7,33,   373,   359,   250,    79,   356,     8,  5739,    16,     8,2078,    11,    92, 11924,     8,   416,  2783,    15,     6, 19602,5523, 25770, 25224,  1079,   301,     5, 10618,   243,     5,   328,33,  1664,     3,  4822,    12,    38,     8, 22277,     7,    13,8,  6502,  2345,     5,    37,   126,   895, 10270,     7,   369,45,  1440,   224,    38, 22138,     6,   368,  5725,    11, 27274,5,    96,  3713,    19,     3,     9,  2783,    15,   113,   182,231,  2746,    12,  1535,    91,    12,   151,    30,     8,  6346,7,     6,    11,    25,  3133,   217,    24,    16,    48,   356,976, 10618,   243,     5,    96,  3774,    31,    60,  2508,    81,895, 10270,     7,    45,  3115, 20633,  1747,     6,   114,  9702,781,   221,     6,     8,  5824,  3368,    13,   304,  1725,     9,6, 21099,     6, 10508,     6, 30758,   535,   299,    21,     8,511,    97,   437, 11065,    31,  4356,     6,   150,  5452,   263,8,   570,     5,    96,   371,    52, 11389,     7,    31,  3275,19,   182,   964,    10,   216,  2746,    12,   281,    12,     8,20187,   158,  5082,    88,  2593,  1066,   145,  1747,    24,    33,641,   420,    18,    88, 19649,    28,   895, 10270,     7,   976,10618,   243,     5, 14702,  5377,   155,   235,     6,     3,     9,5812,    13,  2078,   892,    44,  2566,   152,   636,    16,   368,5092,     6,  4466,    24, 11065,  2162,   112,   126, 21079,    13,895, 10270,     7,    30,     8,  6502,   377, 11535,    13,     8,12741,  8237,    63,     6,    84, 18681,    15,     7,     8,   719,13,     8, 22673,    12,  1850,    31,  3879,  4687,    16, 15659,109,  6015,     5,    96,  7638, 18886,    13,   386,  7624,  1076,45,   623,   550,     6,     8, 17384,    31,     7,  3703,    21,895, 10270,   497,    24,   334,   415,  2078, 15314,     3,     9,286,    44,     8,   600,   953,   535,    86,   119,  1234,     6,11065,  2746,     3,     9,    72,    20, 21411,  2078,    11,  2746,12,  1616,  5139,   912,    45,   422,  2597,    24,  2561,   623,45,  6502,   159,    51,    31,     7,   579,  6881,     6,  5377,155,   235,   243,     5,   466,   744,    31,    17,  1243, 11065,19,     8,   166, 19068,  5982,    12,     3,     9,   102,  2700,895, 10270,     7,    45,     8,  2421,   296,     6,   713,     5,22738,    16,     8, 13978,     7,     6,    46,  3094,   381,    13,6271,   797,  2078,   904,   130,  2650,   895, 10270,     7,     6,11,    16,     8,  8754,     7,     6,   472,     5,  1079,     3,4,     4, 13671,     6,  4068, 11065,    54,   106,  1601,   336,215,     6,  7817,     8,   166,   895, 10270,     7,    45,  3411,6,     8, 12729,    11,  2648,     5,    86,   811,    12,     8,627,   126,   895, 10270,     7, 11065,  2650,    30,  1771,     6,874, 10611, 11508, 11514, 10776,     7,    11, 25214,     7,    56,92,    36, 13242,    38,   895, 10270,     7,     5,  2506,   215,6, 17384, 11065,  7817,   957,   126,   895, 10270,     7,     6,379, 25214,     7,    45, 22179,    11,  4152,  2917,     9,  1699,7,    32,     5, 19602,    31,     7,  4173, 27575,    11,  2144,10333,   109,   377,  8038,    76,  9859,    12,    48,   934,     5,1]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1,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 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}summary_ids =  tensor([[    0,   126,   895, 10270,     7,   369,    45,  1179,  1440,    45,334, 10829,     3,     5,    79,    33,  1664,     3,  4822,    12]])['new cardinals come from 13 countries from every continent . they are sometimes referred to']
['new cardinals come from 13 countries from every continent . they are sometimes referred to']Process finished with exit code 0

方式02、from transformers import T5Tokenizer, T5ForConditionalGeneration

# https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py
from transformers import T5Tokenizer, T5ForConditionalGenerationtokenizer = T5Tokenizer.from_pretrained(r'D:\Pretrained_Model\t5-base')
model = T5ForConditionalGeneration.from_pretrained(r'D:\Pretrained_Model\t5-base')text = """(CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyinputs = tokenizer(text, max_length=1024, truncation=True, return_tensors='pt')print('inputs = ', inputs)summary_ids = model.generate(inputs['input_ids'])print('\nsummary_ids = ', summary_ids)print([tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids])
print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))

打印结果:

inputs =  {'input_ids': tensor([[   41,   254, 17235,    61,  3809,     8,   511,    97,   383,   112,3, 16281,  4710,     6, 17384, 11065,    65,  2162,     3,     9,126,   563,    13, 25214,     7,    11, 11508, 11514, 10776,     7,356,    12,   582,   895, 10270,     7,  1636,    11,    79,   369,45,    66,   147,     8,   296,     5, 17384, 11065,   243,  1771,24,     3,    88,   133,  1520,     3,     9,  1338,    13,   895,10270,     7,    30,  2083,   968,    96,    26,  7920,    84,    27,56,   564,   627,   126, 21967,     7,   113,     6,  1107,    45,1179,  1440,    45,   334, 10829,     6,  6571,     8,     3,  8482,7, 26175,  2416,   344,     8,  2345,    13,  7332,    11,     8,1090,  2345,    15,     7,   915,    16,     8,   296,   976,  1315,12, 25770,  5061,     5,   368,   895, 10270,     7,    33,   373,359,   250,    79,   356,     8,  5739,    16,     8,  2078,    11,92, 11924,     8,   416,  2783,    15,     6, 19602,  5523, 25770,25224,  1079,   301,     5, 10618,   243,     5,   328,    33,  1664,3,  4822,    12,    38,     8, 22277,     7,    13,     8,  6502,2345,     5,    37,   126,   895, 10270,     7,   369,    45,  1440,224,    38, 22138,     6,   368,  5725,    11, 27274,     5,    96,3713,    19,     3,     9,  2783,    15,   113,   182,   231,  2746,12,  1535,    91,    12,   151,    30,     8,  6346,     7,     6,11,    25,  3133,   217,    24,    16,    48,   356,   976, 10618,243,     5,    96,  3774,    31,    60,  2508,    81,   895, 10270,7,    45,  3115, 20633,  1747,     6,   114,  9702,   781,   221,6,     8,  5824,  3368,    13,   304,  1725,     9,     6, 21099,6, 10508,     6, 30758,   535,   299,    21,     8,   511,    97,437, 11065,    31,  4356,     6,   150,  5452,   263,     8,   570,5,    96,   371,    52, 11389,     7,    31,  3275,    19,   182,964,    10,   216,  2746,    12,   281,    12,     8, 20187,   158,5082,    88,  2593,  1066,   145,  1747,    24,    33,   641,   420,18,    88, 19649,    28,   895, 10270,     7,   976, 10618,   243,5, 14702,  5377,   155,   235,     6,     3,     9,  5812,    13,2078,   892,    44,  2566,   152,   636,    16,   368,  5092,     6,4466,    24, 11065,  2162,   112,   126, 21079,    13,   895, 10270,7,    30,     8,  6502,   377, 11535,    13,     8, 12741,  8237,63,     6,    84, 18681,    15,     7,     8,   719,    13,     8,22673,    12,  1850,    31,  3879,  4687,    16, 15659,   109,  6015,5,    96,  7638, 18886,    13,   386,  7624,  1076,    45,   623,550,     6,     8, 17384,    31,     7,  3703,    21,   895, 10270,497,    24,   334,   415,  2078, 15314,     3,     9,   286,    44,8,   600,   953,   535,    86,   119,  1234,     6, 11065,  2746,3,     9,    72,    20, 21411,  2078,    11,  2746,    12,  1616,5139,   912,    45,   422,  2597,    24,  2561,   623,    45,  6502,159,    51,    31,     7,   579,  6881,     6,  5377,   155,   235,243,     5,   466,   744,    31,    17,  1243, 11065,    19,     8,166, 19068,  5982,    12,     3,     9,   102,  2700,   895, 10270,7,    45,     8,  2421,   296,     6,   713,     5, 22738,    16,8, 13978,     7,     6,    46,  3094,   381,    13,  6271,   797,2078,   904,   130,  2650,   895, 10270,     7,     6,    11,    16,8,  8754,     7,     6,   472,     5,  1079,     3,     4,     4,13671,     6,  4068, 11065,    54,   106,  1601,   336,   215,     6,7817,     8,   166,   895, 10270,     7,    45,  3411,     6,     8,12729,    11,  2648,     5,    86,   811,    12,     8,   627,   126,895, 10270,     7, 11065,  2650,    30,  1771,     6,   874, 10611,11508, 11514, 10776,     7,    11, 25214,     7,    56,    92,    36,13242,    38,   895, 10270,     7,     5,  2506,   215,     6, 17384,11065,  7817,   957,   126,   895, 10270,     7,     6,   379, 25214,7,    45, 22179,    11,  4152,  2917,     9,  1699,     7,    32,5, 19602,    31,     7,  4173, 27575,    11,  2144, 10333,   109,377,  8038,    76,  9859,    12,    48,   934,     5,     1]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,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 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}summary_ids =  tensor([[    0,   126,   895, 10270,     7,   369,    45,  1179,  1440,    45,334, 10829,     3,     5,    79,    33,   557,     3,  4822,    12]])['new cardinals come from 13 countries from every continent . they are often referred to']
['new cardinals come from 13 countries from every continent . they are often referred to']Process finished with exit code 0

三、BART

方式01、from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py
from transformers import AutoTokenizer, AutoModelForSeq2SeqLMtokenizer = AutoTokenizer.from_pretrained(r'D:\Pretrained_Model\bart-base')
model = AutoModelForSeq2SeqLM.from_pretrained(r'D:\Pretrained_Model\bart-base')# 用T5做文本摘要任务,前面加 "summarize:"识别符
text = """summarize: (CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyinputs = tokenizer(text, max_length=1024, truncation=True, return_tensors='pt')print('inputs = ', inputs)summary_ids = model.generate(inputs['input_ids'])print('\nsummary_ids = ', summary_ids)print([tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids])
print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))

打印结果:

Ignored unknown kwarg option direction
inputs =  {'input_ids': tensor([[    0, 50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437, 40402,35,    36, 16256,    43,  2709,     5,   200,    86,   148,    39,13102,  5073,     6,  8509,  5075,    34,   585,    10,    92,   333,9, 19929,     8,  9599,   428, 32084,   278,     7,   555,  1886,17552,   480,     8,    51,   283,    31,    70,    81,     5,   232,4, 50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,  8509,5075,    26,   395,    14,    37,    74,   946,    10,   529,     9,1886, 17552,    15,   902,   501,    22, 37460,    61,    38,    40,766,   379,    92,  6293,    54,     6,   567,    31,   508,   749,31,   358,  9183,     6, 19318,     5,  9473,  3006,  1168, 26633,5678,   227,     5,  2197,     9,  8947,     8,     5,  1989, 37391,1455,    11,     5,   232,    60,   309,     7, 11484,  4611,     4,50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,   188,  1886,17552,    32,   460,   505,   142,    51,   278,     5,  6328,    11,5,  2352,     8,    67, 10371,     5,   220, 16627,     6,  3480,3596, 11484,  9821,   610,   226,     4,  3823,    26,     4,   252,32,  2128,  4997,     7,    25,     5, 39978,     9,     5,  4019,2197,     4, 50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,20,    92,  1886, 17552,   283,    31,   749,   215,    25, 13934,6,   188,  3324,     8,  7095,     4, 50118,  1437,  1437,  1437,1437,  1437,  1437,  1437,    22,   713,    16,    10, 16627,    54,182,   203,  1072,     7,  1338,    66,     7,    82,    15,     5,5510,     6,     8,    47,  2563,   192,    14,    11,    42,   278,60,  3823,    26,     4,    22,  1185,   214,  1686,    59,  1886,17552,    31,  3700, 16042,  2127,     6,   101,  6268,  3060,  2794,6,     5,  3073,  2946,     9, 17922,   102,     6, 12276,     6,6547,     6, 17609,    72, 50118,  1437,  1437,  1437,  1437,  1437,1437,  1437,   125,    13,     5,   200,    86,   187,  5075,   108,729,     6,   117,  1791,   156,     5,   889,     4, 50118,  1437,1437,  1437,  1437,  1437,  1437,  1437,    22, 38461,   354,   108,6184,    16,   182,   699,    35,    91,  1072,     7,   213,     7,5, 20456, 41464,   918,  1195,    87,  2127,    14,    32,   416,299,    12, 18888,    19,  1886, 17552,    60,  3823,    26,     4,50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,  5469,  3043,29765,     6,    10,  3097,     9,  2352,   750,    23,  3350,   260,589,    11,   188,  3123,     6,  1581,    14,  5075,   585,    39,92, 15777,     9,  1886, 17552,    15,     5,  4019, 37072,     9,5, 14230, 39880,     6,    61, 16293,  1626,     5,   825,     9,5,  3771,   118,     7,  5772,   108, 32357,    11, 26557,     4,50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,    22,  4148,23220,     9,   130, 11036,   604,    31,   444,   409,     6,     5,8509,    18,  5717,    13, 32533,   224,    14,   358,   400,  2352,8613,    10,   317,    23,     5,   380,  2103,    72, 50118,  1437,1437,  1437,  1437,  1437,  1437,  1437,    96,    97,  1617,     6,5075,  1072,    10,    55, 34930,  2352,     8,  1072,     7,  1798,3114,  2956,    31,   650,  1822,    14,  2662,   444,    31, 42580,18,   476,  5228,     6,  3043, 29765,    26,     4, 50118,  1437,1437,  1437,  1437,  1437,  1437,  1437,   280,   630,    75,  1266,5075,    16,     5,    78, 29476,  4822,     7,  9653,  1886, 17552,31,     5,  2623,   232,     6,   600,     4, 22856,    11,     5,18283,    29,     6,    41,  2284,   346,     9,  5862,   470,  2352,2262,    58,  1440,  1886, 17552,     6,     8,    11,     5,  7571,29,     6,   312,     4,   610, 26166, 24457,     6,  2661,  5075,32839,  1538,    94,    76,     6,  3873,     5,    78,  1886, 17552,31,  1429,     6,     5,  5639,     8,  1327,     4, 50118,  1437,1437,  1437,  1437,  1437,  1437,  1437,    96,  1285,     7,     5,379,    92,  1886, 17552,  5075,  1440,    15,   395,     6,   292,3562,  9599,   428, 32084,     8, 19929,    40,    67,    28,  7809,25,  1886, 17552,     4, 50118,  1437,  1437,  1437,  1437,  1437,1437,  1437,  1426,    76,     6,  8509,  5075,  3873,   753,    92,1886, 17552,     6,   217, 19929,    31, 17009,     8, 18294,  1243,21433,   139,     4, 50118,  1437,  1437,  1437,  1437,  1437,  1437,1437,  3480,    18,  3028, 12032,     8,  4845, 14286,   459,   274,5223,   257,  3162,     7,    42,   266,     4, 50118,     2]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}summary_ids =  tensor([[    2,     0,  1640, 16256,    43,  1437,  1437,  1437,  2537,  1437,1437,    36, 16256,    43,  2709,     5,   200,    86,   148,     2]])['(CNN)   Â   (CNN)For the second time during']
['(CNN)   Â   (CNN)For the second time during']Process finished with exit code 0

方式02、from transformers import BartTokenizer, BartForConditionalGeneration

# https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py
from transformers import BartTokenizer, BartForConditionalGenerationtokenizer = BartTokenizer.from_pretrained(r'D:\Pretrained_Model\bart-base')
model = BartForConditionalGeneration.from_pretrained(r'D:\Pretrained_Model\bart-base')text = """(CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyinputs = tokenizer(text, max_length=1024, truncation=True, return_tensors='pt')print('inputs = ', inputs)summary_ids = model.generate(inputs['input_ids'])print('\nsummary_ids = ', summary_ids)print([tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids])
print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))

打印结果:

inputs =  {'input_ids': tensor([[    0, 50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,  1437,36, 16256,    43,  2709,     5,   200,    86,   148,    39, 13102,5073,     6,  8509,  5075,    34,   585,    10,    92,   333,     9,19929,     8,  9599,   428, 32084,   278,     7,   555,  1886, 17552,480,     8,    51,   283,    31,    70,    81,     5,   232,     4,50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,  8509,  5075,26,   395,    14,    37,    74,   946,    10,   529,     9,  1886,17552,    15,   902,   501,    22, 37460,    61,    38,    40,   766,379,    92,  6293,    54,     6,   567,    31,   508,   749,    31,358,  9183,     6, 19318,     5,  9473,  3006,  1168, 26633,  5678,227,     5,  2197,     9,  8947,     8,     5,  1989, 37391,  1455,11,     5,   232,    60,   309,     7, 11484,  4611,     4, 50118,1437,  1437,  1437,  1437,  1437,  1437,  1437,   188,  1886, 17552,32,   460,   505,   142,    51,   278,     5,  6328,    11,     5,2352,     8,    67, 10371,     5,   220, 16627,     6,  3480,  3596,11484,  9821,   610,   226,     4,  3823,    26,     4,   252,    32,2128,  4997,     7,    25,     5, 39978,     9,     5,  4019,  2197,4, 50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,    20,92,  1886, 17552,   283,    31,   749,   215,    25, 13934,     6,188,  3324,     8,  7095,     4, 50118,  1437,  1437,  1437,  1437,1437,  1437,  1437,    22,   713,    16,    10, 16627,    54,   182,203,  1072,     7,  1338,    66,     7,    82,    15,     5,  5510,6,     8,    47,  2563,   192,    14,    11,    42,   278,    60,3823,    26,     4,    22,  1185,   214,  1686,    59,  1886, 17552,31,  3700, 16042,  2127,     6,   101,  6268,  3060,  2794,     6,5,  3073,  2946,     9, 17922,   102,     6, 12276,     6,  6547,6, 17609,    72, 50118,  1437,  1437,  1437,  1437,  1437,  1437,1437,   125,    13,     5,   200,    86,   187,  5075,   108,   729,6,   117,  1791,   156,     5,   889,     4, 50118,  1437,  1437,1437,  1437,  1437,  1437,  1437,    22, 38461,   354,   108,  6184,16,   182,   699,    35,    91,  1072,     7,   213,     7,     5,20456, 41464,   918,  1195,    87,  2127,    14,    32,   416,   299,12, 18888,    19,  1886, 17552,    60,  3823,    26,     4, 50118,1437,  1437,  1437,  1437,  1437,  1437,  1437,  5469,  3043, 29765,6,    10,  3097,     9,  2352,   750,    23,  3350,   260,   589,11,   188,  3123,     6,  1581,    14,  5075,   585,    39,    92,15777,     9,  1886, 17552,    15,     5,  4019, 37072,     9,     5,14230, 39880,     6,    61, 16293,  1626,     5,   825,     9,     5,3771,   118,     7,  5772,   108, 32357,    11, 26557,     4, 50118,1437,  1437,  1437,  1437,  1437,  1437,  1437,    22,  4148, 23220,9,   130, 11036,   604,    31,   444,   409,     6,     5,  8509,18,  5717,    13, 32533,   224,    14,   358,   400,  2352,  8613,10,   317,    23,     5,   380,  2103,    72, 50118,  1437,  1437,1437,  1437,  1437,  1437,  1437,    96,    97,  1617,     6,  5075,1072,    10,    55, 34930,  2352,     8,  1072,     7,  1798,  3114,2956,    31,   650,  1822,    14,  2662,   444,    31, 42580,    18,476,  5228,     6,  3043, 29765,    26,     4, 50118,  1437,  1437,1437,  1437,  1437,  1437,  1437,   280,   630,    75,  1266,  5075,16,     5,    78, 29476,  4822,     7,  9653,  1886, 17552,    31,5,  2623,   232,     6,   600,     4, 22856,    11,     5, 18283,29,     6,    41,  2284,   346,     9,  5862,   470,  2352,  2262,58,  1440,  1886, 17552,     6,     8,    11,     5,  7571,    29,6,   312,     4,   610, 26166, 24457,     6,  2661,  5075, 32839,1538,    94,    76,     6,  3873,     5,    78,  1886, 17552,    31,1429,     6,     5,  5639,     8,  1327,     4, 50118,  1437,  1437,1437,  1437,  1437,  1437,  1437,    96,  1285,     7,     5,   379,92,  1886, 17552,  5075,  1440,    15,   395,     6,   292,  3562,9599,   428, 32084,     8, 19929,    40,    67,    28,  7809,    25,1886, 17552,     4, 50118,  1437,  1437,  1437,  1437,  1437,  1437,1437,  1426,    76,     6,  8509,  5075,  3873,   753,    92,  1886,17552,     6,   217, 19929,    31, 17009,     8, 18294,  1243, 21433,139,     4, 50118,  1437,  1437,  1437,  1437,  1437,  1437,  1437,3480,    18,  3028, 12032,     8,  4845, 14286,   459,   274,  5223,257,  3162,     7,    42,   266,     4, 50118,     2]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}summary_ids =  tensor([[    2,     0,  1640, 16256,    43,   480,  1437,  1437,  2537,  1437,1437,  1437,    36, 16256,    43,  2709,     5,   200,    86,     2]])['(CNN) --  Â    (CNN)For the second time']
['(CNN) --  Â    (CNN)For the second time']Process finished with exit code 0

四、Pegasus

方式01、from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# https://github.com/huggingface/transformers/blob/master/src/transformers/models/pegasus/modeling_pegasus.py
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLMtokenizer = AutoTokenizer.from_pretrained(r'D:\Pretrained_model\pegasus-cnn_dailymail')
model = AutoModelForSeq2SeqLM.from_pretrained(r'D:\Pretrained_model\pegasus-cnn_dailymail')text = """(CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyinputs = tokenizer.encode(text)
inputs = torch.tensor([inputs])print('inputs = ', inputs)summary_ids = model.generate(inputs)print('\nsummary_ids = ', summary_ids)print([tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids])
print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))

打印结果:

inputs =  tensor([[  143, 40155,   158,   581,   109,   453,   166,   333,   169, 95987,108, 11481,  7756,   148,  1487,   114,   177,   456,   113, 35712,111, 66941,   116,   323,   112,   460, 30726,   116,  1315,   111,157,   331,   135,   149,   204,   109,   278,   107, 11481,  7756,243,  1342,   120,   178,   192,  1137,   114,   988,   113, 30726,116,   124,  1538,  1265,   198, 35871,   162,   125,   138,   442,738,   177, 18345,   170,   108,   792,   135,  1428,  1105,   135,290, 10156,   108, 14451,   109,   115,  8597, 32478,  1784,   317,109,  1887,   113,  6807,   111,   109,   970, 24353,   799,   115,109,   278,   745,   992,   112, 20525,  4474,   107,   351, 30726,116,   127,   329,   356,   262,   157,   323,   109,  4104,   115,109,  1588,   111,   163, 14094,   109,   352, 32577,   108, 11869,4244, 20525, 18672,  1084,  1054,   107,  6611,   243,   107,   322,127,  1254,  3795,   112,   130,   109, 54407,   113,   109,  4569,1887,   107,   139,   177, 30726,   116,   331,   135,  1105,   253,130, 16958,   108,   351,  3571,   111, 14838,   107,   198,   287,117,   114, 32577,   170,   221,   249,  1728,   112,  1111,   165,112,   200,   124,   109, 11691,   108,   111,   119,  2312,   236,120,   115,   136,   323,   745,  6611,   243,   107,   198,   417,131,   216,  1767,   160, 30726,   116,   135,  2222, 10912,  1262,108,   172,  5365, 23288,   108,   109,  3755,  2273,   113, 43439,108, 14668,   108,  6398,   108, 32671,   496,   343,   118,   109,453,   166,   381,  7756,   131,  2974,   108,   220,  3361,   266,109,   467,   107,   198, 59883,   131,  2293,   117,   221,   786,151,   285,  1728,   112,   275,   112,   109, 12483, 26941, 30713,3317,   880,   197,  1262,   120,   127,   506,   349,   121, 22564,122, 30726,   116,   745,  6611,   243,   107,  8751,  5706,  1418,497,   108,   114,  4609,   113,  1588,   689,   134, 69328,   502,115,   351,  3477,   108,  3151,   120,  7756,  1487,   169,   177,11598,   113, 30726,   116,   124,   109,  4569, 26717,   113,   109,60574,   108,   162, 56784,   109,   558,   113,   109, 33806,   112,1694,   131, 25910,   115, 26163,   107,   198,  1189, 11733,   113,339,  5509,  1024,   135,   571,   429,   108,   109, 11481,   131,116,  2257,   118, 30726,   416,   120,   290,   391,  1588,  8068,114,   295,   134,   109,   461,   826,   496,   222,   176,   989,108,  7756,  1728,   114,   154, 24500,  1588,   111,  1728,   112,1232,  6243,   675,   135,   360,  1724,   120,  2051,   571,   135,52403,   131,   116,   484,  3853,   108,  5706,  1418,   497,   243,107,   485,   591,   131,   144,  1021,  7756,   117,   109,   211,110, 39619, 18827,   112, 17717, 30726,   116,   135,   109,  1690,278,   108,   577,   107, 16591,   115,   109,  8821,   116,   108,142,  2186,   344,   113,  5249,   655,  1588,  3635,   195,  1729,30726,   116,   108,   111,   115,   109,  6939,   116,   108,   873,107,  1084, 61939, 12964,   108,  2901,  7756, 24828,  3792,   289,232,   108,  4486,   109,   211, 30726,   116,   135,  2466,   108,109,  6802,   111,  1922,   107,   222,   663,   112,   109,   738,177, 30726,   116,  7756,  1729,   124,  1342,   108,   668,  5774,66941,   116,   111, 35712,   138,   163,   129,  7051,   130, 30726,116,   107,  2882,   232,   108, 11481,  7756,  4486,  1925,   177,30726,   116,   108,   330, 35712,   135, 17256,   111, 58499, 55600,107, 11869,   131,   116,  4767, 18834,   111,  2333, 65534, 15391,28929,  5674,   112,   136,   731,   107,     1]])summary_ids =  tensor([[    0,   139,   177, 30726,   116,   331,   135,  1105,   253,   130,16958,   108,   351,  3571,   111, 14838,   110,   107,   106,  1667,3361,   266,   109,   467,   118,   109,   453,   166,   381,  7756,131,  2974,   110,   107,     1]])["The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar .<n>No Americans made the list for the second time since Francis' election ."]
["The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar .<n>No Americans made the list for the second time since Francis' election ."]Process finished with exit code 0

方式02、from transformers import PegasusTokenizer, PegasusForConditionalGeneration

# https://github.com/huggingface/transformers/blob/master/src/transformers/models/pegasus/modeling_pegasus.py
from transformers import PegasusTokenizer, PegasusForConditionalGenerationtokenizer = PegasusTokenizer.from_pretrained(r'D:\Pretrained_Model\pegasus-cnn_dailymail')
model = PegasusForConditionalGeneration.from_pretrained(r'D:\Pretrained_Model\pegasus-cnn_dailymail')text = """(CNN)For the second time during his papacy, Pope Francis has announced a new group of bishops and archbishops set to become cardinals -- and they come from all over the world.Pope Francis said Sunday that he would hold a meeting of cardinals on February 14 "during which I will name 15 new Cardinals who, coming from 13 countries from every continent, manifest the indissoluble links between the Church of Rome and the particular Churches present in the world," according to Vatican Radio.New cardinals are always important because they set the tone in the church and also elect the next pope, CNN Senior Vatican Analyst John L. Allen said. They are sometimes referred to as the princes of the Catholic Church.The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar."This is a pope who very much wants to reach out to people on the margins, and you clearly see that in this set," Allen said. "You're talking about cardinals from typically overlooked places, like Cape Verde, the Pacific island of Tonga, Panama, Thailand, Uruguay."But for the second time since Francis' election, no Americans made the list."Francis' pattern is very clear: He wants to go to the geographical peripheries rather than places that are already top-heavy with cardinals," Allen said.Christopher Bellitto, a professor of church history at Kean University in New Jersey, noted that Francis announced his new slate of cardinals on the Catholic Feast of the Epiphany, which commemorates the visit of the Magi to Jesus' birthplace in Bethlehem."On feast of three wise men from far away, the Pope's choices for cardinal say that every local church deserves a place at the big table."In other words, Francis wants a more decentralized church and wants to hear reform ideas from small communities that sit far from Catholicism's power centers, Bellitto said.That doesn't mean Francis is the first pontiff to appoint cardinals from the developing world, though. Beginning in the 1920s, an increasing number of Latin American churchmen were named cardinals, and in the 1960s, St. John XXIII, whom Francis canonized last year, appointed the first cardinals from Japan, the Philippines and Africa.In addition to the 15 new cardinals Francis named on Sunday, five retired archbishops and bishops will also be honored as cardinals.Last year, Pope Francis appointed 19 new cardinals, including bishops from Haiti and Burkina Faso.CNN's Daniel Burke and Christabelle Fombu contributed to this report.
"""
# CNN/DM答案:
# @highlight
# The 15 new cardinals will be installed on February 14
# @highlight
# They come from countries such as Myanmar and Tonga
# @highlight
# No Americans made the list this time or the previous time in Francis' papacyinputs = tokenizer(text, max_length=1024, truncation=True, return_tensors='pt')print('inputs = ', inputs)summary_ids = model.generate(inputs['input_ids'])print('\nsummary_ids = ', summary_ids)print([tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids])
print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))

打印结果:

inputs =  {'input_ids': tensor([[  143, 40155,   158,   581,   109,   453,   166,   333,   169, 95987,108, 11481,  7756,   148,  1487,   114,   177,   456,   113, 35712,111, 66941,   116,   323,   112,   460, 30726,   116,  1315,   111,157,   331,   135,   149,   204,   109,   278,   107, 11481,  7756,243,  1342,   120,   178,   192,  1137,   114,   988,   113, 30726,116,   124,  1538,  1265,   198, 35871,   162,   125,   138,   442,738,   177, 18345,   170,   108,   792,   135,  1428,  1105,   135,290, 10156,   108, 14451,   109,   115,  8597, 32478,  1784,   317,109,  1887,   113,  6807,   111,   109,   970, 24353,   799,   115,109,   278,   745,   992,   112, 20525,  4474,   107,   351, 30726,116,   127,   329,   356,   262,   157,   323,   109,  4104,   115,109,  1588,   111,   163, 14094,   109,   352, 32577,   108, 11869,4244, 20525, 18672,  1084,  1054,   107,  6611,   243,   107,   322,127,  1254,  3795,   112,   130,   109, 54407,   113,   109,  4569,1887,   107,   139,   177, 30726,   116,   331,   135,  1105,   253,130, 16958,   108,   351,  3571,   111, 14838,   107,   198,   287,117,   114, 32577,   170,   221,   249,  1728,   112,  1111,   165,112,   200,   124,   109, 11691,   108,   111,   119,  2312,   236,120,   115,   136,   323,   745,  6611,   243,   107,   198,   417,131,   216,  1767,   160, 30726,   116,   135,  2222, 10912,  1262,108,   172,  5365, 23288,   108,   109,  3755,  2273,   113, 43439,108, 14668,   108,  6398,   108, 32671,   496,   343,   118,   109,453,   166,   381,  7756,   131,  2974,   108,   220,  3361,   266,109,   467,   107,   198, 59883,   131,  2293,   117,   221,   786,151,   285,  1728,   112,   275,   112,   109, 12483, 26941, 30713,3317,   880,   197,  1262,   120,   127,   506,   349,   121, 22564,122, 30726,   116,   745,  6611,   243,   107,  8751,  5706,  1418,497,   108,   114,  4609,   113,  1588,   689,   134, 69328,   502,115,   351,  3477,   108,  3151,   120,  7756,  1487,   169,   177,11598,   113, 30726,   116,   124,   109,  4569, 26717,   113,   109,60574,   108,   162, 56784,   109,   558,   113,   109, 33806,   112,1694,   131, 25910,   115, 26163,   107,   198,  1189, 11733,   113,339,  5509,  1024,   135,   571,   429,   108,   109, 11481,   131,116,  2257,   118, 30726,   416,   120,   290,   391,  1588,  8068,114,   295,   134,   109,   461,   826,   496,   222,   176,   989,108,  7756,  1728,   114,   154, 24500,  1588,   111,  1728,   112,1232,  6243,   675,   135,   360,  1724,   120,  2051,   571,   135,52403,   131,   116,   484,  3853,   108,  5706,  1418,   497,   243,107,   485,   591,   131,   144,  1021,  7756,   117,   109,   211,110, 39619, 18827,   112, 17717, 30726,   116,   135,   109,  1690,278,   108,   577,   107, 16591,   115,   109,  8821,   116,   108,142,  2186,   344,   113,  5249,   655,  1588,  3635,   195,  1729,30726,   116,   108,   111,   115,   109,  6939,   116,   108,   873,107,  1084, 61939, 12964,   108,  2901,  7756, 24828,  3792,   289,232,   108,  4486,   109,   211, 30726,   116,   135,  2466,   108,109,  6802,   111,  1922,   107,   222,   663,   112,   109,   738,177, 30726,   116,  7756,  1729,   124,  1342,   108,   668,  5774,66941,   116,   111, 35712,   138,   163,   129,  7051,   130, 30726,116,   107,  2882,   232,   108, 11481,  7756,  4486,  1925,   177,30726,   116,   108,   330, 35712,   135, 17256,   111, 58499, 55600,107, 11869,   131,   116,  4767, 18834,   111,  2333, 65534, 15391,28929,  5674,   112,   136,   731,   107,     1]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}summary_ids =  tensor([[    0,   139,   177, 30726,   116,   331,   135,  1105,   253,   130,16958,   108,   351,  3571,   111, 14838,   110,   107,   106,  1667,3361,   266,   109,   467,   118,   109,   453,   166,   381,  7756,131,  2974,   110,   107,     1]])["The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar .<n>No Americans made the list for the second time since Francis' election ."]
["The new cardinals come from countries such as Ethiopia, New Zealand and Myanmar .<n>No Americans made the list for the second time since Francis' election ."]Process finished with exit code 0



参考资料:
Transformers预训练模型使用:文本摘要 Summarization

这篇关于NLP-文本摘要:利用预训练模型进行文本摘要任务【transformers:pipeline、T5、BART、Pegasus】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1128742

相关文章

大模型研发全揭秘:客服工单数据标注的完整攻略

在人工智能(AI)领域,数据标注是模型训练过程中至关重要的一步。无论你是新手还是有经验的从业者,掌握数据标注的技术细节和常见问题的解决方案都能为你的AI项目增添不少价值。在电信运营商的客服系统中,工单数据是客户问题和解决方案的重要记录。通过对这些工单数据进行有效标注,不仅能够帮助提升客服自动化系统的智能化水平,还能优化客户服务流程,提高客户满意度。本文将详细介绍如何在电信运营商客服工单的背景下进行

Andrej Karpathy最新采访:认知核心模型10亿参数就够了,AI会打破教育不公的僵局

夕小瑶科技说 原创  作者 | 海野 AI圈子的红人,AI大神Andrej Karpathy,曾是OpenAI联合创始人之一,特斯拉AI总监。上一次的动态是官宣创办一家名为 Eureka Labs 的人工智能+教育公司 ,宣布将长期致力于AI原生教育。 近日,Andrej Karpathy接受了No Priors(投资博客)的采访,与硅谷知名投资人 Sara Guo 和 Elad G

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

Retrieval-based-Voice-Conversion-WebUI模型构建指南

一、模型介绍 Retrieval-based-Voice-Conversion-WebUI(简称 RVC)模型是一个基于 VITS(Variational Inference with adversarial learning for end-to-end Text-to-Speech)的简单易用的语音转换框架。 具有以下特点 简单易用:RVC 模型通过简单易用的网页界面,使得用户无需深入了

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

业务中14个需要进行A/B测试的时刻[信息图]

在本指南中,我们将全面了解有关 A/B测试 的所有内容。 我们将介绍不同类型的A/B测试,如何有效地规划和启动测试,如何评估测试是否成功,您应该关注哪些指标,多年来我们发现的常见错误等等。 什么是A/B测试? A/B测试(有时称为“分割测试”)是一种实验类型,其中您创建两种或多种内容变体——如登录页面、电子邮件或广告——并将它们显示给不同的受众群体,以查看哪一种效果最好。 本质上,A/B测

图神经网络模型介绍(1)

我们将图神经网络分为基于谱域的模型和基于空域的模型,并按照发展顺序详解每个类别中的重要模型。 1.1基于谱域的图神经网络         谱域上的图卷积在图学习迈向深度学习的发展历程中起到了关键的作用。本节主要介绍三个具有代表性的谱域图神经网络:谱图卷积网络、切比雪夫网络和图卷积网络。 (1)谱图卷积网络 卷积定理:函数卷积的傅里叶变换是函数傅里叶变换的乘积,即F{f*g}

秋招最新大模型算法面试,熬夜都要肝完它

💥大家在面试大模型LLM这个板块的时候,不知道面试完会不会复盘、总结,做笔记的习惯,这份大模型算法岗面试八股笔记也帮助不少人拿到过offer ✨对于面试大模型算法工程师会有一定的帮助,都附有完整答案,熬夜也要看完,祝大家一臂之力 这份《大模型算法工程师面试题》已经上传CSDN,还有完整版的大模型 AI 学习资料,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

【生成模型系列(初级)】嵌入(Embedding)方程——自然语言处理的数学灵魂【通俗理解】

【通俗理解】嵌入(Embedding)方程——自然语言处理的数学灵魂 关键词提炼 #嵌入方程 #自然语言处理 #词向量 #机器学习 #神经网络 #向量空间模型 #Siri #Google翻译 #AlexNet 第一节:嵌入方程的类比与核心概念【尽可能通俗】 嵌入方程可以被看作是自然语言处理中的“翻译机”,它将文本中的单词或短语转换成计算机能够理解的数学形式,即向量。 正如翻译机将一种语言

AI Toolkit + H100 GPU,一小时内微调最新热门文生图模型 FLUX

上个月,FLUX 席卷了互联网,这并非没有原因。他们声称优于 DALLE 3、Ideogram 和 Stable Diffusion 3 等模型,而这一点已被证明是有依据的。随着越来越多的流行图像生成工具(如 Stable Diffusion Web UI Forge 和 ComyUI)开始支持这些模型,FLUX 在 Stable Diffusion 领域的扩展将会持续下去。 自 FLU