DAM20 commited on
Commit
e9c0068
·
verified ·
1 Parent(s): f5a1f45

Update augment_intents.py

Browse files
Files changed (1) hide show
  1. augment_intents.py +34 -34
augment_intents.py CHANGED
@@ -1,34 +1,34 @@
1
- import json
2
- import random
3
-
4
- # مرادفات بسيطة نضيفها للجمل
5
- prefixes = ["ممكن", "لو سمحت", "لو تكرمت", "أبغى", "ودي", "احتاج"]
6
- suffixes = ["بالضبط", "من فضلك", "الله يعافيك", "بسرعة", "تكفى"]
7
-
8
- def augment_patterns(patterns, n=3):
9
- """يزيد الأمثلة بإضافة prefixes و suffixes"""
10
- augmented = []
11
- for p in patterns:
12
- augmented.append(p) # الأصلية
13
- for _ in range(n):
14
- new_p = p
15
- if random.random() > 0.5:
16
- new_p = random.choice(prefixes) + " " + new_p
17
- if random.random() > 0.5:
18
- new_p = new_p + " " + random.choice(suffixes)
19
- augmented.append(new_p)
20
- return list(set(augmented)) # إزالة التكرار
21
-
22
- # تحميل intents.json
23
- with open("intents.json", encoding="utf-8") as f:
24
- data = json.load(f)
25
-
26
- # زيادة الأمثلة
27
- for intent in data["intents"]:
28
- intent["patterns"] = augment_patterns(intent["patterns"], n=5)
29
-
30
- # حفظ ملف جديد
31
- with open("intents_augmented.json", "w", encoding="utf-8") as f:
32
- json.dump(data, f, ensure_ascii=False, indent=2)
33
-
34
- print(" تم إنشاء ملف intents_augmented.json بعدد أكبر من الأمثلة")
 
1
+ import json
2
+ import random
3
+
4
+
5
+ prefixes = ["ممكن", "لو سمحت", "لو تكرمت", "أبغى", "ودي", "احتاج"]
6
+ suffixes = ["بالضبط", "من فضلك", "الله يعافيك", "بسرعة", "تكفى"]
7
+
8
+ def augment_patterns(patterns, n=3):
9
+ """يزيد الأمثلة بإضافة prefixes و suffixes"""
10
+ augmented = []
11
+ for p in patterns:
12
+ augmented.append(p)
13
+ for _ in range(n):
14
+ new_p = p
15
+ if random.random() > 0.5:
16
+ new_p = random.choice(prefixes) + " " + new_p
17
+ if random.random() > 0.5:
18
+ new_p = new_p + " " + random.choice(suffixes)
19
+ augmented.append(new_p)
20
+ return list(set(augmented))
21
+
22
+
23
+ with open("intents.json", encoding="utf-8") as f:
24
+ data = json.load(f)
25
+
26
+
27
+ for intent in data["intents"]:
28
+ intent["patterns"] = augment_patterns(intent["patterns"], n=5)
29
+
30
+
31
+ with open("intents_augmented.json", "w", encoding="utf-8") as f:
32
+ json.dump(data, f, ensure_ascii=False, indent=2)
33
+
34
+ print("intents_augmented.json")