如何使用SLM構建企業業務應用

如何使用SLM構建企業業務應用

如今,企業正在使用人工智慧聊天機器人來改善客戶服務並提供即時支援。這些由人工智慧驅動的聊天機器人可以回答問題並推薦產品。與人工座席不同,它們全天候工作,沒有休息時間,是各種規模公司的寶貴工具。在本文中,我們將探討人工智慧驅動的聊天機器人如何在客戶服務、銷售和個性化方面幫助企業。

  • 瞭解小語言模型(SLM)如何以較低的資源消耗提升業務運營。
  • 瞭解 SLM 如何實現客戶支援、財務分析和文件處理等關鍵業務任務的自動化。
  • 探索 Flan-T5、FinancialBERT 和 LayoutLM 等模型在商業人工智慧應用中的實施。
  • 分析 SLM 相對於 LLM 的優勢,包括效率、適應性和特定行業的培訓。
  • 探索 SLM 在人工智慧驅動的客戶服務、金融和文件自動化中的實際應用案例。

什麼是小型語言模型?

由於大型語言模型體積過大,耗電過多,而且難以安裝在手機和平板電腦等小型裝置上,因此需要體積更小的模型,但仍能正確理解人們的語言。因此,小型語言模型應運而生,其設計緊湊高效,同時還能提供準確的語言理解能力。小型語言模型專門設計用於小型裝置,能耗更低。它們也更易於更新和維護。LLM 使用大量計算能力和大型資料集進行訓練,這意味著它們可以輕鬆學習語言中的複雜模式和關係。

它們的訓練包括遮蔽語言建模、下一句預測和大規模預訓練,這使它們能夠更深入地理解語言。SLM 使用更高效的演算法和更小的資料集進行訓練,因此更加緊湊高效。SLM 使用知識提煉、遷移學習和高效的預訓練方法,因此可以獲得與大型模型相同的結果,但所需資源更少。

LLM與SLM的區別

我們將從下表中瞭解 LLM 與 SLM 的區別:

特徵 大型語言模型 (LLM)  小型語言模型 (SLM)
引數 十億到數萬億 百萬到數千萬
訓練資料 大量、多樣的資料集 小型、更具體的資料集
計算要求 較高(速度較慢,記憶體/功耗較大) 較低(速度較快,記憶體/功耗較小)
成本 訓練和執行成本較高 訓練和執行成本較低
領域專業知識 更多跨領域的通用知識 可針對特定領域進行微調
在簡單任務上的效能 良好到出色的效能 良好的效能
在複雜任務中的表現 能力較高 能力較低
通用性 跨任務/領域的通用性強 通用性有限
透明度/可解釋性 較低 透明度/可解釋性較高
用例 開放式對話、創意寫作、問題解答、通用 NLP 聊天機器人、簡單文字生成、特定領域 NLP
代表 GPT-3, BERT, T5 ALBERT, DistilBERT, TinyBERT, Phi-3

優勢

  • LLM 是在大量通用資料的基礎上進行訓練的,而 SLM 則可以在針對特定行業的較小資料集上進行訓練。這使它們能夠很好地理解該行業的語言細節。
  • SLM 比 LLM 更透明,更容易解釋。在使用大型語言模型時,很難理解它是如何做出決策的,也很難理解它的決策依據是什麼。SLM 模型更小、更直接,因此更容易理解它們是如何工作的。這對於醫療保健或金融等行業非常重要,因為在這些行業中,您需要相信模型所做的決策。
  • SLM 比 LLM 更具適應性。因為它們更小、更專業,我們可以更容易地對它們進行更新或微調。這使得 SLM 對於變化迅速的行業非常有用。例如,在醫學領域,新的研究和發現層出不窮。SLM 可以快速更新,以反映這些變化,因此對醫療專業人員非常有用。

在商業人工智慧中使用SLM

