---
title: DateResolver-Qwen2-7B-Instruct
canonical_url: "https://www.modelscope.cn/models/XGenerationLab/DateResolver-Qwen2-7B-Instruct"
md_url: "https://www.modelscope.cn/models/XGenerationLab/DateResolver-Qwen2-7B-Instruct.md"
repository: XGenerationLab/DateResolver-Qwen2-7B-Instruct
last_updated: 2025-12-04
license: "Apache License 2.0"
pipeline_tag: nli
tasks:
  - nli
model_type:
  - qwen2
architectures:
  - Qwen2ForCausalLM
base_model:
  - Qwen/Qwen2-7B-Instruct
base_model_relation: finetune
parameters: 7.6B
tensor_type:
  - BF16
library_name:
  - safetensors
  - pytorch
frameworks:
  - Pytorch
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 10554
stars: 12
---

# DateResolver-Qwen2-7B-Instruct

> DateResolver-Qwen2-7B-Instruct - XGenerationLab 在 ModelScope 开源的模型。日期推理 为了解决通用大模型在时间感知方面所面临的挑战，我们开发了一套解析处理文本中的时间和日期信息的流程XiYan-DateResolver，并将其转换为准确的真实时间。在覆盖的时间范围内实现了超过95%的准确率，支持包括年、月、日、周、季度、半年及时间段等在内的100多种时间表达方式。

XGenerationLab/DateResolver-Qwen2-7B-Instruct 是 ModelScope 魔搭社区上的 7.6B 参数nli模型，采用 Apache License 2.0 许可，基于 Qwen/Qwen2-7B-Instruct 构建，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: XGenerationLab/DateResolver-Qwen2-7B-Instruct
- **License**: Apache License 2.0
- **Tasks**: nli
- **Parameters**: 7.6B
- **Base model**: Qwen/Qwen2-7B-Instruct
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 10554
- **Stars**: 12
- **Last updated**: 2025-12-04

Source: https://www.modelscope.cn/models/XGenerationLab/DateResolver-Qwen2-7B-Instruct

---

# 日期推理
为了解决通用大模型在时间感知方面所面临的挑战，我们开发了一套解析处理文本中的时间和日期信息的流程XiYan-DateResolver，并将其转换为准确的真实时间。在覆盖的时间范围内实现了超过95%的准确率，支持包括年、月、日、周、季度、半年及时间段等在内的100多种时间表达方式。

示例：（假设今天为2024年12月6日，星期五）

```python
输入：上周三的销量是多少？
输出：上周星期3=2024年11月27日。

输入：公司在不包含今天的近三天内处理的订单数有多少？
输出：不包含今天的近3天=2024年12月3日至2024年12月5日。
```

## 流程介绍

XiYan-DateResolver包含以下两个步骤：

### 1、时间表达式抽取

模型文件：基于`Qwen2-7B-Instruct`微调的checkpoint，用于从输入的文本中抽取时间表达式，并将其转化成本方案定义的标准格式。

模型地址：[modelscope](https://www.modelscope.cn/models/XGenerationLab/DateResolver-Qwen2-7B-Instruct)

示例：

```python
输入：本年度的销量是多少？
模型输出：["今年"]

输入：上周周五比周三的订单数多多少？
模型输出：["上周星期5", "上周星期3"]
```


### 2、时间表达式推理

日期后处理脚本`date_convert.py`，自动获取当前日期，完成从标准的时间表达式到真实时间的推理。

示例：（假设今天为2024年12月6日，星期五）

```python
输入：["今年"]
输出：["今年=2024年"]

输入：["上周星期5", "上周星期3"]
输出：["上周星期5=2024年11月29日", "上周星期3=2024年11月27日"]
```

## Requirements
* python>=3.9
* transformers>4.37.0
* modelscope>=1.17.0

## 使用方式
### 1、时间表达式抽取

首先从modelscope加载模型：
```python
from modelscope import AutoModelForCausalLM, AutoTokenizer
device = "cuda"

model_name = "XGenerationLab/DateResolver-Qwen2-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
```

LLM从输入的文本中解析出时间表达式：
```python
question = "上周三和上周五的销量是多少？"
prompt = "给你一个用户的问题，请你提取出该用户所提问的时间，结果以list格式输出。\n\n【用户问题】\n{question}\n\n【回答】\n".format(question=question)
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
list_output = eval(response)
```

### 2、时间表达式推理
```python
from date_convert import DateTimeUtil
DateTimeUtil.run(list_output)
```

## 适用范围

+ 语言：中文为主
+ 时间表达式：一百多种常用的时间表达式，完整的时间表达式列表及对应的计算逻辑请查看：[时间表达式](https://github.com/XGenerationLab/XiYan-DateResolver/blob/main/%E6%97%B6%E9%97%B4%E8%A1%A8%E8%BE%BE%E5%BC%8F.xlsx)


## 致谢
如果您觉得我们的工作有用，请引用或点赞，这样我们可以为开源社区做出更大的贡献！

```bibtex
@article{XiYanSQL,
      title={XiYan-SQL: A Novel Multi-Generator Framework For Text-to-SQL}, 
      author={Yifu Liu and Yin Zhu and Yingqi Gao and Zhiling Luo and Xiaoxia Li and Xiaorong Shi and Yuntao Hong and Jinyang Gao and Yu Li and Bolin Ding and Jingren Zhou},
      year={2025},
      eprint={2507.04701},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2507.04701}, 
}
```
