ambivalent02 commited on
Commit
e0765d0
·
verified ·
1 Parent(s): 49fd160

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Vietnamese[[:space:]]truthful[[:space:]]QA[[:space:]]results.xlsx filter=lfs diff=lfs merge=lfs -text
Vietnamese truthful QA results.xlsx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfe1ae3ab2868fcb79e8670167bd820feb3143be59910db29816e02d3f2601c0
3
+ size 294085
eval_truthful_vi.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import jsonlines
5
+ import sys
6
+ from tqdm.auto import tqdm
7
+ # --- Configuration ---
8
+ MODEL_NAME = sys.argv[1]
9
+ INPUT_FILENAME = "./Vietnamese truthful QA results.xlsx"
10
+ OUTPUT_FILENAME = sys.argv[2]
11
+ MAX_NEW_TOKENS = 512 # The maximum number of new tokens to generate for each answer.
12
+
13
+ writer = jsonlines.open(OUTPUT_FILENAME, "w")
14
+ # 1. Load data from an XLSX file
15
+ try:
16
+ df = pd.read_excel(INPUT_FILENAME)
17
+ except FileNotFoundError:
18
+ print(f"Error: The file '{INPUT_FILENAME}' was not found.")
19
+ print("Please make sure your XLSX file is in the same directory as the script.")
20
+ exit()
21
+ except Exception as e:
22
+ print(f"An error occurred while reading the Excel file: {e}")
23
+ exit()
24
+
25
+ # 2. Select Relevant Columns and validate
26
+ if "Question" not in df.columns or "Ground truth" not in df.columns:
27
+ print("Error: Required columns 'Question' and/or 'Ground truth' not found.")
28
+ print(f"Available columns are: {list(df.columns)}")
29
+ exit()
30
+
31
+ df_processed = df[["Question", "Ground truth"]].copy()
32
+
33
+ # 3. Load Model and Tokenizer
34
+ print(f"Loading model '{MODEL_NAME}' and tokenizer...")
35
+ # Set up device (use GPU if available, otherwise CPU)
36
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
37
+ print(f"Using device: {device}")
38
+
39
+ # Load the tokenizer and model from Hugging Face Hub
40
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
41
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16, attn_implementation='flash_attention_2')
42
+ model.to(device) # Move the model to the selected device
43
+
44
+ # Set pad token if it's not set (GPT-2 doesn't have a default pad token)
45
+ if tokenizer.pad_token is None:
46
+ tokenizer.pad_token = tokenizer.eos_token
47
+ model.config.pad_token_id = model.config.eos_token_id
48
+
49
+ print("Model and tokenizer loaded successfully.")
50
+
51
+ # 4. Generate Answers using the Model
52
+ answers = []
53
+ out_dict = []
54
+ total_questions = len(df_processed)
55
+ print(f"Generating answers for {total_questions} questions...")
56
+
57
+ for i, question in tqdm(enumerate(df_processed["Question"])):
58
+ # Encode the question text into token IDs
59
+ # input_ids = tokenizer.encode(question, return_tensors='pt').to(device)
60
+ messages = [
61
+ {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
62
+ {"role": "user", "content": question}
63
+ ]
64
+ input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
65
+ input_ids = tokenizer([input], return_tensors='pt').to(model.device)
66
+ # Generate text using the model
67
+ # do_sample=False makes the output deterministic (no randomness)
68
+ output_sequences = model.generate(
69
+ **input_ids,
70
+ max_new_tokens=MAX_NEW_TOKENS,
71
+ do_sample=False,
72
+ pad_token_id=tokenizer.pad_token_id
73
+ )
74
+
75
+ # Decode the generated token IDs back to a string
76
+ # The output includes the original prompt, so we need to remove it.
77
+ full_text = tokenizer.decode(output_sequences[0][input_ids['input_ids'].shape[1]:], skip_special_tokens=True)
78
+ answer = full_text.strip()
79
+ gold = df['Ground truth'][i]
80
+ answers.append(answer)
81
+ print(f"Processed question {i + 1}/{total_questions}\nAnswer: {answer}\nGold: {gold}")
82
+ writer.write({
83
+ "question": question,
84
+ "answer": answer,
85
+ "gold": gold
86
+ })
87
+
output_lora_qwen2.5_1.5b.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
output_og_qwen2.5_1.5b.jsonl ADDED
The diff for this file is too large to render. See raw diff