企業越來越多地轉向小型語言模型(SLM),以獲得兼顧效率和成本效益的人工智慧驅動型解決方案。SLM 既能處理特定領域的任務,又需要較少的資源,因此為尋求人工智慧自動化的公司提供了一種實用的選擇。

利用AI聊天機器人實現客戶支援自動化

客戶希望能即時回覆他們的詢問。由 SLM 支援的人工智慧聊天機器人使企業能夠提供高效的全天候支援。主要優勢包括

  • 自動化客戶支援
  • 個性化幫助
  • 多語言支援

將 Google/flan-t5-small 用於人工智慧聊天機器人

谷歌 FLAN-T5-Small 是一個功能強大的語言模型,屬於 T5(文字到文字轉換器)系列。

模型架構:

FLAN-T5-Small 基於 T5 架構,是 Transformer 模型的一種變體。它包括

  • 編碼器:接收輸入文字並生成連續表示。
  • 解碼器:根據編碼表示生成輸出文字。

FLAN-T5-Small 具體說明:

該模型是原始 T5 模型的較小變體,擁有約 6000 萬個引數。其設計目的是在保持強大效能的同時,使其更加高效和易用。

培訓目標:

FLAN-T5-Small 是在海量文字資料的語料庫上進行訓練的,採用了多種目標組合:

  • 遮蔽語言建模 (MLM): 預測輸入文字中的遮蔽標記。
  • 文字到文字生成: 根據輸入文字生成輸出文字。

FLAN(微調語言網)自適應:

FLAN-T5-Small 中的 “FLAN ”指的是對 T5 模型的特定調整。FLAN 包括在一系列不同的自然語言處理任務(如問題解答、情感分析和文字分類)中對模型進行微調。這種調整能讓模型對語言有更廣泛的理解,並提高其在各種任務中的效能。

主要特點

  • 體積小: 約 6000 萬個引數,更高效、更易用。
  • 效能強大: 儘管體積較小,FLAN-T5-Small 仍能在各種自然語言處理任務中保持強勁的效能。
  • 多功能性: 可針對特定任務進行微調,適用於各種領域。

使用案例:

FLAN-T5-Small 適用於各種自然語言處理應用,包括

  • 文字分類
  • 情感分析
  • 問題解答
  • 文字生成
  • 語言翻譯

程式碼示例:將 SLM 用於人工智慧聊天機器人

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from transformers import pipeline
# Load the Flan-T5-small model
chatbot = pipeline("text2text-generation", model="google/flan-t5-small")
# Sample customer queries
queries = [
"What are your business hours?",
"Do you offer international shipping?",
"How can I return a product?"
]
# Generate responses
for query in queries:
response = chatbot(query, max_length=50, do_sample=False)
print(f"Customer: {query}\nAI: {response[0]['generated_text']}\n")
from transformers import pipeline # Load the Flan-T5-small model chatbot = pipeline("text2text-generation", model="google/flan-t5-small") # Sample customer queries queries = [ "What are your business hours?", "Do you offer international shipping?", "How can I return a product?" ] # Generate responses for query in queries: response = chatbot(query, max_length=50, do_sample=False) print(f"Customer: {query}\nAI: {response[0]['generated_text']}\n")
from transformers import pipeline
# Load the Flan-T5-small model
chatbot = pipeline("text2text-generation", model="google/flan-t5-small")
# Sample customer queries
queries = [
"What are your business hours?",
"Do you offer international shipping?",
"How can I return a product?"
]
# Generate responses
for query in queries:
response = chatbot(query, max_length=50, do_sample=False)
print(f"Customer: {query}\nAI: {response[0]['generated_text']}\n")

輸入文字

"What are your business hours?",
"Do you offer international shipping?",
"How can I return a product?

輸出

Customer: What are your business hours?AI: 8:00 a.m. - 5:00 p.m.Customer: Do you offer international shipping?AI: noCustomer: How can I return a product?AI: Return the product to the store.

