如何使用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 和时间序列预测)来提高人工智能的性能。

评论留言