TW202030625A - Method and device for extracting main words through reinforcement learning - Google Patents
Method and device for extracting main words through reinforcement learning Download PDFInfo
- Publication number
- TW202030625A TW202030625A TW108132431A TW108132431A TW202030625A TW 202030625 A TW202030625 A TW 202030625A TW 108132431 A TW108132431 A TW 108132431A TW 108132431 A TW108132431 A TW 108132431A TW 202030625 A TW202030625 A TW 202030625A
- Authority
- TW
- Taiwan
- Prior art keywords
- classification
- network
- sentence
- strategy
- total loss
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/30—Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
- G06F16/33—Querying
- G06F16/3331—Query processing
- G06F16/334—Query execution
- G06F16/3344—Query execution using natural language analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/30—Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
- G06F16/35—Clustering; Classification
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/205—Parsing
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- Artificial Intelligence (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Audiology, Speech & Language Pathology (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Machine Translation (AREA)
Abstract
Description
本說明書一個或多個實施例涉及機器學習領域,尤其涉及利用強化學習的方式提取句子中的主幹詞的方法和裝置。One or more embodiments of this specification relate to the field of machine learning, and more particularly to methods and devices for extracting stem words in sentences by means of reinforcement learning.
電腦執行的自然語言處理和文本分析,例如意圖識別,事件抽取等,已經應用到多種技術場景中,例如智慧客服。在智慧客服中,需要對使用者的描述問題進行意圖識別,進而將其匹配到知識庫中的知識點,從而自動地回答用戶的問題。然而,用戶在進行問題描述時,特別是通過語音進行問題描述,例如電話交流溝通時,經常有一些口語描述,比如『嗯』『啊』『那個』『哦』『就是』等等,或者包含一些非重點的,不必要的詞語。這就需要把句子中主要的詞,即主幹詞提取出來,以便後續做語義分析和意圖識別。在進行事件抽取時,也需要排除一些停用詞,提取出主幹詞,從而優化事件提取的效果。 因此,希望能有改進的方案,可以有效地對句子中的主幹詞進行提取,從而優化文本分析效果。Computer-executed natural language processing and text analysis, such as intent recognition and event extraction, have been applied to a variety of technical scenarios, such as smart customer service. In smart customer service, it is necessary to identify the user's intent to describe the problem, and then match it to the knowledge points in the knowledge base, so as to automatically answer the user's question. However, when the user describes the problem, especially the problem description through voice, such as telephone communication, there are often some spoken descriptions, such as "um", "ah", "that", "oh", "yes", etc., or include Some non-essential, unnecessary words. This requires extracting the main words in the sentence, that is, the main words for subsequent semantic analysis and intention recognition. When performing event extraction, it is also necessary to exclude some stop words and extract the main words, so as to optimize the effect of event extraction. Therefore, it is hoped that there will be an improved scheme that can effectively extract the main words in the sentence, so as to optimize the effect of text analysis.
本說明書一個或多個實施例描述了一種利用強化學習系統提取主幹詞的方法和裝置。通過實施例中的方法和裝置,利用強化學習的方式進行主幹詞提取的訓練,從而減少人工標注成本,提高主幹詞提取效率,優化文本分析效果。 根據第一態樣,提供了一種通過強化學習提取主幹詞的方法,包括: 利用句子樣本集,訓練用於句子分類的分類網路; 利用當前策略參數下的策略網路,對所述句子樣本集中的第一樣本句子進行主幹詞提取,獲得第一主幹詞集合,並根據所述第一樣本句子中的詞語數目和所述第一主幹詞集合中的詞語數目,確定當前的第一損失; 利用所述分類網路對由所述第一主幹詞集合構成的第一備選句子進行分類處理,獲得所述第一備選句子的第一分類結果,並根據所述第一分類結果以及所述第一樣本句子的分類標籤,確定當前的第二損失; 根據所述當前的第一損失和當前的第二損失,確定當前的總損失; 在總損失減小的方向,至少更新所述策略網路,以用於從待分析句子中提取主幹詞。 在一個實施例中,策略網路包括第一嵌入層,第一處理層和第二處理層,所述利用策略網路對所述句子樣本集中的第一樣本句子進行主幹詞提取包括: 在所述第一嵌入層,獲得所述第一樣本句子中的各個詞的詞嵌入向量; 在所述第一處理層,根據所述詞嵌入向量,確定所述各個詞作為主幹詞的機率; 在所述第二處理層,至少根據所述機率,從所述各個詞中選擇至少一部分詞,構成所述第一主幹詞集合。 在一個進一步的實施例中,在所述第二處理層,從所述各個詞中選擇機率值大於預設閾值的詞,構成所述第一主幹詞集合。 根據一種實施方式,分類網路包括第二嵌入層和第三處理層,所述利用所述分類網路對由所述第一主幹詞集合構成的第一備選句子進行分類處理包括: 在所述第二嵌入層,獲得所述第一備選句子對應的句子嵌入向量; 在所述第三處理層,根據所述句子嵌入向量,確定所述第一備選句子的第一分類結果。 在一種實施方式中,策略網路和/或分類網路基於循環神經網路RNN。 在一個實施例中,上述方法還包括,確定所述總損失減小的方向,包括: 分別利用N群組原則參數下的所述策略網路處理所述第一樣本句子,獲得對應的N個主幹詞集合,並分別確定N個第一損失; 利用所述分類網路,對所述N個主幹詞集合分別對應的N個備選句子進行分類處理,獲得N個分類結果,並分別確定N個第二損失; 根據N個第一損失和N個第二損失,確定對應的N個總損失,以及所述N個總損失的均值; 確定損失值小於等於所述均值的至少一個第一總損失,以及損失值大於所述均值的至少一個第二總損失; 基於所述至少一個第一總損失和所述至少一個第二總損失,確定所述總損失減小的方向。 進一步的,在一個實施例中,上述N個分類結果是利用同一組分類參數下的所述分類網路,對所述N個備選句子分別進行分類處理而獲得;在這樣的情況下,所述N個總損失對應於所述N群組原則參數; 此時,確定所述總損失減小的方向,包括: 確定所述至少一個第一總損失對應的至少一組第一策略參數相對於當前策略參數的梯度的累積,作為正方向; 確定所述至少一個第二總損失對應的至少一組第二策略參數相對於當前策略參數的梯度的累積,作為負方向; 將所述正方向與所述負方向的相反方向疊加,作為所述總損失減小的方向。 進一步的,在上述情況下,可以在所述總損失減小的方向,更新所述策略網路中的當前策略參數。 在另一實施例中,所述N個分類結果是利用M組分類參數下的所述分類網路,對所述N個備選句子進行分類處理而獲得,其中M<=N;在這樣的情況下,所述N個總損失對應於N個參數集,其中第i參數集包括第i群組原則參數,和處理第i備選句子時所述分類網路對應的分類參數; 此時,確定所述總損失減小的方向包括: 確定所述至少一個第一總損失對應的至少一組第一參數集相對於當前策略參數的梯度的累積,作為第一正方向; 確定所述至少一個第二總損失對應的至少一組第二參數集相對於當前策略參數的梯度的累積,作為第一負方向; 將所述第一正方向與所述第一負方向的相反方向疊加,作為第一調整方向; 確定所述至少一個第一總損失對應的至少一組第一參數集相對於當前分類參數的梯度的累積,作為第二正方向; 確定所述至少一個第二總損失對應的至少一組第二參數集相對於當前分類參數的梯度的累積,作為第二負方向; 將所述第二正方向與所述第二負方向的相反方向疊加,作為第二調整方向; 將所述第一調整方向和第二調整方向的總和作為所述總損失減小的方向。 進一步的,在上述情況下,可以在所述第一調整方向,更新所述策略網路的當前策略參數;在所述第二調整方向,更新所述分類網路的當前分類參數。 根據一種實施方式,上述方法還包括: 將待分析的第二句子輸入所述策略網路; 根據所述策略網路的輸出,確定所述第二句子中的主幹詞。 根據第二態樣,提供了一種通過強化學習提取主幹詞的裝置,包括: 分類網路訓練單元,配置為利用句子樣本集,訓練用於句子分類的分類網路; 第一確定單元,配置為利用當前策略參數下的策略網路,對所述句子樣本集中的第一樣本句子進行主幹詞提取,獲得第一主幹詞集合,並根據所述第一樣本句子中的詞語數目和所述第一主幹詞集合中的詞語數目,確定當前的第一損失; 第二確定單元,配置為利用所述分類網路對由所述第一主幹詞集合構成的第一備選句子進行分類處理,獲得所述第一備選句子的第一分類結果,並根據所述第一分類結果以及所述第一樣本句子的分類標籤,確定當前的第二損失; 總損失確定單元,配置為根據所述當前的第一損失和當前的第二損失,確定當前的總損失; 更新單元,配置為在總損失減小的方向,至少更新所述策略網路,以用於從待分析句子中提取主幹詞。 根據第三態樣,提供了一種電腦可讀儲存媒體,其上儲存有電腦程式,當所述電腦程式在電腦中執行時,令電腦執行第一態樣的方法。 根據第四態樣,提供了一種計算設備,包括記憶體和處理器,其特徵在於,所述記憶體中儲存有可執行程式碼,所述處理器執行所述可執行程式碼時,實現第一態樣的方法。 根據本說明書實施例提供的方法和裝置,通過強化學習的方式,進行主幹詞提取的學習和訓練。更具體的,採用actor-critic方式的強化學習系統進行主幹詞提取,其中在強化學習系統中,策略網路作為actor,用於主幹詞提取;分類網路作為critic,用於對句子進行分類。可以利用現有的句子樣本庫作為訓練預料訓練分類網路,從而避免主幹詞標注的人工成本。經過初步訓練的分類網路即可對策略網路提取的主幹詞構成的句子進行分類,如此評估主幹詞提取的效果。通過對策略網路和分類網路的輸出結果均設置損失,根據總損失反覆訓練策略網路和分類網路,可以得到理想的強化學習系統。如此,可以在無需主幹詞人工標注的情況下,訓練得到理想的網路系統,實現對主幹詞的有效提取。One or more embodiments of this specification describe a method and device for extracting backbone words using a reinforcement learning system. Through the method and device in the embodiment, the training of stem word extraction is carried out in the manner of reinforcement learning, thereby reducing the cost of manual labeling, improving the efficiency of stem word extraction, and optimizing the effect of text analysis. According to the first aspect, a method for extracting stem words through reinforcement learning is provided, including: Use sentence sample sets to train a classification network for sentence classification; Use the strategy network under the current strategy parameters to extract the stem words of the first sample sentence in the sentence sample set to obtain the first stem word set, and according to the number of words in the first sample sentence and the The number of words in the first stem word set determines the current first loss; Use the classification network to classify the first candidate sentence formed by the first stem word set to obtain the first classification result of the first candidate sentence, and according to the first classification result and the State the classification label of the first sample sentence and determine the current second loss; Determine the current total loss according to the current first loss and the current second loss; In the direction where the total loss is reduced, at least the strategy network is updated to extract the main words from the sentence to be analyzed. In one embodiment, the strategy network includes a first embedding layer, a first processing layer, and a second processing layer. The use of the strategy network to extract the stem words of the first sample sentence in the sentence sample set includes: In the first embedding layer, obtaining the word embedding vector of each word in the first sample sentence; In the first processing layer, according to the word embedding vector, determine the probability of each word as a backbone word; In the second processing layer, at least a part of the words is selected from the various words at least according to the probability to form the first trunk word set. In a further embodiment, in the second processing layer, words with a probability value greater than a preset threshold are selected from the various words to form the first trunk word set. According to an embodiment, the classification network includes a second embedding layer and a third processing layer, and the classification processing of the first candidate sentence formed by the first set of stem words using the classification network includes: In the second embedding layer, obtain the sentence embedding vector corresponding to the first candidate sentence; In the third processing layer, the first classification result of the first candidate sentence is determined according to the sentence embedding vector. In one embodiment, the strategy network and/or classification network is based on a recurrent neural network RNN. In an embodiment, the above method further includes determining the direction in which the total loss is reduced, including: Processing the first sample sentence by using the strategy network under the N group principle parameters to obtain corresponding N trunk word sets, and respectively determining N first losses; Use the classification network to classify the N candidate sentences corresponding to the N trunk word sets, obtain N classification results, and determine N second losses respectively; Determine the corresponding N total losses and the average value of the N total losses according to the N first losses and N second losses; Determine at least one first total loss whose loss value is less than or equal to the average value, and at least one second total loss whose loss value is greater than the average value; Based on the at least one first total loss and the at least one second total loss, a direction in which the total loss decreases is determined. Further, in an embodiment, the foregoing N classification results are obtained by using the classification network under the same set of classification parameters to perform classification processing on the N candidate sentences; in this case, The N total losses correspond to the N group principle parameters; At this time, determining the direction in which the total loss is reduced includes: Determining the accumulation of gradients of at least one group of first strategy parameters corresponding to the at least one first total loss with respect to the current strategy parameters as a positive direction; Determining the accumulation of gradients of at least one set of second strategy parameters corresponding to the at least one second total loss with respect to the current strategy parameters as a negative direction; The direction opposite to the positive direction and the negative direction is superimposed as the direction in which the total loss decreases. Further, in the above case, the current strategy parameters in the strategy network can be updated in the direction in which the total loss is reduced. In another embodiment, the N classification results are obtained by classifying the N candidate sentences using the classification network under M groups of classification parameters, where M<=N; In this case, the N total losses correspond to N parameter sets, where the i-th parameter set includes the i-th group principle parameter and the classification parameter corresponding to the classification network when processing the i-th candidate sentence; At this time, determining the direction of the total loss reduction includes: Determining the accumulation of the gradient of the at least one first parameter set corresponding to the at least one first total loss relative to the current strategy parameter as the first positive direction; Determining the accumulation of the gradient of the at least one second parameter set corresponding to the at least one second total loss relative to the current strategy parameter as the first negative direction; Superimposing the first positive direction and the opposite direction of the first negative direction as the first adjustment direction; Determining the accumulation of the gradient of the at least one first parameter set corresponding to the at least one first total loss relative to the current classification parameter as the second positive direction; Determining the accumulation of the gradient of the at least one second parameter set corresponding to the at least one second total loss with respect to the current classification parameter as the second negative direction; Superimposing the second positive direction and the opposite direction of the second negative direction as a second adjustment direction; The sum of the first adjustment direction and the second adjustment direction is taken as the direction in which the total loss is reduced. Further, in the above case, the current strategy parameters of the strategy network can be updated in the first adjustment direction; and the current classification parameters of the classification network can be updated in the second adjustment direction. According to an embodiment, the above method further includes: Input the second sentence to be analyzed into the strategy network; Determine the main word in the second sentence according to the output of the strategy network. According to the second aspect, a device for extracting stem words through reinforcement learning is provided, including: The classification network training unit is configured to use the sentence sample set to train the classification network for sentence classification; The first determining unit is configured to use the strategy network under the current strategy parameters to extract the stem words of the first sample sentence in the sentence sample set to obtain the first stem word set, and according to the first sample sentence The number of words in and the number of words in the first stem word set to determine the current first loss; The second determining unit is configured to use the classification network to classify the first candidate sentence formed by the first stem word set, to obtain the first classification result of the first candidate sentence, and according to the Describe the first classification result and the classification label of the first sample sentence, and determine the current second loss; The total loss determining unit is configured to determine the current total loss according to the current first loss and the current second loss; The update unit is configured to update at least the strategy network in a direction in which the total loss is reduced, so as to extract the main words from the sentence to be analyzed. According to the third aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed in the computer, the computer is caused to execute the method of the first aspect. According to a fourth aspect, there is provided a computing device, including a memory and a processor, wherein the memory stores executable program code, and when the processor executes the executable program code, the first The same method. According to the method and device provided in the embodiment of this specification, the learning and training of the extraction of the main words are carried out by means of reinforcement learning. More specifically, an actor-critic reinforcement learning system is used for stem word extraction. In the reinforcement learning system, the strategy network is used as an actor for stem word extraction; the classification network is used as a critic to classify sentences. The existing sentence sample library can be used as a training prediction to train the classification network, thereby avoiding the labor cost of the main word tagging. The classification network after preliminary training can classify the sentences composed of the main words extracted by the strategy network, and thus evaluate the effect of main word extraction. By setting losses for both the output results of the strategy network and the classification network, and repeatedly training the strategy network and the classification network according to the total loss, an ideal reinforcement learning system can be obtained. In this way, an ideal network system can be trained without manual labeling of the main words, and the effective extraction of main words can be realized.
下面結合圖式,對本說明書提供的方案進行描述。
如前所述,在多種文本分析場景中,都需要對句子的主幹詞進行提取。為了能夠自動地進行主幹詞提取,在一種方案中,可以通過有監督的機器學習方法來訓練主幹詞提取模型。根據常規的監督學習方法,為了訓練這樣的主幹詞提取模型,就需要大量人工標注的標注資料,這些標注資料需要對句子中各個詞是否為主幹詞進行標注,人工成本很大。
根據本說明書實施例的構思,採用強化學習的方式進行主幹詞提取,降低人工標注成本,優化主幹詞提取效果。
如本領域技術人員所知,強化學習是一種基於序列行為的回饋,進行的無標注的學習策略的方法。一般地,強化學習系統包括智慧體和執行環境,智慧體通過與執行環境的交流和回饋,不斷進行學習,優化其策略。具體而言,智慧體觀察並獲得執行環境的狀態(state),根據一定策略,針對當前執行環境的狀態確定要採取的行為或動作(action)。這樣的行為作用於執行環境,會改變執行環境的狀態,同時產生一個回饋給智慧體,該回饋又稱為獎勵分數(reward)。智慧體根據獲得的獎勵分數來判斷,之前的行為是否正確,策略是否需要調整,進而更新其策略。通過反覆不斷地觀察狀態、確定行為、收到回饋,使得智慧體可以不斷更新策略,最終目標是能夠學習到一個策略,使得獲得的獎勵分數累積最大化。
存在多種演算法來進行智慧體中策略的學習和優化,其中Actor-Critic方法是用於強化學習的一種策略梯度方法。圖1示出採用Actor-Critic方式的深度強化學習系統的示意圖。如圖1所示,系統包括作為actor的策略模型和作為critic的評估模型。
策略模型從環境獲得環境狀態s,根據一定策略,輸出在當前環境狀態下要採取的動作a。評估模型獲取上述環境狀態s,以及策略模型輸出的動作a,對策略模型在狀態s下採取動作a的本次決策進行評分,並將該評分回饋給策略模型。策略模型根據評估模型的評分來調整策略,以期獲得更高的評分。也就是說,策略模型訓練的目標是,獲得評估模型的盡可能高的評分。另一態樣,評估模型也會不斷調整其評分方式,使得評分更好的反映環境回饋的獎勵分數r的累積。
如此,反覆訓練評估模型和策略模型,使得評估模型的評分越來越準確,越來越接近環境回饋的獎勵,於是,策略模型採取的策略也越來越優化合理,得到更多的環境的獎勵。
基於以上的特點,根據本說明書的實施例,通過採用Actor-Critic方式的強化學習系統進行主幹詞提取。
圖2為本說明書披露的一個實施例的強化學習系統示意圖。如圖2所示,用於主幹詞提取的強化學習系統包括策略網路100和分類網路200。策略網路100用於從句子中提取主幹詞,它對應於圖1所示的策略模型,作用為Actor;分類網路200用於對句子進行分類,它對應於圖1所示的評估模型,作用為Critic。策略網路100和分類網路200均為神經網路。
為了對策略網路100和分類網路200進行訓練,可以採用具有句子分類標籤的樣本句子。
在訓練過程中,將樣本句子(對應於環境狀態s)輸入到策略網路100。通過一定策略,策略網路100從該樣本句子中提取出若干主幹詞,形成主幹詞集合(相當於採取的一個動作a),該主幹詞集合可以對應於一個主幹句。
分類網路200獲取主幹詞集合,並對該主幹詞集合對應的主幹句子進行分類,得到分類結果。通過比對該分類結果與原始樣本句子的分類標籤,來評估該主幹詞集合提取得是否正確。
可以分別為策略網路100的主幹詞提取過程和分類網路200的分類過程設置損失(圖中的損失1和損失2),基於該損失反覆訓練策略網路100和分類網路200,使得損失更小,分類更准。如此訓練得到的策略網路100,就可以用於對待分析的句子進行主幹詞提取。
下面描述以上系統的訓練過程和處理過程。
圖3示出根據一個實施例的訓練用於主幹詞提取的強化學習系統的方法流程圖。可以理解,該方法可以通過任何具有計算、處理能力的裝置、設備、平臺、設備群集來執行。如圖3所示,該方法包括:步驟31,利用句子樣本集,訓練用於句子分類的分類網路;步驟32,利用當前策略參數組下的策略網路,對句子樣本集中的第一樣本句子進行主幹詞提取,獲得第一主幹詞集合,並根據所述第一樣本句子中的詞語數目和所述第一主幹詞集合中的詞語數目,確定當前的第一損失;步驟33,利用所述分類網路對由所述第一主幹詞集合構成的第一備選句子進行分類處理,獲得所述第一備選句子的第一分類結果,並根據所述第一分類結果以及所述第一樣本句子的分類標籤,確定當前的第二損失;步驟34,根據當前的第一損失和當前的第二損失,確定當前的總損失;步驟35,在總損失減小的方向,至少更新所述策略網路,以用於從待分析句子中提取主幹詞。下面描述以上各個步驟的具體執行方式。
如以上結合圖2所述,策略網路100用於從句子中提取主幹詞,分類網路200用於對句子進行分類,進而評估策略網路提取主幹詞的品質。這兩個神經網路互相交流,需要反覆進行訓練,才可以獲得理想的網路參數。為了促進模型儘快收斂,在第一階段,單獨訓練分類網路200,使其可以實現基本的句子分類。
因此,首先,在步驟31,利用句子樣本集,訓練用於句子分類的分類網路。
句子分類,或稱為文本分類,是文本分析中的常見任務,因此,已經存在大量豐富的樣本語料,可以用於進行分類訓練。因此,在步驟31,可以從已有語料庫中獲取一些句子樣本,構成句子樣本集,這裡的句子樣本包括原始句子,以及為該原始句子添加的分類標籤。利用這樣的具有分類標籤的句子樣本構成的句子樣本集,就可以訓練句子分類網路。訓練的方式可以採用經典的監督訓練的方式進行。
如此,通過步驟31,可以得到初步訓練的分類網路,該分類網路可以用於對句子進行分類。 在此基礎上,就可以利用上述分類網路對策略網路進行評估,從而訓練強化學習系統。
具體地,在步驟32,利用當前策略參數組下的策略網路,對句子樣本集中的任意的一個樣本句子,下文稱為第一樣本句子,進行主幹詞提取,獲得對應的主幹詞集合,稱為第一主幹詞集合。
可以理解,初始地,策略網路中的策略參數可以是隨機初始化的;隨著策略網路的訓練,策略參數會不斷調整和更新。當前的策略參數組可以是初始狀態下隨機的參數組,也可以是訓練過程中,某一狀態下的策略參數。策略網路的一群組原則參數可以認為對應於一種策略。相應的,在步驟32,策略網路根據當前策略,對輸入的第一樣本句子進行處理,從中提取出主幹詞。
在一個實施例中,策略網路可以包括多個網路層,通過該多個網路層實現主幹詞提取。
圖4示出根據一個實施例的策略網路的結構示意圖。如圖4所示,策略網路100可以包括,嵌入層110,第一處理層120和第二處理層130。
嵌入層110獲得樣本句子,對於句子中的各個詞,計算其詞嵌入向量。例如,對於第一樣本句子,將其分詞後可以得到詞序列{W1
,W2
,…,Wn
},其中包括n個詞。嵌入層針對每個詞Wi
計算對應的詞嵌入向量Ei
,於是得到{E1
,E2
,…,En
}。
第一處理層120根據以上的詞嵌入向量,確定各個詞作為主幹詞的機率。例如,對於n個詞的詞嵌入向量{E1
,E2
,…,En
},確定各個詞的作為主幹詞的機率{P1
,P2
,…,Pn
}。
第二處理層130根據上述機率,從各個詞中選擇至少一部分詞,作為主幹詞,構成主幹詞集合。在一個實施例中,預先設置一個機率閾值。第二處理層從各個詞中,選出機率大於上述閾值的詞,作為主幹詞。
以上嵌入層110、第一處理層120和第二處理層130中各層網路參數的整體,構成策略參數。
在一個實施例中,策略網路100採用循環神經網路RNN。更具體的,可以通過RNN實現以上的嵌入層110,從而在進行各個詞的詞嵌入時,考慮詞的時序影響。第一處理層120和第二處理層130可以通過全連接處理層實現。
在其他實施例中,策略網路100也可以採用不同的神經網路架構,例如基於RNN改進的長短期記憶LSTM神經網路,GRU神經網路,或者深度神經網路DNN,等等。
通過以上的策略網路,可以對樣本句子進行主幹詞提取。例如,對於第一樣本句子中的n個詞,策略網路通過當前策略,從中選擇了m個詞(m<=n)作為主幹詞,這m個主幹詞表示為{w1
,w2
,…,wm
}。如此,得到主幹詞集合。
在得到主幹詞集合的基礎上,可以通過一個損失函數,下文稱為第一損失函數,衡量主幹詞提取過程的損失,下文稱為第一損失,記為LK(Loss_Keyword)。也就是,在步驟32,在獲得第一主幹詞集合的基礎上,根據第一樣本句子中的詞語數目和第一主幹詞集合中的詞語數目,確定當前的第一損失。
在一個實施例中,第一損失函數被設定為,提取的主幹詞的數目越少,損失值越低;主幹詞數目越多,損失值越高。在一個實施例中,還可以根據提取的主幹詞相對於樣本句子的占比來確定第一損失,占比越高,損失值越大,占比越小,損失值越低。這都是考慮到,希望訓練完成的理想狀態下,策略網路100可以從原始句子中排除儘量多的無用詞,保留盡可能少的詞作為主幹詞。
例如,在一個例子中,第一損失函數可以設置為:
LK=Num_Reserve/Num_Total
其中,Num_Reserve為作為主幹詞保留下來的詞語數目,即主幹詞集合中的詞語數目,Num_Total為樣本句子中的詞語數目。
在以上例子中,假定第一樣本句子中包含n個詞,策略網路通過當前策略,從中選擇了m個詞,那麼當前的第一損失為LK=m/n。
接下來,在步驟33,利用分類網路對由第一主幹詞集合構成的第一備選句子進行分類處理,獲得第一備選句子的第一分類結果。
可以理解,通過步驟31的初步訓練,確定出了分類網路的初步分類參數,這樣的分類網路可以用於對句子進行分類。此外,在步驟32,策略網路100可以輸出針對第一樣本句子提取的第一主幹詞集合,該第一主幹詞集合可以對應一個備選句子,即第一備選句子。該第一備選句子可以理解為,對第一樣本句子排除停用詞、無意義詞,僅保留主幹詞後得到的句子。相應的,在步驟33,可以用分類網路對該第一備選句子進行分類處理,得到分類結果。
在一個實施例中,分類網路可以包括多個網路層,通過該多個網路層實現句子分類。
圖5示出根據一個實施例的分類網路的結構示意圖。如圖5所示,分類網路200可以包括,嵌入層210,全連接處理層220。
嵌入層210獲得策略網路100輸出的主幹詞集合,對於各個詞,計算其詞嵌入向量,進而計算出該主幹詞集合所構成的備選句子的句子嵌入向量。例如,對於第一主幹詞集合{w1
,w2
,…,wm
},可以分別計算各個詞的詞嵌入向量{e1
,e2
,…,em
},然後基於各個詞嵌入向量,得到第一備選句子的句子嵌入向量Es。在不同實施例中,句子嵌入向量可以通過對各個詞嵌入向量進行拼接、平均等運算而得到。
接著,全連接處理層220根據以上的句子嵌入向量Es,確定第一備選句子的分類結果,即第一分類結果。
以上嵌入層210和全連接處理層220中各層網路參數的整體,構成分類參數。
與策略網路100類似的,分類網路200可以採用循環神經網路RNN來實現。更具體的,可以通過RNN實現以上的嵌入層210。在其他實施例中,分類網路200也可以採用不同的神經網路架構,例如LSTM神經網路,GRU神經網路,或者深度神經網路DNN,等等。
在對備選句子進行分類後,可以通過另一個損失函數,下文稱為第二損失函數,衡量分類過程的損失,下文稱為第二損失,記為LC(Loss_Classify)。也就是,在步驟33,在獲得第一分類結果的基礎上,根據該第一分類結果以及第一樣本句子的分類標籤,確定當前的第二損失。
在一個實施例中,第二損失函數被設定為,基於交叉熵演算法確定第二損失LC。在其他實施例中,也可以通過其他形式和其他演算法的損失函數,基於分類結果和分類標籤之間的差異,確定出第二損失LC。相應的,通過上述第二損失函數,基於本次分類得到的第一分類結果,以及第一樣本句子對應的分類標籤之間的比對,可以確定出本次分類的分類損失,即當前的第二損失。
在確定出第一損失和第二損失的基礎上,在步驟34,根據當前的第一損失和當前的第二損失,確定當前的總損失。
總損失可以理解為,整個強化學習系統的損失,包括策略網路提取主幹詞過程的損失,和分類網路進行分類過程的損失。在一個實施例中,總損失定義為,上述第一損失和第二損失的加和。在另一實施例中,還可以為第一損失和第二損失各自賦予一定權重,將總損失定義為,第一損失和第二損失的加權求和。
根據總損失的定義方式,基於本次提取主幹詞對應的當前的第一損失,以及本次分類對應的當前的第二損失,可以確定出當前的總損失。
基於這樣的總損失,就可以對強化學習系統進行訓練,訓練的目標是使得總損失盡可能小。根據以上第一損失、第二損失和總損失的定義方式,可以理解,總損失盡可能小意味著,在策略網路100排除儘量多的無用詞、提取儘量少的主幹詞的同時,不改變句子的含義,因而分類網路200的句子分類結果儘量接近原始句子的分類標籤。
為了達到總損失減小的目的,在步驟35,在總損失減小的方向,更新強化學習系統。更新強化學習系統至少包括,更新策略網路100,還可以包括,更新分類網路200。
以上總損失減小的方向的確定方式,以及強化學習系統的更新方式,在不同訓練方式下、不同訓練階段中可以有所不同,下面分別進行描述。
根據一種訓練方式,為了確定出總損失減小的方向,在策略網路100中用不同策略分別處理多個樣本句子,得出對應的多個主幹詞句子,以及對應的多個第一損失;然後利用分類網路200對各個主幹詞句子進行分類,得出對應的多個分類結果,以及對應的多個第二損失。於是,得到對多個樣本句子進行處理的多個總損失。比較當前損失與多個總損失,將多個總損失中比當前損失小的總損失所對應的網路參數相對於當前網路參數的梯度,確定為總損失減小的方向。
根據另一種訓練方式,為了確定出總損失減小的方向,對同一樣本句子進行多次處理得到多個總損失,基於這樣的多個總損失,確定總損失減小的方向。圖6示出在該訓練方式下確定總損失減小方向的步驟流程圖。
為了探索出更多更好的策略,在策略網路100中,可以在當前策略的基礎上加入一定隨機性而產生N個策略,這N個策略對應於N群組原則參數。結合圖4所示的網路結構,可以對嵌入層的嵌入演算法加入隨機擾動,得到新的策略;可以對第一處理層中確定主幹詞機率的演算法進行變動,得到新的策略;也可以對機率選擇的規則演算法,例如對機率閾值進行變動,得到新的策略。通過以上各種變動方式的組合,可以得到N種策略,對應於N群組原則參數。
相應的,在步驟61,分別利用上述N群組原則參數下的策略網路處理第一樣本句子,獲得對應的N個主幹詞集合。並且,可以根據如前所述的第一損失函數,分別確定出N個第一損失。
然後,在步驟62,利用分類網路200,對所述N個主幹詞集合分別對應的N個備選句子進行分類處理,獲得N個分類結果。並且,根據前述的第二損失函數,分別確定N個分類結果對應的N個第二損失。
在步驟63,根據N個第一損失和N個第二損失,確定對應的N個總損失,記為L1,L2,…,Ln。並且,還可以確定出上述N個總損失的均值La。
在步驟64,確定損失值小於等於均值的至少一個第一總損失,以及損失值大於均值的至少一個第二總損失。換而言之,將上述N個總損失劃分為,小於等於均值La的總損失,稱為第一總損失,以及大於均值La的總損失,稱為第二總損失。
在步驟65,基於上述第一總損失和第二總損失,確定總損失減小的方向。更具體而言,上述第一總損失由於損失較小,可以對應於正向學習的方向,上述第二總損失由於損失較大,可以對應於負向學習的方向。因此,在步驟65,綜合正向學習的方向,和負向學習方向的反方向,可以得到總的學習方向,即總損失減小的方向。
對於以上的訓練方式,在不同的訓練階段,也可以有不同的具體執行方式。
如前所述,在整個強化學習系統訓練的第一階段,單獨訓練分類網路,如步驟31所示。為了加速模型的收斂,在一個實施例,在接下來的第二階段,固定住上述分類網路,僅訓練和更新策略網路;然後,在第三階段,同時訓練更新策略網路和分類網路。下面分別描述第二階段和第三階段,圖6流程的執行方式。
具體的,在第二階段中,分類網路被固定,也就是分類網路中的分類參數不變,不進行調整。那麼相應的,在圖6的步驟62中,是利用同一組分類參數下的分類網路,對前述N個備選句子進行分類處理,也就是基於同樣的分類方式進行分類,得到了所述N個分類結果。
由於分類參數不變,在這樣的情況下,步驟63中確定的N個總損失,實際上對應於策略網路的N個策略,進而對應於N群組原則參數。也就是,第i個總損失Li,對應於第i群組原則參數PSi。
然後在步驟64,在確定出第一總損失和第二總損失的基礎上,確定出第一總損失對應的第一策略參數,以及第二總損失對應的第二策略參數。
換而言之,如果總損失Li小於等於均值La,則將該總損失歸為第一總損失,相應的策略參數組PSi則歸為第一策略參數;如果總損失Li大於均值La,則將該總損失歸為第二總損失,相應的策略參數組PSi則歸為第二策略參數。
接下來,在步驟65,通過以下方式確定總損失減小的方向:
確定至少一組第一策略參數相對於當前策略參數的梯度的累積,作為正方向;確定至少一組第二策略參數相對於當前策略參數的梯度的累積,作為負方向;將所述正方向與所述負方向的相反方向疊加,作為總損失減小的方向。
這是由於,第一策略參數對應於損失值小於等於平均值的總損失,或者說,損失值較小的總損失,因此,可以認為第一策略參數所對應的策略選擇方向是正確的,是系統學習的“正樣本”,應該進行正向學習;而第二策略參數對應於損失值大於平均值的總損失,是損失值較大的總損失,因此,可以認為第二策略參數所對應的策略選擇方向是錯誤的,是系統學習的“負樣本”,應該進行反向學習。
一般地,損失值小於等於平均值的第一總損失可以是多個,相應的,第一策略參數可以是多組第一策略參數。該多組第一策略參數有可能對樣本句子不同位置的主幹詞提取有不同的效果,因此,在一個實施例中,對該多組第一策略參數均進行正向學習,確定各組第一策略參數相對於當前策略參數的梯度,將其進行累積,得到上述正方向。
相應的,第二策略參數也可以是多組第二策略參數。在一個實施例中,對該多組第二策略參數均進行負向學習,確定各組第二策略參數相對於當前策略參數的梯度,將其進行累積,得到上述負方向。
最後,將負方向取反,與正方向進行疊加,作為總損失減小的方向。
以上總損失減小的方向可以表示為:
其中,PSi為第一策略參數,PSj為第二策略參數,為當前策略參數。
在一個具體例子中,假定N=10,其中L1-L6小於損失均值,為第一總損失,相應的策略參數組PS1-PS6為第一策略參數;假定L7-L10大於損失均值,為第二總損失,相應的策略參數組PS7-PS10為第二策略參數。
在一個實施例中,分別計算PS1-PS5這6群組原則參數相對於當前策略參數的梯度,將其進行累積,得到上述正方向;分別計算PS7-PS10這4群組原則參數相對於當前策略參數的梯度,將其進行累積,得到上述負方向,進而得到總損失減小的方向。
如此,在系統訓練的第二階段的一個實施例中,通過以上方式確定出總損失減小的方向。於是,在圖3的步驟35,在總損失減小的方向,更新策略網路100中的當前策略參數組。
通過不斷執行以上過程,在分類網路200的分類方式不變的情況下,探索更多的主幹詞提取策略,並不斷更新、優化策略網路100中的策略參數,從而針對性的訓練策略網路100。
在策略網路的訓練達到一定訓練目標之後,強化學習系統的訓練可以進入第三階段,同時訓練和更新策略網路100和分類網路200。下面描述在第三階段,圖6的執行方式。
在第三階段,在步驟61,仍然利用N組不同的策略參數下的策略網路處理第一樣本句子,獲得對應的N個主幹詞集合,這N個主幹詞集合可以對應於N個備選句子。
然而,不同的是,在第三階段中,分類網路不固定,也就是說,分類網路中的分類參數也可以進行調整。那麼相應的,在步驟62中,是利用M組不同的分類參數下的分類網路,對步驟61得到的N個備選句子進行分類處理,得到N個備選句子對應的N個分類結果。其中,M<=N。
在M=N的情況下,相當於,對於N個備選句子,分別採用了M=N種不同的分類方法(對應於N組分類參數)進行分類;在M<N的情況下,相當於,對前述N個備選句子進行分類所採用的分類參數,不完全相同。
接著在步驟63,根據N個第一損失和N個第二損失,確定對應的N個總損失。
需要理解的是,在以上得到N個分類結果的過程中,策略網路和分類網路的網路參數均發生了變化。此時,N個總損失對應於N個參數集,其中第i參數集Si包括第i群組原則參數PSi,和處理第i備選句子時分類網路對應的分類參數CSi。換而言之,上述參數集是策略網路100和分類網路200的網路參數的整體集合。
此外,與前述類似的,可以確定出N個總損失的均值La。然後,在步驟64,將上述N個總損失劃分為,小於等於均值La的第一總損失,以及大於均值La的第二總損失。
並且,在確定出第一總損失和第二總損失的基礎上,可以相應確定出第一總損失對應的第一參數集,以及第二總損失對應的第二參數集。
換而言之,如果總損失Li小於等於均值La,則將該總損失歸為第一總損失,相應的參數集Si則歸為第一參數集;如果總損失Li大於均值La,則將該總損失歸為第二總損失,相應的參數集Si則歸為第二參數集。
接下來,在步驟65,通過以下方式確定總損失減小的方向:
確定至少一組第一參數集相對於當前策略參數的梯度的累積,作為第一正方向;確定至少一組第二參數集相對於當前策略參數的梯度的累積,作為第一負方向;將第一正方向與第一負方向的相反方向疊加,作為第一調整方向,即策略參數優化方向;
確定至少一組第一參數集相對於當前分類參數的梯度的累積,作為第二正方向;確定至少一組第二參數集相對於當前分類參數的梯度的累積,作為第二負方向;將第二正方向與第二負方向的相反方向疊加,作為第二調整方向,即分類參數優化方向。
以上確定總損失減小的方向,也就是參數調整方向的構思與第二階段相同,也就是,將損失值較小的總損失所對應的參數集,即第一參數集,作為系統學習的“正樣本”,進行正向學習;將損失值較大的總損失所對應的參數集,即第二參數集,作為系統學習的“負樣本”,進行反向學習。學習時,對於策略網路和分類網路,分別確定各自對應的策略參數和分類參數的調整優化方向。
具體的,對於策略網路的策略參數,其調整方向的確定與第二階段類似,只是計算梯度時,是計算整個參數集相對於當前策略參數的梯度。一般的,參數集中策略參數和分類參數是兩套相互獨立的參數,因此,實際梯度運算中,仍然是通過計算參數集中的策略參數部分相對於當前策略參數的梯度,獲得前述的第一正方向和第一負方向,進而確定出第一調整方向,即策略參數優化方向。
以上第一調整方向可以表示為:
其中,Si為第一參數集,Sj為第二參數集,為當前策略參數。
對於分類網路中的分類參數,其調整方向的確定與策略參數相似,具體地,計算第一參數集相對於當前分類參數的梯度的累積,作為第二正方向;計算第二參數集相對於當前分類參數的梯度的累積,作為第二負方向;將第二正方向與第二負方向的相反方向疊加,作為分類優化方向。如前所述,由於策略參數和分類參數通常相互獨立,在實際梯度運算中,可以通過計算各個參數集中的分類參數部分相對於當前分類參數的梯度,獲得前述的第二正方向和第二負方向,進而確定出第二調整方向,作為分類參數優化方向。
以上第二調整方向可以表示為:
其中,Si為第一參數集,Sj為第二參數集,為當前分類參數。
於是,可以將第一調整方向和第二調整方向的總和,作為總損失減小的方向,即整個系統的調整方向。
如此,在系統訓練的第三階段的一個實施例中,通過以上方式確定出總損失減小的方向。於是,在圖3的步驟35,在總損失減小的方向,更新強化學習系統包括,按照上述第一調整方向,更新策略網路100中的當前策略參數,按照上述第二調整方向,更新分類網路中的當前分類參數。如此,在第三階段,同時訓練策略網路和分類網路。
可以理解,儘管以上實施例中描述了在第一階段單獨訓練分類網路之後,在第二階段固定住分類網路,單獨訓練策略網路,然後在第三階段,同時訓練策略網路和分類網路的訓練過程,但是,在其他實施例中,也可以在第一階段之後,跳過第二階段而直接進入第三階段,同時訓練策略網路和分類網路。
通過不斷訓練策略網路和分類網路,可以探索、確定出更優化的主幹詞提取策略以及分類演算法,不斷優化整個強化學習系統,使得系統的總損失不斷減小,實現訓練目標。在達成訓練目標的情況下,策略網路可以準確地提取出儘量少的主幹詞,以使得句子表達更加精煉,同時不影響句子的含義,也就是不影響該句子的語義分類結果。
在實現訓練目標的情況下,就可以將訓練得到的策略網路用於主幹詞提取。在這樣的情況下,可以將待分析的句子輸入給策略網路,策略網路利用訓練得到的策略參數,對該句子進行處理。根據策略網路的輸出,就可以確定該句子中的主幹詞。這些主幹詞的集合可以對應於一個主幹句子,用於後續的意圖識別,語義匹配等進一步文本分析,優化後續文本分析的效果。
綜合以上,通過強化學習的方式,進行主幹詞提取的學習和訓練。在強化學習系統中,策略網路作為actor,用於主幹詞提取;分類網路作為critic,用於對句子進行分類。可以利用現有的句子樣本庫作為訓練預料訓練分類網路,從而避免主幹詞標注的人工成本。經過初步訓練的分類網路即可對策略網路提取的主幹詞構成的句子進行分類,如此評估主幹詞提取的效果。通過對策略網路和分類網路的輸出結果均設置損失,根據總損失反覆訓練策略網路和分類網路,可以得到理想的強化學習系統。如此,可以在無需主幹詞人工標注的情況下,訓練得到理想的網路系統,實現對主幹詞的有效提取。
根據另一態樣的實施例,還提供一種通過強化學習提取主幹詞的裝置。該裝置可以部署在任何具有計算、處理能力的設備或平臺上。圖7示出根據一個實施例的裝置示意圖。如圖7所示,該裝置700包括:
分類網路訓練單元71,配置為利用句子樣本集,訓練用於句子分類的分類網路;
第一確定單元72,配置為利用當前策略參數下的策略網路,對所述句子樣本集中的第一樣本句子進行主幹詞提取,獲得第一主幹詞集合,並根據所述第一樣本句子中的詞語數目和所述第一主幹詞集合中的詞語數目,確定當前的第一損失;
第二確定單元73,配置為利用所述分類網路對由所述第一主幹詞集合構成的第一備選句子進行分類處理,獲得所述第一備選句子的第一分類結果,並根據所述第一分類結果以及所述第一樣本句子的分類標籤,確定當前的第二損失;
總損失確定單元74,配置為根據所述當前的第一損失和當前的第二損失,確定當前的總損失;
更新單元75,配置為在總損失減小的方向,至少更新所述策略網路,以用於從待分析句子中提取主幹詞。
在一個實施例中,策略網路包括第一嵌入層,第一處理層和第二處理層。第一確定單元72具體配置為:
在所述第一嵌入層,獲得所述第一樣本句子中的各個詞的詞嵌入向量;
在所述第一處理層,根據所述詞嵌入向量,確定所述各個詞作為主幹詞的機率;
在所述第二處理層,至少根據所述機率,從所述各個詞中選擇至少一部分詞,構成所述第一主幹詞集合。
進一步的,在一個實施例中,在所述第二處理層,從所述各個詞中選擇機率值大於預設閾值的詞,構成所述第一主幹詞集合。
在一個實施例中,分類網路包括第二嵌入層和第三處理層,第二確定單元73具體配置為:
在所述第二嵌入層,獲得所述第一備選句子對應的句子嵌入向量;
在所述第三處理層,根據所述句子嵌入向量,確定所述第一備選句子的第一分類結果。
根據一種實施方式,所述策略網路和/或所述分類網路基於循環神經網路RNN。
在一種實施方式中,第一確定單元72還配置為,分別利用N群組原則參數下的所述策略網路處理所述第一樣本句子,獲得對應的N個主幹詞集合,並分別確定N個第一損失;
所述第二確定單元73還配置為,利用所述分類網路,對所述N個主幹詞集合分別對應的N個備選句子進行分類處理,獲得N個分類結果,並分別確定N個第二損失;
所述總損失確定單元74還配置為,根據N個第一損失和N個第二損失,確定對應的N個總損失,以及所述N個總損失的均值;
以及,確定損失值小於等於所述均值的至少一個第一總損失,以及損失值大於所述均值的至少一個第二總損失。
此外,更新單元75包括方向確定模組751以及更新模組752。其中,方向確定模組751配置為,基於所述至少一個第一總損失和所述至少一個第二總損失,確定所述總損失減小的方向;更新模組752配置為,根據方向確定模組751確定的方向,執行網路更新。
更具體的,在一個實施例中,第二確定單元73配置為:利用同一組分類參數下的所述分類網路,對所述N個備選句子分別進行分類處理,獲得所述N個分類結果;在這樣的情況下,所述N個總損失對應於所述N群組原則參數;
如此,所述方向確定模組751配置為:
確定所述至少一個第一總損失對應的至少一組第一策略參數相對於當前策略參數的梯度的累積,作為正方向;
確定所述至少一個第二總損失對應的至少一組第二策略參數相對於當前策略參數的梯度的累積,作為負方向;
將所述正方向與所述負方向的相反方向疊加,作為所述總損失減小的方向。
與此相應的,在一個實施例中,更新模組752配置為:在所述總損失減小的方向,更新所述策略網路中的當前策略參數。
在另一實施例中,第二確定單元73配置為:利用M組分類參數下的所述分類網路,對所述N個備選句子進行分類處理,獲得所述N個備選句子對應的N個分類結果,其中M<=N;在這樣的情況下,所述N個總損失對應於N個參數集,其中第i參數集包括第i群組原則參數,和處理第i備選句子時所述分類網路對應的分類參數;
此時,所述方向確定模組751配置為:
確定所述至少一個第一總損失對應的至少一組第一參數集相對於當前策略參數的梯度的累積,作為第一正方向;
確定所述至少一個第二總損失對應的至少一組第二參數集相對於當前策略參數的梯度的累積,作為第一負方向;
將所述第一正方向與所述第一負方向的相反方向疊加,作為第一調整方向;
確定所述至少一個第一總損失對應的至少一組第一參數集相對於當前分類參數的梯度的累積,作為第二正方向;
確定所述至少一個第二總損失對應的至少一組第二參數集相對於當前分類參數的梯度的累積,作為第二負方向;
將所述第二正方向與所述第二負方向的相反方向疊加,作為第二調整方向;
將所述第一調整方向和第二調整方向的總和作為所述總損失減小的方向。
與此相應的,在一個實施例中,所述更新模組752配置為:
在所述第一調整方向,更新所述策略網路的當前策略參數;
在所述第二調整方向,更新所述分類網路的當前分類參數。
根據一種實施方式,所述裝置700還包括預測單元(未示出),配置為:
將待分析的第二句子輸入所述策略網路;
根據所述策略網路的輸出,確定所述第二句子中的主幹詞。
通過以上裝置,利用深度強化學習系統,實現主幹詞的提取。
根據另一態樣的實施例,還提供一種電腦可讀儲存媒體,其上儲存有電腦程式,當所述電腦程式在電腦中執行時,令電腦執行結合圖2和圖4所描述的方法。
根據再一態樣的實施例,還提供一種計算設備,包括記憶體和處理器,所述記憶體中儲存有可執行程式碼,所述處理器執行所述可執行程式碼時,實現結合圖3和圖6所述的方法。
本領域技術人員應該可以意識到,在上述一個或多個示例中,本發明所描述的功能可以用硬體、軟體、韌體或它們的任意組合來實現。當使用軟體實現時,可以將這些功能儲存在電腦可讀媒體中或者作為電腦可讀媒體上的一個或多個指令或程式碼進行傳輸。
以上所述的具體實施方式,對本發明的目的、技術方案和有益效果進行了進一步詳細說明,所應理解的是,以上所述僅為本發明的具體實施方式而已,並不用於限定本發明的保護範圍,凡在本發明的技術方案的基礎之上,所做的任何修改、等同替換、改進等,均應包括在本發明的保護範圍之內。The following describes the solutions provided in this specification in conjunction with the drawings. As mentioned earlier, in a variety of text analysis scenarios, it is necessary to extract the main words of sentences. In order to be able to automatically extract the stem words, in a scheme, a supervised machine learning method can be used to train the stem word extraction model. According to conventional supervised learning methods, in order to train such a stem word extraction model, a large amount of manually labeled annotation data is needed. These annotation data need to label each word in a sentence whether it is a stem word, and the labor cost is high. According to the concept of the embodiment of this specification, the method of reinforcement learning is adopted to extract the main words, which reduces the cost of manual labeling and optimizes the effect of the main words extraction. As those skilled in the art know, reinforcement learning is a method of unlabeled learning strategy based on the feedback of sequence behavior. Generally, a reinforcement learning system includes a smart body and an execution environment. The smart body continuously learns and optimizes its strategy through communication and feedback with the execution environment. Specifically, the intelligent body observes and obtains the state of the execution environment, and according to a certain strategy, determines the action or action to be taken for the current state of the execution environment. Such behavior acts on the execution environment, will change the state of the execution environment, and at the same time generate a feedback to the intelligent body, which is also called reward. The intelligent body judges whether the previous behavior is correct according to the reward score obtained, and whether the strategy needs to be adjusted, and then updates its strategy. By repeatedly observing the state, determining the behavior, and receiving feedback, the intelligent body can continuously update the strategy. The ultimate goal is to learn a strategy that maximizes the accumulation of reward points. There are a variety of algorithms to learn and optimize strategies in the intelligent body, and the Actor-Critic method is a strategy gradient method for reinforcement learning. Figure 1 shows a schematic diagram of a deep reinforcement learning system using the Actor-Critic method. As shown in Figure 1, the system includes a strategy model as an actor and an evaluation model as a critic. The strategy model obtains the environment state s from the environment, and outputs the action a to be taken in the current environment state according to a certain strategy. The evaluation model obtains the above-mentioned environmental state s and the action a output by the strategy model, scores this decision of the strategy model taking action a in the state s, and feeds the score back to the strategy model. The strategy model adjusts the strategy according to the score of the evaluation model in order to obtain a higher score. In other words, the goal of strategy model training is to obtain the highest possible score for the evaluation model. In another aspect, the evaluation model will continuously adjust its scoring method so that the scoring better reflects the accumulation of the reward score r of environmental feedback. In this way, repeated training of the evaluation model and strategy model makes the evaluation model's score more and more accurate, getting closer and closer to the rewards of environmental feedback, so the strategies adopted by the strategy model are more and more optimized and reasonable, and more environmental rewards are obtained. . Based on the above characteristics, according to the embodiment of this specification, the main word extraction is performed by the reinforcement learning system adopting the Actor-Critic method. Fig. 2 is a schematic diagram of a reinforcement learning system according to an embodiment disclosed in this specification. As shown in FIG. 2, the reinforcement learning system used for stem word extraction includes a strategy network 100 and a classification network 200. The strategy network 100 is used to extract the main words from the sentence, which corresponds to the strategy model shown in Fig. 1 and functions as an Actor; the classification network 200 is used to classify sentences, which corresponds to the evaluation model shown in Fig. 1, The role is Critic. Both the strategy network 100 and the classification network 200 are neural networks. In order to train the strategy network 100 and the classification network 200, sample sentences with sentence classification tags can be used. During the training process, sample sentences (corresponding to the environment state s) are input to the policy network 100. Through a certain strategy, the strategy network 100 extracts a number of stem words from the sample sentence to form a stem word set (equivalent to an action a taken), and the stem word set can correspond to a stem sentence. The classification network 200 obtains the main word set, and classifies the main sentence corresponding to the main word set to obtain the classification result. By comparing the classification result with the classification label of the original sample sentence, it is evaluated whether the main word set is extracted correctly. The loss (loss 1 and loss 2 in the figure) can be set for the main word extraction process of the strategy network 100 and the classification process of the classification network 200 respectively. Based on the loss, the strategy network 100 and the classification network 200 are repeatedly trained to make the loss Smaller, more accurate classification. The strategy network 100 thus trained can be used to extract the main words of the sentence to be analyzed. The training process and processing process of the above system are described below. Fig. 3 shows a flowchart of a method for training a reinforcement learning system for stem word extraction according to an embodiment. It can be understood that the method can be executed by any device, device, platform, or device cluster with computing and processing capabilities. As shown in Figure 3, the method includes:
31:步驟 32:步驟 33:步驟 34:步驟 35:步驟 61:步驟 62:步驟 63:步驟 64:步驟 65:步驟 71:分類網路訓練單元 72:第一確定單元 73:第二確定單元 74:總損失確定單元 75:更新單元 100:策略網路 110:嵌入層 120:第一處理層 130:第二處理層 200:分類網路 210:嵌入層 220:全連接處理層 751:方向確定模組 752:更新模組31: steps 32: steps 33: steps 34: steps 35: steps 61: Step 62: steps 63: steps 64: steps 65: steps 71: Classification network training unit 72: The first determination unit 73: The second determination unit 74: Total loss determination unit 75: update unit 100: Strategic Network 110: Embedded layer 120: first processing layer 130: second processing layer 200: Classification network 210: Embedded layer 220: Fully connected processing layer 751: Direction Determination Module 752: update module
為了更清楚地說明本發明實施例的技術方案,下面將對實施例描述中所需要使用的圖式作簡單地介紹,顯而易見地,下面描述中的圖式僅僅是本發明的一些實施例,對於本領域普通技術人員來講,在不付出進步性勞動的前提下,還可以根據這些圖式獲得其它的圖式。 圖1示出採用Actor-Critic方式的深度強化學習系統的示意圖; 圖2為本說明書披露的一個實施例的強化學習系統示意圖; 圖3示出根據一個實施例的訓練用於主幹詞提取的強化學習系統的方法流程圖; 圖4示出根據一個實施例的策略網路的結構示意圖; 圖5示出根據一個實施例的分類網路的結構示意圖; 圖6示出在一種訓練方式下確定總損失減小方向的步驟流程圖; 圖7示出根據一個實施例的裝置示意圖。In order to explain the technical solutions of the embodiments of the present invention more clearly, the following will briefly introduce the drawings that need to be used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. Those of ordinary skill in the art can also obtain other schemas based on these schemas without making progressive labor. Figure 1 shows a schematic diagram of a deep reinforcement learning system using Actor-Critic mode; Figure 2 is a schematic diagram of a reinforcement learning system according to an embodiment disclosed in this specification; Fig. 3 shows a flowchart of a method for training a reinforcement learning system for stem word extraction according to an embodiment; Figure 4 shows a schematic structural diagram of a policy network according to an embodiment; Figure 5 shows a schematic structural diagram of a classification network according to an embodiment; Figure 6 shows a flow chart of steps for determining the direction of total loss reduction in a training mode; Fig. 7 shows a schematic diagram of an apparatus according to an embodiment.
100:策略網路 100: Strategic Network
200:分類網路 200: Classification network
Claims (24)
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910116482.XA CN110008332B (en) | 2019-02-13 | 2019-02-13 | Method and device for extracting main words through reinforcement learning |
CN201910116482.X | 2019-02-13 |
Publications (2)
Publication Number | Publication Date |
---|---|
TW202030625A true TW202030625A (en) | 2020-08-16 |
TWI717826B TWI717826B (en) | 2021-02-01 |
Family
ID=67165738
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
TW108132431A TWI717826B (en) | 2019-02-13 | 2019-09-09 | Method and device for extracting main words through reinforcement learning |
Country Status (3)
Country | Link |
---|---|
CN (1) | CN110008332B (en) |
TW (1) | TWI717826B (en) |
WO (1) | WO2020164336A1 (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110008332B (en) * | 2019-02-13 | 2020-11-10 | 创新先进技术有限公司 | Method and device for extracting main words through reinforcement learning |
CN111582371B (en) * | 2020-05-07 | 2024-02-02 | 广州视源电子科技股份有限公司 | Training method, device, equipment and storage medium of image classification network |
CN113377884B (en) * | 2021-07-08 | 2023-06-27 | 中央财经大学 | Event corpus purification method based on multi-agent reinforcement learning |
CN117350302B (en) * | 2023-11-04 | 2024-04-02 | 湖北为华教育科技集团有限公司 | Semantic analysis-based language writing text error correction method, system and man-machine interaction device |
Family Cites Families (30)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8929877B2 (en) * | 2008-09-12 | 2015-01-06 | Digimarc Corporation | Methods and systems for content processing |
CN101751437A (en) * | 2008-12-17 | 2010-06-23 | 中国科学院自动化研究所 | Web active retrieval system based on reinforcement learning |
US8694444B2 (en) * | 2012-04-20 | 2014-04-08 | Xerox Corporation | Learning multiple tasks with boosted decision trees |
CN103984741B (en) * | 2014-05-23 | 2016-09-21 | 合一信息技术(北京)有限公司 | Customer attribute information extracting method and system thereof |
TW201612770A (en) * | 2014-09-24 | 2016-04-01 | Univ Chang Gung Science & Technology | Method and system for scoring an english writing work |
KR101882585B1 (en) * | 2016-11-29 | 2018-07-26 | 한양대학교 산학협력단 | Method and system for classifying natural language sentence/paragraph readability in educational environment for hri |
CN106934008B (en) * | 2017-02-15 | 2020-07-21 | 北京时间股份有限公司 | Junk information identification method and device |
CN107368524B (en) * | 2017-06-07 | 2020-06-02 | 创新先进技术有限公司 | Dialog generation method and device and electronic equipment |
CN107423440B (en) * | 2017-08-04 | 2020-09-01 | 逸途(北京)科技有限公司 | Question-answer context switching and reinforced selection method based on emotion analysis |
CN107491531B (en) * | 2017-08-18 | 2019-05-17 | 华南师范大学 | Chinese network comment sensibility classification method based on integrated study frame |
CN107943783A (en) * | 2017-10-12 | 2018-04-20 | 北京知道未来信息技术有限公司 | A kind of segmenting method based on LSTM CNN |
CN107992467A (en) * | 2017-10-12 | 2018-05-04 | 北京知道未来信息技术有限公司 | A kind of mixing language material segmenting method based on LSTM |
CN107679039B (en) * | 2017-10-17 | 2020-12-29 | 北京百度网讯科技有限公司 | Method and device for determining statement intention |
CN108108351B (en) * | 2017-12-05 | 2020-05-22 | 华南理工大学 | Text emotion classification method based on deep learning combination model |
CN108255934B (en) * | 2017-12-07 | 2020-10-27 | 北京奇艺世纪科技有限公司 | Voice control method and device |
CN108108094A (en) * | 2017-12-12 | 2018-06-01 | 深圳和而泰数据资源与云技术有限公司 | A kind of information processing method, terminal and computer-readable medium |
CN108170736B (en) * | 2017-12-15 | 2020-05-05 | 南瑞集团有限公司 | Document rapid scanning qualitative method based on cyclic attention mechanism |
CN108090218B (en) * | 2017-12-29 | 2022-08-23 | 北京百度网讯科技有限公司 | Dialog system generation method and device based on deep reinforcement learning |
CN108280058A (en) * | 2018-01-02 | 2018-07-13 | 中国科学院自动化研究所 | Relation extraction method and apparatus based on intensified learning |
CN108228572A (en) * | 2018-02-07 | 2018-06-29 | 苏州迪美格智能科技有限公司 | Medicine natural language semantic network reaction type extraction system and method based on intensified learning |
CN108280064B (en) * | 2018-02-28 | 2020-09-11 | 北京理工大学 | Combined processing method for word segmentation, part of speech tagging, entity recognition and syntactic analysis |
CN108491386A (en) * | 2018-03-19 | 2018-09-04 | 上海携程国际旅行社有限公司 | natural language understanding method and system |
CN108427771B (en) * | 2018-04-09 | 2020-11-10 | 腾讯科技(深圳)有限公司 | Abstract text generation method and device and computer equipment |
CN108595602A (en) * | 2018-04-20 | 2018-09-28 | 昆明理工大学 | The question sentence file classification method combined with depth model based on shallow Model |
CN108628834B (en) * | 2018-05-14 | 2022-04-15 | 国家计算机网络与信息安全管理中心 | Word expression learning method based on syntactic dependency relationship |
CN108805268A (en) * | 2018-06-08 | 2018-11-13 | 中国科学技术大学 | Deeply learning strategy network training method based on evolution algorithm |
CN109189862A (en) * | 2018-07-12 | 2019-01-11 | 哈尔滨工程大学 | A kind of construction of knowledge base method towards scientific and technological information analysis |
CN108897896B (en) * | 2018-07-13 | 2020-06-02 | 深圳追一科技有限公司 | Keyword extraction method based on reinforcement learning |
CN109191276B (en) * | 2018-07-18 | 2021-10-29 | 北京邮电大学 | P2P network lending institution risk assessment method based on reinforcement learning |
CN110008332B (en) * | 2019-02-13 | 2020-11-10 | 创新先进技术有限公司 | Method and device for extracting main words through reinforcement learning |
-
2019
- 2019-02-13 CN CN201910116482.XA patent/CN110008332B/en active Active
- 2019-09-09 TW TW108132431A patent/TWI717826B/en active
-
2020
- 2020-01-02 WO PCT/CN2020/070149 patent/WO2020164336A1/en active Application Filing
Also Published As
Publication number | Publication date |
---|---|
TWI717826B (en) | 2021-02-01 |
CN110008332A (en) | 2019-07-12 |
WO2020164336A1 (en) | 2020-08-20 |
CN110008332B (en) | 2020-11-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
TWI717826B (en) | Method and device for extracting main words through reinforcement learning | |
WO2021093755A1 (en) | Matching method and apparatus for questions, and reply method and apparatus for questions | |
EP3767536A1 (en) | Latent code for unsupervised domain adaptation | |
CN112069310B (en) | Text classification method and system based on active learning strategy | |
KR20190140824A (en) | Training method of deep learning models for ordinal classification using triplet-based loss and training apparatus thereof | |
CN110298386B (en) | Label automatic definition method based on image content | |
CN113326731A (en) | Cross-domain pedestrian re-identification algorithm based on momentum network guidance | |
CN111554276B (en) | Speech recognition method, device, equipment and computer readable storage medium | |
US20210133588A1 (en) | Method for model adaptation, electronic device and computer program product | |
CN109359302A (en) | A kind of optimization method of field term vector and fusion sort method based on it | |
CN111046178A (en) | Text sequence generation method and system | |
CN110751234A (en) | OCR recognition error correction method, device and equipment | |
CN111144567A (en) | Training method and device of neural network model | |
JP7310904B2 (en) | LEARNING DEVICE, LEARNING METHOD, AND PROGRAM | |
Taymouri et al. | Encoder-decoder generative adversarial nets for suffix generation and remaining time prediction of business process models | |
CN113988175B (en) | Clustering processing method and device | |
KR20240034804A (en) | Evaluating output sequences using an autoregressive language model neural network | |
CN113535911B (en) | Reward model processing method, electronic device, medium and computer program product | |
CN114429140A (en) | Case cause identification method and system for causal inference based on related graph information | |
JP7161974B2 (en) | Quality control method | |
CN114564579A (en) | Entity classification method and system based on massive knowledge graph and graph embedding | |
CN113094504A (en) | Self-adaptive text classification method and device based on automatic machine learning | |
KR20220138257A (en) | Active Learning Apparatus, Apparatus and Method for Sampling Data used for Active Learning | |
CN112069800A (en) | Sentence tense recognition method and device based on dependency syntax and readable storage medium | |
LU504703B1 (en) | Face liveness detection method |