財務分析和預測

SLM 透過分析趨勢和預測市場狀況,幫助企業做出資料驅動的財務決策。使用案例包括

  • 銷售預測
  • 風險評估
  • 投資洞察

使用 FinancialBERT 進行市場分析

金融 BERT 是一種預訓練語言模型,專門用於金融文字分析。它是廣受歡迎的 BERT(來自變換器的雙向編碼器表示)模型的變體,針對金融應用進行了微調。

金融 BERT 在大量金融文字語料庫中進行了訓練,例如

  • 金融新聞文章
  • 公司報告
  • 財務報表
  • 股票市場資料

這種專門訓練使 Financial BERT 能夠更好地理解金融術語、概念和關係。對於以下任務尤其有用

  • 情緒分析: 分析金融文字以確定市場情緒、投資者態度或公司業績。
  • 事件提取: 識別特定的金融事件,如併購、盈利公告或監管變化。
  • 風險分析: 透過分析財務報告、新聞文章或社交媒體中的文字資料來評估金融風險。
  • 投資組合最佳化: 使用自然語言處理(NLP)分析金融文字並最佳化投資組合。

金融 BERT 在金融領域有許多應用,包括

  • 量化交易 : 使用機器學習模型分析金融文字,做出明智的交易決策。
  • 風險管理: 透過分析金融文字資料識別潛在風險和機遇。
  • 投資研究: 分析金融報告、新聞文章和社交媒體,為投資決策提供依據。

程式碼示例:使用 SLM 進行市場分析

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
# Load FinancialBERT model
tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone")
model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone")
# Create a sentiment analysis pipeline
finance_pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
# Sample financial news headlines
headlines = [
"Tech stocks rally as investors anticipate strong earnings.",
"Economic downturn leads to market uncertainty.",
"Central bank announces interest rate hike, impacting stock prices."
]
# Analyze sentiment
for news in headlines:
result = finance_pipeline(news)
print(f"News: {news}\nSentiment: {result[0]['label']}\n")
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline # Load FinancialBERT model tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone") model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone") # Create a sentiment analysis pipeline finance_pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer) # Sample financial news headlines headlines = [ "Tech stocks rally as investors anticipate strong earnings.", "Economic downturn leads to market uncertainty.", "Central bank announces interest rate hike, impacting stock prices." ] # Analyze sentiment for news in headlines: result = finance_pipeline(news) print(f"News: {news}\nSentiment: {result[0]['label']}\n")
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
# Load FinancialBERT model
tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone")
model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone")
# Create a sentiment analysis pipeline
finance_pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
# Sample financial news headlines
headlines = [
"Tech stocks rally as investors anticipate strong earnings.",
"Economic downturn leads to market uncertainty.",
"Central bank announces interest rate hike, impacting stock prices."
]
# Analyze sentiment
for news in headlines:
result = finance_pipeline(news)
print(f"News: {news}\nSentiment: {result[0]['label']}\n")

輸出文字

"Tech stocks rally as investors anticipate strong earnings.","Economic downturn leads to market uncertainty.","Central bank announces interest rate hike, impacting stock prices"

輸出

News: Tech stocks rally as investors anticipate strong earnings.
Sentiment: Positive
News: Economic downturn leads to market uncertainty.
Sentiment: Negative
News: Central bank announces interest rate hike, impacting stock prices.
Sentiment: Neutral

利用人工智慧加強文件處理

人工處理大量業務文件效率低下。SLM 可以

  • 彙總冗長的報告
  • 提取關鍵資訊
  • 確保合規性

使用 LayoutLM 進行文件分析

微軟開發的 LayoutLM 基於預訓練語言模型。它利用基於轉換器的架構,專門為需要理解文件視覺佈局的任務而設計。

