Views
No views yet
git clone https://github.com/zjunlp/DataMind.gitcd DataMind/evalAnaconda.1conda create -n DataMind python=3.10
2conda activate DataMindpip install -r requirements.txttransformers library for text generation, particularly for data analysis and code generation tasks.transformers library installed:pip install transformers torch1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_name = "zjunlp/DataMind-Qwen2.5-7B" # Or zjunlp/DataMind-Qwen2.5-14B, if available
5
6# Load the model and tokenizer
7# Use torch_dtype=torch.bfloat16 for better performance on compatible GPUs
8# Use device_map="auto" to automatically distribute the model across available devices
9model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 trust_remote_code=True,
14)
15tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
16
17# Example: Generate Python code for data analysis
18messages = [
19 {"role": "user", "content": "I have a CSV file named 'sales_data.csv' with columns 'Date', 'Product', 'Quantity', 'Price'. Write Python code using pandas to calculate the total revenue for each product and save it to a new CSV file named 'product_revenue.csv'."}
20]
21
22# Apply chat template for Qwen models
23text = tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True
27)
28
29model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
30
31# Generate response
32generated_ids = model.generate(
33 model_inputs.input_ids,
34 max_new_tokens=512,
35 do_sample=True,
36 temperature=0.7,
37 top_p=0.8,
38 repetition_penalty=1.05,
39 eos_token_id=tokenizer.eos_token_id, # Ensure generation stops at EOS token
40)
41
42# Decode and print the generated text
43response = tokenizer.batch_decode(generated_ids[0][len(model_inputs.input_ids[0]):], skip_special_tokens=True)[0]
44print(response)Note:
- Ensure that your working directory is set to the
evalfolder in a virtual environment.- If you have more questions, feel free to open an issue with us.
- If you need to use local model, you need to deploy it according to (Optional)
local_model.sh.
data/QRData/benchmark/data/*.csv and data/DiscoveryBench/*.csv.config.yaml1api_key: your_api_key # your API key for the model with API service. No need for open-source models.
2data_root: /path/to/your/project/DataMind/eval/data # Root directory for data. (absolute path)run_eval.sh1python do_generate.py \
2 --model_name DataMind-Qwen2.5-7B \ # Model name to use.
3 --check_model gpt-4o-mini \ # Check model to use.
4 --output results \ # Output directory path.
5 --dataset_name QRData \ # Dataset name to use, chosen from QRData, DiscoveryBench.
6 --max_round 25 \ # Maximum number of steps.
7 --api_port 8000 \ # API port number, it is necessary if the local model is used.
8 --bidx 0 \ # Begin index (inclusive), `None` indicates that there is no restriction.
9 --eidx None \ # End index (exclusive), `None` indicates that there is no restriction.
10 --temperature 0.0 \ # Temperature for sampling.
11 --top_p 1 \ # Top p for sampling.
12 --add_random False \ # Whether to add random files.local_model.sh1CUDA_VISIBLE_DEVICES=$i python -m vllm.entrypoints.openai.api_server \
2 --model $MODEL_PATH \ # Local model path.
3 --served-model-name $MODEL_NAME \ # The model name specified by you.
4 --tensor-parallel-size $i \ # Set the size of tensor parallel processing.
5 --port $port # API port number, which is consistent with the `api_port` above.bash local_model.shbash run_eval.sh@article{zhu2025open,
title={Why Do Open-Source LLMs Struggle with Data Analysis? A Systematic Empirical Study},
author={Zhu, Yuqi and Zhong, Yi and Zhang, Jintian and Zhang, Ziheng and Qiao, Shuofei and Luo, Yujie and Du, Lun and Zheng, Da and Chen, Huajun and Zhang, Ningyu},
journal={arXiv preprint arXiv:2506.19794},
year={2025}
}