開(kāi)放式文本生成(Open-Ended Text Generation)
1 引言
開(kāi)放式文本生成(Open-Ended Text Generation)通俗一點(diǎn)兒來(lái)說(shuō)就是續(xù)寫(xiě)句子。我們以前使用馬爾科夫鏈產(chǎn)生新的文本《馬爾可夫鏈(Markov chain)隨機(jī)產(chǎn)生新的文檔》,可以認(rèn)為是續(xù)寫(xiě)句子的一種方法。在開(kāi)放式文本生成中,已知一個(gè)給定的句子,目標(biāo)是按照這個(gè)句子創(chuàng)建一個(gè)連貫的文本,使得句子能夠延續(xù)下去。Transformers的管道名為"text-generation",其構(gòu)建基礎(chǔ)是因果語(yǔ)言模擬(causal language modeling), 默認(rèn)的模型是GPT-2,Top-K采樣。
from transformers import pipelinetext_generator = pipeline("text-generation")
管道對(duì)象調(diào)用方法generate()來(lái)生成文本。可以用max_length和do_sample方法重載默認(rèn)參數(shù)。在下面的測(cè)試中,除了使用GPT-2外,也使用distilgpt2和gpt2-large(3.25G)進(jìn)行了觀察。
2 實(shí)例
(1) 輸入的文本 text = "These solutions have been combined with probabilistic Monte Carlo methods to identify critical step paths."【這些解決方案與概率蒙特卡洛方法相結(jié)合,以確定關(guān)鍵階梯路徑。】
生成的文本如下:
The study was supported by the National Science Foundation. The results of the study are published in the journal Nature. "We have shown that the probabilistic approach is able to identify the critical step paths that are necessary for the development of a new system," said lead author Dr. Michael J. H. Hirsch, a professor of physics at the University of California, Berkeley. "This is a major step forward in the development of a new system." 【這些解決方案與概率蒙特卡洛方法相結(jié)合,以確定關(guān)鍵階梯路徑。這項(xiàng)研究得到了美國(guó)國(guó)家科學(xué)基金會(huì)的支持。該研究的結(jié)果發(fā)表在《自然》雜志上。"我們已經(jīng)表明,概率方法能夠確定開(kāi)發(fā)一個(gè)新系統(tǒng)所需的關(guān)鍵階梯路徑," 主要作者、加州大學(xué)伯克利分校物理學(xué)教授Michael J. Hirsch博士說(shuō)。"這是開(kāi)發(fā)新系統(tǒng)的一個(gè)重要步驟"。】
(2) 輸入的文本 text ="Recent research indicates that brittle fracture and step-path failure are important considerations in both natural high-mountain and engineered rock slopes."【最近的研究表明,脆性斷裂和階梯式破壞是自然高山和工程巖坡的重要考慮因素。】
生成的文本如下:
The following table summarizes the results of a series of studies on the effects of fracture and step-path failure on rock slopes. Table 1. Effects of fracture and step-path failure on rock slopes (in inches) 【下表總結(jié)了一系列關(guān)于斷裂和階梯式破壞對(duì)巖坡影響的研究結(jié)果。表1. 斷裂和階梯式破壞對(duì)巖坡的影響(單位:英寸)】
3 結(jié)束語(yǔ)
開(kāi)放式文本生成提供了一種自動(dòng)續(xù)寫(xiě)句子的方法。不過(guò),生成的句子盡管在語(yǔ)法上滿足了要求,但在語(yǔ)義上和邏輯上仍然顯得文理不通,就像上面實(shí)例所示的一樣。
工程師必備
- 項(xiàng)目客服
- 培訓(xùn)客服
- 平臺(tái)客服
TOP




















