File size: 2,053 Bytes
b31728c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os 
import sys 


sys .path .append (os .path .dirname (os .path .abspath (__file__ )))

from transformers import AutoTokenizer 
from dataset import UrduTextDataset 
from torch .utils .data import DataLoader 

def main ():
    print ("Loading XLM-RoBERTa Tokenizer...")
    tokenizer =AutoTokenizer .from_pretrained ("xlm-roberta-base")

    data_dir =os .path .join (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))),'data')

    print ("\n--- Testing Sentiment Dataset ---")
    sentiment_train_files =[
    os .path .join (data_dir ,'roman_urdu_sentiment_train.csv'),
    os .path .join (data_dir ,'urdu_sentiment_corpus_train.csv')
    ]

    sentiment_dataset =UrduTextDataset (
    csv_paths =sentiment_train_files ,
    tokenizer =tokenizer ,
    max_length =128 ,
    task ="sentiment"
    )

    print (f"Total Sentiment Training Samples: {len (sentiment_dataset )}")


    sample =sentiment_dataset [0 ]
    print (f"\nSample Text: {sample ['text']}")
    print (f"Sample Label: {sample ['label']} (0=Neg, 1=Neu, 2=Pos)")
    print (f"Input IDs shape: {sample ['input_ids'].shape }")
    print (f"Attention Mask shape: {sample ['attention_mask'].shape }")


    loader =DataLoader (sentiment_dataset ,batch_size =4 ,shuffle =True )
    batch =next (iter (loader ))
    print (f"\nBatch Input IDs shape: {batch ['input_ids'].shape }")
    print (f"Batch Labels: {batch ['label']}")

    print ("\n--- Testing Emotion Dataset ---")
    emotion_train_files =[
    os .path .join (data_dir ,'semeval_emotion_train.csv')
    ]

    emotion_dataset =UrduTextDataset (
    csv_paths =emotion_train_files ,
    tokenizer =tokenizer ,
    max_length =128 ,
    task ="emotion"
    )

    print (f"Total Emotion Training Samples: {len (emotion_dataset )}")
    emotion_sample =emotion_dataset [0 ]
    print (f"Sample Label: {emotion_sample ['label']} (0=Joy, 1=Anger, 2=Fear, 3=Sadness)")

    print ("\nPhase 3 Verification Successful! Dataset class and tokenization work perfectly.")

if __name__ =="__main__":
    main ()