Harsh Raj commited on
Commit
e9661a1
·
1 Parent(s): 015aa6c

Update model weights and inference script

Browse files
results/runs/Jul26_06-11-45_HarshRaj/events.out.tfevents.1753490507.HarshRaj.35712.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:766761953873ad81fd44ab797e7caa4a84fa76690af11dece744f7007dc7ad25
3
+ size 5064
train.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering, Trainer, TrainingArguments
3
+
4
+ # 1) Load dataset from the Hub
5
+ ds = load_dataset("HarshMortal/personal-facts")
6
+
7
+ # 2) Tokenizer & model
8
+ model_name = "distilbert-base-cased-distilled-squad"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
11
+
12
+ # 3) Preprocess
13
+ def preprocess(ex):
14
+ inputs = tokenizer(
15
+ ex["question"], ex["context"],
16
+ truncation=True, padding="max_length", max_length=384
17
+ )
18
+ # map answer start/end here...
19
+ inputs["start_positions"] = ex["answers"]["answer_start"][0]
20
+ inputs["end_positions"] = ex["answers"]["answer_start"][0] + len(ex["answers"]["text"][0])
21
+ return inputs
22
+
23
+ tokenized = ds["train"].map(preprocess, batched=False)
24
+
25
+ # 4) Train
26
+ args = TrainingArguments(
27
+ output_dir="results",
28
+ num_train_epochs=2,
29
+ per_device_train_batch_size=1,
30
+ logging_steps=5,
31
+ push_to_hub=True,
32
+ hub_model_id="HarshMortal/personal-qa",
33
+ hub_strategy="every_save",
34
+ )
35
+ trainer = Trainer(model=model, args=args, train_dataset=tokenized)
36
+ trainer.train()