---
title: hihihi_trainingllm_Finlnd
canonical_url: "https://www.modelscope.cn/models/BAAI_Industry_Competition_FinEcon_dev/hihihi_trainingllm_Finlnd"
md_url: "https://www.modelscope.cn/models/BAAI_Industry_Competition_FinEcon_dev/hihihi_trainingllm_Finlnd.md"
repository: BAAI_Industry_Competition_FinEcon_dev/hihihi_trainingllm_Finlnd
chinese_name: "嘻嘻嘻小飞棍来训大模型_Finlnd"
last_updated: 2025-01-01
pipeline_tag: text-generation
tasks:
  - text-generation
parameters: 7.7B
tensor_type:
  - BF16
library_name:
  - safetensors
downloads: 64
stars: 1
---

# hihihi_trainingllm_Finlnd

> hihihi_trainingllm_Finlnd - BAAI_Industry_Competition_FinEcon_dev 在 ModelScope 开源的模型。嘻嘻嘻小飞棍来训大模型队参加智源行业数据集大赛-金融开发者

- **Repository**: BAAI_Industry_Competition_FinEcon_dev/hihihi_trainingllm_Finlnd
- **Tasks**: text-generation
- **Parameters**: 7.7B
- **Downloads**: 64
- **Stars**: 1
- **Last updated**: 2025-01-01

Source: https://www.modelscope.cn/models/BAAI_Industry_Competition_FinEcon_dev/hihihi_trainingllm_Finlnd

---

# 金融大模型知识问答实现流程

本项目旨在通过大模型实现金融知识问答，基于 InternLM 提供的 InternLM/internlm2_5-7b-chat 模型进行定制化优化。

## 功能简介

1. **训练回答评分模型**
   - 设计严谨的评分模型InternLM/internlm2_5-7b-financescoremodel，对模型回答质量进行严格评估。
2. **最佳回答筛选**
   - 用原始的InternLM/internlm2_5-7b-chat大模型生成多个回答，评分后选出最佳答案。
3. **回答反思与优化**
   - 当最佳回答的分数依然太低（评分低于0）时，调用原始的InternLM/internlm2_5-7b-chat大模型对回答进行反思并优化，再次筛选最佳答案。

## 使用说明
1. 配置环境，确保安装依赖库（LlamaFactory和vllm）。
2. 准备训练数据和模型配置文件。
3. vllm运行评分模型训练脚本训练评分模型InternLM/internlm2_5-7b-financescoremodel。
4. vllm运行原始的InternLM/internlm2_5-7b-chat模型进行回答
5. 使用 `eval_score_multianswer.py` 和 `eval_score_reflection.py` 实现最佳回答生成、筛选与优化。

## 实现细节

### 1. 训练回答评分模型

#### 数据准备
从 `industry_instruction_semantic_cluster_dedup_金融_经济_train.jsonl` 文件中提取数据，将问题与回答作为用户输入，评分作为助手输出。

#### Prompt 设计
- 中文数据:
  ```json
  {
      "system": "阅读下面的对话，'question'是一个与金融或经济相关的问题，'answer'是一个模型给出的回答，请对这个模型的回答质量的好坏给出一个打分，注意打分必须得十分的严格，任何没有关注到的细节和事实性错误都必须给予一个极低的分数，分数的区间为[-30,30]。",
      "instruction": "question: 根据文中分析，3月后市场风险增大的主要原因是什么？\n\nanswer: 3月后市场风险增大的主要原因包括经济基本面恶化，如固定资产投资增速下滑，尤其是基建投资增速的大幅下滑；流动性环境偏紧，央行可能维持偏紧的货币政策以控制M2增速并抑制影子银行扩张。",
      "input": "",
      "output": "-3.015625"
  }
  ```

- 英文数据:
  ```json
  {
      "system": "Read the following conversation, 'question' is a question related to finance or economy. 'answer' is the answer given by a model. Please give a score for the quality of the model's answer. Note that grading must be very strict, any unnoticed details and factual errors must be given a very low score, with the score range being [-30,30].",
      "instruction": "question: What are the main concerns of Henry Meier regarding the emphasis on cooperative principles in the credit union industry, and how does he think they should be balanced with other considerations?\n\nanswer: Henry Meier's main concern is that the emphasis on cooperative principles may overshadow more critical issues facing credit unions, such as lending and legislative impact. He believes that an appreciation for the impact of legislation on credit unions is more important than the cooperative structure. Meier also thinks that the cooperative structure is not as crucial to potential young members as some might think, and that convenience and good service are more important to them.",
      "input": "",
      "output": "-2.078125"
  }
  ```

