news 2026/8/5 12:25:14

【多模态】11-GPT-4V实验:通用问题、特定问题和思维链提示技术

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
【多模态】11-GPT-4V实验:通用问题、特定问题和思维链提示技术

案例目标

本案例旨在评估GPT-4V在分析图表时使用不同提示技术的效果差异,具体比较以下三种方法:

  • 通用问题:简单提问"分析图像"
  • 特定问题:针对特定类别或模型性能进行详细询问
  • 思维链提示:使用逐步推理方法进行分析

通过这些实验,我们试图确定GPT-4V是否可以通过精确提问和系统推理技术超越其已知限制。

技术栈与核心依赖

主要技术
  • GPT-4V多模态大语言模型
  • LlamaIndex多模态框架
  • 图像分析与理解
  • 提示工程技术
核心依赖
  • llama-index-multi-modal-llms-openai
  • llama-index
  • matplotlib(用于图像显示)
  • PIL(Python Imaging Library)

环境配置

# 安装必要依赖 %pip install llama-index-multi-modal-llms-openai !pip install llama-index # 设置OpenAI API密钥 import os OPENAI_API_KEY = "YOUR OPENAI API KEY" os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY

案例实现

1. 数据准备

实验使用了来自Llama2和MistralAI论文中的三个图表:

  1. 不同LLM在各类别中的安全违规率(Llama2论文)
  2. Llama2与Mistral模型在各种NLP任务中的性能比较(Mistral论文)
  3. 不同LLM在各种NLP任务中的性能表现(Llama2论文)
# 下载测试图像 !wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/gpt4_experiments/llama2_mistral.png' -O './llama2_mistral.png' !wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/gpt4_experiments/llama2_model_analysis.pdf' -O './llama2_model_analysis.png' !wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/gpt4_experiments/llama2_violations_charts.png' -O './llama2_violations_charts.png'

2. 多模态LLM初始化

from llama_index.core import SimpleDirectoryReader from llama_index.multi_modal_llms.openai import OpenAIMultiModal openai_mm_llm = OpenAIMultiModal( model="gpt-4o", api_key=OPENAI_API_KEY, max_new_tokens=500, temperature=0.0, )

3. 图像分析实验

实验1:安全违规率分析

使用包含Llama2和Vicuna模型违规率对比的柱状图进行测试。

通用问题测试
query = "Analyse the image" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:GPT-4V正确识别了三个违规类别(仇恨和有害、非法和犯罪活动、不合格建议),但错误地识别了x轴值,幻觉出"视频分享"、"社交网络"等平台类型,而实际x轴应该是不同的模型。

特定问题测试
query = "Compare Llama2 models vs Vicuna models across categories." response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:GPT-4V错误地回答Vicuna模型在所有子类别中的违规率都低于Llama2模型,与实际图表不符。

提供更多上下文的特定问题
query = """In the image provided to you depicts about the violation rate performance of various AI models across Hateful and harmful, Illicit and criminal activity, Unqualified advice categories. Hateful and harmful category is in first column. Bars with light blue are with Llama2 model and dark blue are with Vicuna models. With this information, Can you compare about Llama2 and Vicuna models in Hateful and harmful category.""" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:提供更多上下文后,GPT-4V正确回答了问题。

思维链提示测试
query = """Based on the image provided. Follow the steps and answer the query - which model among llama2 and vicuna does better in terms of violation percentages in 'Hateful and harmful'. Examine the Image: Look at the mentioned category in the query in the Image. Identify Relevant Data: Note the violation percentages. Evaluate: Compare if there is any comparison required as per the query. Draw a Conclusion: Now draw the conclusion based on the whole data.""" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:使用思维链提示,GPT-4V虽然对条形颜色有幻觉,但正确地得出结论:在"仇恨和有害"类别中,Llama2的违规率低于Vicuna,尽管在某些部分Llama2的违规率高于Vicuna。

实验2:Llama2与Mistral模型性能比较

使用包含Llama2和Mistral模型在各种NLP任务中性能对比的图表进行测试。

通用问题测试
query = "Analyse the image" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:GPT-4V正确识别了图表内容,但错误地认为Mistral在所有指标上都优于LLaMA-2。

特定问题测试
query = "Assuming mistral is available in 7B series. How well does mistral model compared to llama2 model?" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:提供Mistral有7B系列的信息后,GPT-4V能够正确回答。

思维链提示测试
query = """Based on the image provided. Follow the steps and answer the query - Assuming mistral is available in 7B series. How well does mistral model compared to llama2 model?. Examine the Image: Look at the mentioned category in the query in the Image. Identify Relevant Data: Note the respective percentages. Evaluate: Compare if there is any comparison required as per the query. Draw a Conclusion: Now draw the conclusion based on the whole data.""" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:使用思维链提示时,虽然对模型参数数量和百分比点有幻觉,但最终结论部分正确。

实验3:不同LLM在各种NLP任务中的性能表现

使用包含不同LLM在各种NLP任务中性能表现的图表进行测试。