主要功能

  • 多模式輸入:LayoutLM-base-uncased 可接受兩種型別的輸入:
    • 文字:文件的文字內容。
    • 佈局:文件的視覺佈局,包括文字、影像和其他元素的位置和大小。
  • 文字嵌入:該模型使用基於轉換器的架構來生成文字嵌入,文字嵌入是表示文字含義的數字向量。
  • 佈局嵌入:該模型還能生成佈局嵌入,這是代表文件視覺佈局的數字向量。
  • 融合文字和佈局嵌入:該模型將文字和佈局嵌入結合起來,以建立文件的聯合表示。

它是如何工作的?

以下是基於 LayoutLM 的工作原理的高階概述:

  • 文字和佈局輸入:模型接收文件的文字內容和視覺佈局。
  • 文字嵌入生成:該模型使用基於轉換器的架構生成文字嵌入。
  • 佈局嵌入生成:該模型使用單獨的神經網路生成佈局嵌入。
  • 融合文字和佈局嵌入:模型透過融合層將文字和佈局嵌入結合起來。
  • 聯合表示:融合層的輸出是文件的聯合表示,它同時捕捉文字內容和視覺佈局。

應用

  • 文件分析:您可以使用基於 LayoutLM 的文件分類、實體提取和情感分析等任務。
  • 表單理解:您可以使用該模型從表單中提取資料,包括文字、覈取方塊和其他視覺化元素。
  • 收據分析:您可以使用基於 LayoutLM 的模型從收據中提取相關資訊,包括購買的物品、價格和總額。

優點

  • 提高準確性:透過結合文字和佈局資訊,LayoutLM-base-uncased 可以在需要了解文件視覺化佈局的任務中實現更高的準確性。
  • 靈活性:可以針對各種任務和應用對模型進行微調。
  • 高效:LayoutLM-base-uncased 是一種相對高效的模型,與其他一些預訓練語言模型相比,它所需的計算資源更少。

程式碼示例:使用 SLM 進行市場分析

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from transformers import AutoModelForTokenClassification, AutoTokenizer, pipeline
# Load LayoutLM model
tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")
model = AutoModelForTokenClassification.from_pretrained("microsoft/layoutlm-base-uncased")
# Create a document analysis pipeline
doc_analyzer = pipeline("ner", model=model, tokenizer=tokenizer)
# Sample business document text
business_doc = "Invoice #12345: Total Amount Due: $500. Payment Due Date: 2024-06-30."
# Extract key data
data_extracted = doc_analyzer(business_doc)
print(data_extracted)
from transformers import AutoModelForTokenClassification, AutoTokenizer, pipeline # Load LayoutLM model tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased") model = AutoModelForTokenClassification.from_pretrained("microsoft/layoutlm-base-uncased") # Create a document analysis pipeline doc_analyzer = pipeline("ner", model=model, tokenizer=tokenizer) # Sample business document text business_doc = "Invoice #12345: Total Amount Due: $500. Payment Due Date: 2024-06-30." # Extract key data data_extracted = doc_analyzer(business_doc) print(data_extracted)
from transformers import AutoModelForTokenClassification, AutoTokenizer, pipeline
# Load LayoutLM model
tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")
model = AutoModelForTokenClassification.from_pretrained("microsoft/layoutlm-base-uncased")
# Create a document analysis pipeline
doc_analyzer = pipeline("ner", model=model, tokenizer=tokenizer)
# Sample business document text
business_doc = "Invoice #12345: Total Amount Due: $500. Payment Due Date: 2024-06-30."
# Extract key data
data_extracted = doc_analyzer(business_doc)
print(data_extracted)

輸入文字

"Invoice #12345: Total Amount Due: $500. Payment Due Date: 2024-06-30

輸出

