零點(Zero-Shot)文本分類的實踐---Flair訓練數據
1 引言
在所有的自然語言處理任務中,感覺《零點文本分類(Zero Shot Text Classification)》最有趣。然而,當把這種技術應用于實際項目時,會產生附加的問題。這個筆記簡要討論了一些實踐中遇到的問題以及解決辦法。
2 遇到的問題
最初想把段落劃分成句子來分類,但在實踐中發現這條路徑行不通,主要原因是運行時間太長,必須按預先劃分的段落來分類。接下來的問題是如何選取合適的candidate_labels,在Zero-Shot中,標簽選擇非常關鍵,為了得到特定的主題,標簽不能取得太籠統,例如"bearing capacity" 要比"geotechnical engineering"更合適些。在試驗bart-large-mnli和distilbert-base-uncased-mnli這兩個模型的過程中,發現如果標簽中的詞匯在文本中出現過,那么匹配的幾率大。例如,從數據集中隨機抽取了18個含有“rock bolts"的段落,如果用標簽"rock bolt"來匹配,那么會取得很好的結果。
不過,對于這個句子"An empirical method for design of grouted bolts in rock tunnels based on the Geological Strength Index (GSI)[基于地質強度指數(GSI)的巖石隧道灌漿錨桿設計的經驗方法]", 如果我們設定兩個標簽"underground"和"slope", 結果發現這兩個模型都不能給出結果,這是由于模型不能識別出"tunnel"究竟是指地下還是邊坡。這也充分說明了預訓練模型的局限性。因此我們需要解決這個問題。
3 Flair訓練
我們可以在現有模型的基礎上用自己的數據進行訓練。不過在這個筆記中,我們試驗了另一種方法,使用flair 0.8.0.post1(Mar 9, 2021) 來訓練這個標簽。為了避免沖突,Flair安裝在虛擬環境flair下。在Flair默認的TARSClassifier訓練器中,同樣不能識別出含有"tunnel"的這個句子究竟說的是地上(slope)還是地下(underground)。于是使用了如下四個訓練句子作為訓練數據,其中前兩個描述的是地下開挖,后兩個描述的是邊坡:
(1) This can be of use in determining design aspects such as the installation time of tunnel support elements and instrumentation. [這可以用于確定設計方面,如隧道支撐部件和儀器的安裝時間。]
(2) The tunnel support system in this region would be minimal compared to tunneling through solid bedrock.[與在堅實的基巖中開挖隧道相比,該地區的隧道支撐系統將是最小的。]
(3) The Chukicamata mine in northern Chile is one of the largest open pit mines in the world, about 4 km long, 3 km wide and 1 km deep. [智利北部的丘基卡馬塔礦是世界上最大的露天礦之一,長約4公里,寬3公里,深1公里。]
(4) Experienced in geomechanics analysis using FLAC3D to study the potential failure type and mechanism of an open pit mine. [有使用FLAC3D進行地質力學分析的經驗,研究露天礦潛在的破壞類型和機制]
如下兩個句子作為試驗數據,一個是地下的,另一個是地面上的:
(1) Rock behaviour and rock bolt support in large excavations. [大型挖掘中的巖石行為和巖石錨桿支護]
(2) Computer aided risk analysis of open pit mine[露天礦的計算機輔助風險分析]
訓練后得到了如下模型:
現在我們再使用"An empirical method for design of grouted bolts in rock tunnels based on the Geological Strength Index (GSI)" 進行分類,這個句子會歸結為"underground", 歸類分數為0.9575,可見分類標簽添加成功,模型會識別出tunnel 是在地下。
再試驗一個句子"Assessing rock mass UCS anisotropy using a coupled DFN-DEM approach at a surface mining project in Artic Canada[在加拿大阿蒂克地區的一個露天采礦項目中,使用DFN-DEM耦合方法評估巖體單軸抗壓強度的各向異性]", 運行結果顯示這個句子正確地歸結為"slope"分類,盡管句子中沒有出現slope,歸類分數為0.8024。
工程師必備
- 項目客服
- 培訓客服
- 平臺客服
TOP




