#### 训练方法（训练代码）
使用 [LlamaFactory](https://github.com/hiyouga/LLaMA-Factory) 库对internlm2_5-7b-chat进行微调，训练参数见 `intern_lora_sft_ds0.yaml`。

### 2. 最佳回答筛选
#### Prompt 设计
- 中文回答system Prompt:
 ```text
作为一位资深的金融与经济专家，擅长提供详细、准确且富有见解的回答。请根据以下规则回答用户的问题：
### 通用规则：
使用简洁且专业的语言，避免冗长和重复。
确保回答内容详尽、逻辑清晰，并以用户需求为核心展开。
在适当情况下，加入相关背景知识和数据，丰富内容并增强权威性。
处理复杂问题时，可提供结构化回答（如分类或分步骤说明），确保易于理解
###针对主观问题：
回答需要体现我的专业见解，并提供清晰的理由或说明。
若问题涉及决策或选择，例如投资建议或经济趋势分析，需从多个维度展开，如风险、收益、时间跨度、政策环境等，帮助用户全面理解和决策。
### 针对客观问题：
回答需完整且详细，对涉及的每个选项或概念进行分析，而不仅直接给出答案。
必要时引用经济理论、金融模型、历史数据或全球趋势，解释原因并增强内容的深度和可信度。
 ```

- 英文回答system Prompt:
 ```text
You are a seasoned expert in finance and economy, known for providing detailed, accurate, and insightful responses. Follow these guidelines when answering questions:
### General Guidelines:
Use concise and professional language, avoiding redundancy and unnecessary repetition.
Ensure the response is detailed, logically clear, and centered around the user’s needs.
When appropriate, include relevant background knowledge and data to enrich the content and enhance its authority.
For complex issues, provide structured answers (e.g., categorization or step-by-step explanations) to ensure clarity and ease of understanding.
### For Subjective Questions:
The response should reflect my professional insights and provide clear reasoning or explanations.
For decisions or choices, such as investment advice or economic trend analysis, address multiple dimensions—e.g., risks, returns, time horizons, policy environment—to help users understand and make informed decisions comprehensively.
### For Objective Questions:
The response should be complete and detailed, analyzing each option or concept rather than merely providing a direct answer.
When necessary, reference economic theories, financial models, historical data, or global trends to explain the rationale and add depth and credibility to the content. 
  ```

#### 推理代码实现
生成多个回答，并通过评分模型筛选最高分回答，核心代码如下，详细代码见 `eval_score_multianswer.py`。：
```python
# 根据问题语言选择合适的系统提示词
if '\u4e00' <= question[0] <= '\u9fff':
    messages = [
        {"role": "system", "content": prompt_zh},
        {"role": "user", "content": question}
    ]
else:
    messages = [
        {"role": "system", "content": prompt_en},
        {"role": "user", "content": question}
    ]

# 生成20个回答
completion = client.chat.completions.create(
    model="/root/pubmodels/glm-4-9b-chat",
    messages=messages,
    max_tokens=6144,
    temperature=0.8,
    timeout=200,
    n=20
)
responses = [choice.message.content for choice in completion.choices]

# 对生成的回答进行评分
scores = [score_response('question: '+question+'\n\n'+'answer: '+response, response) for response in responses]

# 筛选得分最高的回答
max_score = max(scores)
best_responses = [responses[i] for i in range(len(scores)) if scores[i] == max_score]

# 同分时选择长度最长的回答
best_response = max(best_responses, key=len)
```

### 3. 回答反思与优化

#### Prompt 设计
- 中文反思 Prompt:
  ```text
  请你反思你做出的回复：
  1. 该回复是否准确回答了用户的问题？
  2. 是否遗漏了用户提供的信息或要求？
  3. 是否存在逻辑错误、不清晰的表述或不相关的内容？
  4. 是否有改进空间，比如补充细节、优化语言表达或提高信息的精确性？
  请根据以上检查点，对你的原回复进行改进，请不要提供修订的建议，直接提供修订后的回答。
  ```

- 英文反思 Prompt:
  ```text
  Please reflect on your response:
  1. Did the response accurately answer the user's question?
  2. Did it omit any information or requests provided by the user?
  3. Were there any logical errors, unclear expressions, or irrelevant content?
  4. Is there room for improvement, such as adding details, optimizing language, or increasing the precision of the information?
  Based on the above checkpoints, please revise your original response directly, without providing revision suggestions, and present the improved version.
  ```

#### 推理代码实现
反思与评分的代码实现与第二部分相同，详细代码见 `eval_score_reflection.py`。

## 文件结构

```
.
├── 嘻嘻嘻小飞棍来训大模型_Finlnd_12071927.jsonl(最终提交的最高分jsonl)
├── 嘻嘻嘻小飞棍来训大模型_Finlnd_report(报告)
├── intern_lora_sft_ds0.yaml(评分模型训练设置)
├── eval_score_multianswer.py(生成多回答挑最优回答的代码)
├── eval_score_reflection.py(反思挑最优回答的代码)
├── 嘻嘻嘻小飞棍来训大模型_Finlnd（LoRA训练后的金融回答评分模型）
└── README.md
```

## 联系方式
如有问题，请联系项目维护者：`yuanzz24@mails.tsinghua.edu.cn`
