当前位置: 首页 > article >正文

多模态模型在做选择题时,如何设置Prompt,如何精准定位我们需要的选项

我们这里以Qwen2-VL-7B-instruct为例:

假设我们需要分析一张图片的情绪(从现有的情绪中进行选择),并且我们需要它以思维链的形式展现出来,我们可以这样设置prompt:

emotion6_CoT = """
Analyze the given image and determine the emotion it represents.
Emotional options :(A) anger (B) disgust (C) fear (D) joy (E) sadness (F) surprise (G) neutral
Your output should follow this format strictly:
# analyze 
Your analyze here
# answer
Choice index, one of A-G
"""

这样设计的好处是,最终的answer中一定会有 # analyze 和 # answer 我们就可以利用正则表达式去进行准确提取:假设我们要提取其中的选项,我们可以这样写:

def remove_words(s):
    # 定义需要删除的词汇列表
    words_to_remove = ['Choice', 'index', 'one', 'of', 'A-G']

    # 使用正则表达式删除这些词
    for word in words_to_remove:
        s = re.sub(r'\b' + word + r'\b', '', s)

    # 去除多余的空格
    s = re.sub(r'\s+', ' ', s).strip()

    return s

#ouput为输出列表,我们需要将里面的字符串进行提取,所以为output_text[0]。

option = re.search(r'[A-H]', remove_words(output_text[0].split("# answer")[1]))

最终,我们可以借用字典去匹配对应情绪即可。

注意:在一些推理能力不强的模型中(例如 Qwen2-base-7B),可能会遇到输出依然不遵循prompt的回答,这是正常的。


http://www.kler.cn/a/574195.html

相关文章:

  • 装饰器模式:灵活扩展对象功能的利器
  • 如何高效使用 Mybatis-Plus 的批量操作
  • CDH下配置Flume进行配置传输日志文件
  • 深入探究C++并发编程:信号 异步 原子
  • muduo库源码分析:TcpConnection 类
  • better-sqlite3之exec方法
  • 【深度学习】Adam(Adaptive Moment Estimation)优化算法
  • dify + ollama + deepseek-r1+ stable-diffusion 构建绘画智能体
  • 从零开始在Windows使用VMware虚拟机安装黑群晖7.2系统并实现远程访问
  • .keystore文件转成pkcs1.pem文件记录
  • 阿里云 DataWorks面试题集锦及参考答案
  • 产品需求分析-概览
  • 高效便捷的 Spring Boot 通用控制器框架
  • c# wpf 开发中安装使用SqlSugar操作MySql数据库具体操作步骤保姆级教程
  • 智慧校园可视化:开启校园管理的数字化新未来
  • 2005-2019年各省城镇人口数据
  • 【hello git】git 扫盲(add、commit、push、reset、status、log、checkout)
  • 【论文分享】推理大模型Post-Training技术的全面综述
  • Java数组详解/从JVM理解数组/数组反转/随机排名/数组在计算机如何存储
  • Unity Shader 学习15:可交互式雪地流程