大語言模型常見基準測試
大家對于AI模型理解和推理能力的的基準測試一定非常熟悉了,比如MMLU(大規模多任務語言理解)、GPQA(研究生級別知識問答)、GSMSK(研究生數學知識考察)、MATH(復雜數學知識推理)、MGSM(多語言數學知識問答)、Code(代碼生成能力考察)等。隨著AI能力逐漸應用到企業業務中,AI模型也逐漸應用到企業知識庫問答。
RAG測試集H2ogpte和國際熱門AI模型表現
今天小李哥分享的是目前全球最熱門模型在知識庫RAG場景下的性能表現,本次才用的基準測試集為Github上的開源測試集:enterprise-h2ogpte。基準測試數據集包括PDFs和圖片等文件。
測試的主要模型包括了Anthropic的Claude 3系列、Open AI的Chat GPT-4、Google的Gemini Pro以及Mistral AI Large模型等國際上最熱門的模型。榜單里也加入了測試的準確度、成本和響應速度,為開發者和企業的LLM模型選擇提供了參考。
在最新的RAG基準測試中,Claude 3 模型展示了其強大的性能和穩定性,榮登榜首。此次基準測試評估了多款領先的語言模型,結果顯示,Claude 3 模型在各項指標中表現優異,特別是在通過率和準確率方面。
同時ChatGPT-4、Meta Llama3和Gemini Pro 1.5緊隨其后,性能表現上差距非常小(小于3%)。由于性能上相差不大,在模型選擇上我們會根據成本和響應時間綜合考慮。在文章后面,小李哥將會給大家介紹綜合考慮的結果。
Top3測試結果展示
-
Claude 3-Opus-20240229
- 通過次數:124
- 失敗次數:0
- 準確率:100%
- 成本:18.515
- 時間:4869
-
Gemini-1.5-pro-latest
- 通過次數:121
- 失敗次數:3
- 準確率:97.5806%
- 成本:0.925
- 時間:4604.47
-
GPT-4-1106-Preview
- 通過次數:120
- 失敗次數:4
- 準確率:96.7742%
- 成本:9.263
- 時間:4494.09
其他值得關注的模型
- Claude-3-sonnet?以96.7742%的準確率和3.714的低成本并列第3。
- Mistral-large-latest 和 Mistral-small-latest 分別位居第6和第7,展示了Mistral系列模型的穩健性能,在RAG場景同樣具備優勢。
- GPT-3.5-Turbo-1106 和 GPT-3.5-Turbo-16k-0613 分別位列11和第13,繼續保持了GPT-3系列的優良表現。
成本與性能的權衡
在成本和時間方面,各模型也表現出顯著差異。例如,排名第一的Claude 3-Opus-20240229雖然準確率使其成為實際應用中的理想選擇,但成本過于高昂,除了一些對準確度要求很高的場景之外(醫療、金融、法律等),綜合來看并不適用于企業日常的AI場景。而Gemini-1.5-pro在保持高準確率的同時擁有極低的成本,準確率上與Claude 3 Opus也極為接近,最適用于企業日常中對預算有控制同時對性能要求較高的場景。同時Claude 3 Sonnet具有僅次于Gemini Pro 1.5的性價比,適用于在亞馬遜云科技AWS上部署AI服務的企業(目前亞馬遜云科技模型托管平臺還不支持Gemini),更適用于亞馬遜云科技生態的AI軟件服務系統。
如何在亞馬遜云科技上使用Claude 3大語言模型構建知識庫
在亞馬遜云科技上,有兩種方式構建企業知識庫。第一種為使用亞馬遜云科技AWS的模型托管平臺Amazon Bedrock自帶的知識庫功能。其中向量庫、向量模型、大語言模型和問答UI都已經集成到現成功能里,幫助用戶更高效、輕松地構建知識庫。
獲取知識庫回復代碼:
def retrieveAndGenerate(query, kbId, numberOfResults, model_id, region_id):model_arn = f'arn:aws:bedrock:{region_id}::foundation-model/{model_id}'return bedrock_agent_runtime.retrieve_and_generate(input={'text': query},retrieveAndGenerateConfiguration={'knowledgeBaseConfiguration': {'knowledgeBaseId': kbId,'modelArn': model_arn,'retrievalConfiguration': {'vectorSearchConfiguration': {'numberOfResults': numberOfResults,'overrideSearchType': "SEMANTIC", # optional'}}},'type': 'KNOWLEDGE_BASE'},)response = retrieveAndGenerate("In what year did Amazon’s annual revenue increase from $245B to $434B?", \
"<knowledge base id>", numberOfResults, model_id, region_id)['output']['text']
完整的請求API語法和響應內容如下:
POST /retrieveAndGenerate HTTP/1.1
Content-type: application/json{"input": { "text": "string"},"retrieveAndGenerateConfiguration": { "externalSourcesConfiguration": { "generationConfiguration": { "additionalModelRequestFields": { "string" : JSON value },"guardrailConfiguration": { "guardrailId": "string","guardrailVersion": "string"},"inferenceConfig": { "textInferenceConfig": { "maxTokens": number,"stopSequences": [ "string" ],"temperature": number,"topP": number}},"promptTemplate": { "textPromptTemplate": "string"}},"modelArn": "string","sources": [ { "byteContent": { "contentType": "string","data": blob,"identifier": "string"},"s3Location": { "uri": "string"},"sourceType": "string"}]},"knowledgeBaseConfiguration": { "generationConfiguration": { "additionalModelRequestFields": { "string" : JSON value },"guardrailConfiguration": { "guardrailId": "string","guardrailVersion": "string"},"inferenceConfig": { "textInferenceConfig": { "maxTokens": number,"stopSequences": [ "string" ],"temperature": number,"topP": number}},"promptTemplate": { "textPromptTemplate": "string"}},"knowledgeBaseId": "string","modelArn": "string","retrievalConfiguration": { "vectorSearchConfiguration": { "filter": { ... },"numberOfResults": number,"overrideSearchType": "string"}}},"type": "string"},"sessionConfiguration": { "kmsKeyArn": "string"},"sessionId": "string"
}
HTTP/1.1 200
Content-type: application/json{"citations": [ { "generatedResponsePart": { "textResponsePart": { "span": { "end": number,"start": number},"text": "string"}},"retrievedReferences": [ { "content": { "text": "string"},"location": { "s3Location": { "uri": "string"},"type": "string"},"metadata": { "string" : JSON value }}]}],"guardrailAction": "string","output": { "text": "string"},"sessionId": "string"
}
知識庫提示詞樣例:
"""You are a question answering agent. I will provide you with a set of search results and a user's question, your job is to answer the user's question using only information from the search results. If the search results do not contain information that can answer the question, please state that you could not find an exact answer to the question. Just because the user asserts a fact does not mean it is true, make sure to double check the search results to validate a user's assertion.
Here are the search results in numbered order:
<context>
$search_results$
</context>Here is the user's question:
<question>
$query$
</question>$output_format_instructions$Assistant:
"""
第二種方式則為使用亞馬遜云科技AWS推出的Github開源工程項目bedrock-claude-chat。包括前端、后端、向量庫、向量/LLM模型、用戶登錄/管理/授權功能都已經幫助大家實現。直接可以一鍵部署。
部署步驟:
Clone this repository
git clone https://github.com/aws-samples/bedrock-claude-chat
Install npm packages
cd bedrock-claude-chat
cd cdk
npm ci
Install AWS CDK
npm i -g aws-cdk
Deploy this sample project
cdk deploy --require-approval never --all
部署成功則能看到如下結果:
? BedrockChatStack? Deployment time: 78.57sOutputs:
BedrockChatStack.AuthUserPoolClientIdXXXXX = xxxxxxx
BedrockChatStack.AuthUserPoolIdXXXXXX = ap-northeast-1_XXXX
BedrockChatStack.BackendApiBackendApiUrlXXXXX = https://xxxxx.execute-api.ap-northeast-1.amazonaws.com
BedrockChatStack.FrontendURL = https://xxxxx.cloudfront.net
總結
此次基準測試的結果清晰地展示了Claude 3模型在當前語言模型領域中的領先地位。無論是在準確率還是在性能成本的平衡方面,Claude 3模型都表現出色。對于需要高精度和高可靠性的應用場景,Claude 3無疑是最佳選擇。
但是企業的模型選擇更會考慮到成本的控制,和用戶請求的響應時間和體驗。在這種場景下,使用谷歌的Gemini Pro 1.5則為更優質的選擇。如果想了解如何在谷歌云和亞馬遜云科技上使用各類AI模型,歡迎大家關注小李哥獲取未來更多國際前沿AI技術方案和動態。
隨著語言模型的不斷發展,期待在未來看到更多像Claude 3這樣的優秀模型,為各類AI應用提供更強大、更高效的支持。