Views
No views yet
Qwen/Qwen1.5-1.8B-Chat, specifically adapted for question-answering in the agricultural domain.Qwen/Qwen1.5-1.8B-Chat1# Example prompt
2question = "How can I improve soil fertility naturally?"
3# The model will generate a relevant answer.KisanVaani/agriculture-qa-english-only). This may result in gaps in knowledge on niche or very recent agricultural topics. The dataset may contain inherent biases which could be reflected in the model's responses.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# Load the fine-tuned model and tokenizer
5model = AutoModelForCausalLM.from_pretrained("ElsayedGhonaim/Agriculture_chatbot")
6tokenizer = AutoTokenizer.from_pretrained("ElsayedGhonaim/Agriculture_chatbot")
7
8# Move model to GPU if available
9device = "cuda" if torch.cuda.is_available() else "cpu"
10model = model.to(device)
11
12# Set the model to evaluation mode
13model.eval()
14
15def ask_question(question):
16 # Format the input using the chat template
17 messages = [
18 {"role": "system", "content": "You are a helpful agricultural assistant."},
19 {"role": "user", "content": question}
20 ]
21
22 # Apply the chat template
23 prompt = tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True
27 )
28
29 # Tokenize the input
30 inputs = tokenizer(prompt, return_tensors="pt").to(device)
31
32 # Generate response
33 with torch.no_grad():
34 outputs = model.generate(
35 **inputs,
36 max_new_tokens=256,
37 temperature=0.7,
38 do_sample=True,
39 pad_token_id=tokenizer.eos_token_id,
40 repetition_penalty=1.1
41 )
42
43 # Extract only the generated response
44 response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
45
46 return response
47
48# Example usage
49question = "What are the benefits of drip irrigation for a small farm?"
50answer = ask_question(question)
51print(f"Question: {question}")
52print(f"Answer: {answer}")KisanVaani/agriculture-qa-english-only dataset, which contains question-answer pairs related to agriculture.lora_r: 16lora_alpha: 32lora_dropout: 0.05learning_rate: 2e-4num_train_epochs: 3per_device_train_batch_size: 1gradient_accumulation_steps: 2max_seq_length: 512@misc{qwen,
title={Qwen Technical Report},
author={Jinze Bai and Shuai Bai and Yunfei Chu and Zeyu Cui and Kai Dang and Xiaodong Deng and Yang Fan and Wenbin Ge and Yu Han and Fei Huang and Binyuan Hui and Luo Ji and Mei Li and Junyang Lin and Runji Lin and Dayiheng Liu and Gao Liu and Chengqiang Lu and Keming Lu and Jianxin Ma and Rui Men and Xingxuan Ren and Xuancheng Ren and Chuanqi Tan and Sinan Tan and Jianhong Tu and Peng Wang and Shijie Wang and Wei Wang and Shengguang Wu and Benfeng Xu and Jin Xu and An Yang and Hao Yang and Jian Yang and Shusheng Yang and Yang Yao and Bowen Yu and Hongyi Yuan and Zheng Yuan and Jianing Zhang and Xingzhang Zhang and Yichang Zhang and Zhenru Zhang and Chang Zhou and Jingren Zhou and Xiaohuan Zhou and Tianhang Zhu},
year={2023},
eprint={2309.16609},
archivePrefix={arXiv},
primaryClass={cs.CL}
}