思维链提示测试
query = """Based on the image provided. Follow the steps and answer the query - which model has higher performance in SAT-en in 7B series models? Examine the Image: Look at the mentioned category in the query in the Image. Identify Relevant Data: Note the respective percentages. Evaluate: Compare if there is any comparison required as per the query. Draw a Conclusion: Now draw the conclusion based on the whole data.""" response_gpt4v = openai_mm_llm.complete( prompt=query, image_documents=image_documents, ) print(response_gpt4v)

观察结果:使用思维链提示能够得到正确的结论,尽管它获取了错误的数值。

案例效果

通过实验,我们观察到以下效果:

  • 通用问题:GPT-4V能够提供图像的一般性描述,但容易产生幻觉和错误识别。
  • 特定问题:当提供足够的上下文信息时,GPT-4V能够更准确地回答特定问题。
  • 思维链提示:即使存在一些数值幻觉,思维链提示也能帮助GPT-4V得出更准确的结论。

总体而言,提出特定问题而非一般性问题,能够获得更好的答案。

案例实现思路

本案例的实现思路基于以下假设:GPT-4V在分析图表时可能存在限制,但通过优化提示技术可以改善其性能。

  1. 问题定义:确定要测试的三种提示技术(通用问题、特定问题、思维链提示)。
  2. 数据选择:从学术论文中选择具有代表性的图表作为测试数据。
  3. 实验设计:对每个图表应用三种不同的提示技术,比较结果。
  4. 结果分析:评估每种提示技术的准确性、幻觉程度和整体表现。
  5. 结论总结:基于实验结果,提出最佳实践建议。

扩展建议

  • 扩展测试数据集:使用更多样化的图表类型(饼图、折线图、散点图等)进行测试。
  • 增加提示技术变体:探索更多提示工程技术,如少样本学习、角色扮演等。
  • 量化评估:开发更系统的评估指标,量化不同提示技术的效果。
  • 跨模型比较:将相同实验应用于其他多模态模型,比较不同模型的表现。
  • 领域特定测试:在特定领域(如医疗、金融)的图表上测试提示技术的效果。

总结

本案例通过实验验证了提示技术对GPT-4V图表分析能力的影响。主要发现包括:

  • 特定问题比一般性问题能获得更准确的答案
  • 提供足够的上下文信息有助于减少幻觉
  • 思维链提示即使存在数值错误,也能帮助得出更合理的结论
  • 不同提示技术在不同场景下各有优势

这些发现为使用GPT-4V进行图表分析提供了实用的指导原则,有助于用户更有效地利用这一强大的多模态工具。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/5 12:25:12

财务总监面对人工智能未来的10大决胜能力

从总账到财务总监:AI时代决胜未来的10大核心能力 背景:总账会计时代,大量凭证、结账、报表编制工作正在被AI/RPA接管;AI可以输出报表、算出指标、生成预测初稿,但职业判断、责任承担、业务理解、战略取舍只能由人完成。从总账晋升财务总监,不再比拼谁账做的平、分录做的…

作者头像 李华
网站建设 2026/8/5 12:24:50

CTF 参赛必备:50 个实战解题技巧,一文直接复用

CTF 参赛必备:50 个实战解题技巧,一文直接复用 CTF竞赛的核心逻辑 • 核心目标:快速拆解问题(Flag导向)、工具链协作、模式化思维。• 关键原则:先广度后深度(优先收集信息)、分治策…

作者头像 李华
网站建设 2026/8/5 12:24:25

Linux gnome设置触控板当连接鼠标时关闭

前言 注:本文以gnome桌面环境演示 笔记本电脑自带一个触控板,但平常都用鼠标,触控板会造成误触,所以一般在设置中关闭触控板,但有时没有鼠标的情况下会用触控板应急。 Windows上有个"当连接鼠标时关闭触控板"…

作者头像 李华
网站建设 2026/8/5 12:24:19

5分钟拯救杂乱Windows桌面:NoFences免费分区工具完整指南

5分钟拯救杂乱Windows桌面:NoFences免费分区工具完整指南 【免费下载链接】NoFences 🚧 Open Source Stardock Fences alternative 项目地址: https://gitcode.com/gh_mirrors/no/NoFences 你是否每天都要在混乱的桌面图标海洋中寻找需要的文件&a…

作者头像 李华
网站建设 2026/8/5 12:24:06

前端JavaScript实现MD5算法:原理、方案与应用场景详解

1. 项目概述:为什么要在前端实现MD5?在Web开发中,数据安全是一个绕不开的话题。虽然MD5作为一种密码哈希函数,因其碰撞漏洞已不再被推荐用于密码存储等安全场景,但在很多非密码学的业务场景里,它依然扮演着…

作者头像 李华
网站建设 2026/8/5 12:18:34

信号处理中的吉布斯现象:原理、影响与工程应对策略

1. 信号处理中的“振铃”效应:吉布斯现象初探如果你曾经尝试用一系列正弦波去“拼凑”出一个理想的方波,或者在图像处理中试图用锐化滤镜让边缘更清晰,结果却发现边缘处出现了令人讨厌的、像“鬼影”一样的振荡和过冲,那么恭喜你&…

作者头像 李华