[{'entity': 'LABEL_0', 'score': 0.5759164, 'index': 1, 'word': 'in', 'start': 0, 'end': 2}, {'entity': 'LABEL_0', 'score': 0.6300008, 'index': 2, 'word': '##vo', 'start': 2, 'end': 4}, {'entity': 'LABEL_0', 'score': 0.6079731, 'index': 3, 'word': '##ice', 'start': 4, 'end': 7}, {'entity': 'LABEL_0', 'score': 0.6304574, 'index': 4, 'word': '#', 'start': 8, 'end': 9}, {'entity': 'LABEL_0', 'score': 0.6141283, 'index': 5, 'word': '123', 'start': 9, 'end': 12}, {'entity': 'LABEL_0', 'score': 0.5887407, 'index': 6, 'word': '##45', 'start': 12, 'end': 14}, {'entity': 'LABEL_0', 'score': 0.631358, 'index': 7, 'word': ':', 'start': 14, 'end': 15}, {'entity': 'LABEL_0', 'score': 0.6065132, 'index': 8, 'word': 'total', 'start': 16, 'end': 21}, {'entity': 'LABEL_0', 'score': 0.62801933, 'index': 9, 'word': 'amount', 'start': 22, 'end': 28}, {'entity': 'LABEL_0', 'score': 0.60564953, 'index': 10, 'word': 'due', 'start': 29, 'end': 32}, {'entity': 'LABEL_0', 'score': 0.62605065, 'index': 11, 'word': ':', 'start': 32, 'end': 33}, {'entity': 'LABEL_0', 'score': 0.61071014, 'index': 12, 'word': '$', 'start': 34, 'end': 35}, {'entity': 'LABEL_0', 'score': 0.6122757, 'index': 13, 'word': '500', 'start': 35, 'end': 38}, {'entity': 'LABEL_0', 'score': 0.6424746, 'index': 14, 'word': '.', 'start': 38, 'end': 39}, {'entity': 'LABEL_0', 'score': 0.60535395, 'index': 15, 'word': 'payment', 'start': 40, 'end': 47}, {'entity': 'LABEL_0', 'score': 0.60176647, 'index': 16, 'word': 'due', 'start': 48, 'end': 51}, {'entity': 'LABEL_0', 'score': 0.6392822, 'index': 17, 'word': 'date', 'start': 52, 'end': 56}, {'entity': 'LABEL_0', 'score': 0.6197982, 'index': 18, 'word': ':', 'start': 56, 'end': 57}, {'entity': 'LABEL_0', 'score': 0.6305164, 'index': 19, 'word': '202', 'start': 58, 'end': 61}, {'entity': 'LABEL_0', 'score': 0.5925634, 'index': 20, 'word': '##4', 'start': 61, 'end': 62}, {'entity': 'LABEL_0', 'score': 0.6188032, 'index': 21, 'word': '-', 'start': 62, 'end': 63}, {'entity': 'LABEL_0', 'score': 0.6260454, 'index': 22, 'word': '06', 'start': 63, 'end': 65}, {'entity': 'LABEL_0', 'score': 0.6231731, 'index': 23, 'word': '-', 'start': 65, 'end': 66}, {'entity': 'LABEL_0', 'score': 0.6299959, 'index': 24, 'word': '30', 'start': 66, 'end': 68}, {'entity': 'LABEL_0', 'score': 0.63334775, 'index': 25, 'word': '.', 'start': 68, 'end': 69}]

小結

小型語言模型為自動化提供了輕量級的高效解決方案,從而徹底改變了商業人工智慧。無論是用於客戶支援、財務預測還是文件處理,SLM 都能為企業提供可擴充套件的人工智慧功能,同時最大限度地減少計算開銷。透過利用 Flan-T5、FinancialBERT和LayoutLM等模型,企業可以改進工作流程,降低成本,提高決策水平。(Link to Notebook

  • SLM 為各種業務應用提供了高效、隱私友好的 LLM 替代品。
  • Flan-T5、FinancialBERT和LayoutLM等模型可以實現客戶支援、財務分析和文件處理的自動化。
  • 企業可以透過整合更多技術(如 NER、OCR 和時間序列預測)來提高人工智慧的效能。

評論留言